0% found this document useful (0 votes)
273 views

CS301 Assignment 1 Solution Spring 2024

Uploaded by

ahsan shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
273 views

CS301 Assignment 1 Solution Spring 2024

Uploaded by

ahsan shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

GET MORE SOLUTION FILES FROM

VUStudentspk.com
CS301 ASSIGNMENT 1 SOLUTION SPRING 2024

Due Date: 29-Apr-2024


Total Marks: 20

FOR OTHER SUBJECTS FREE AND PAID SOLUTION CONTACT


WHATSAPP 03162965677

DO NOT COPY PASTE THE SAME SOLUTION

Uploading instructions

For clarity and simplicity, you are required to Upload/Submit only ONE .cpp file.
Download free .cpp file directly from VUStudentspk.com

CPP CODE Solution:

#include <iostream>
#include <iomanip>

using namespace std;

class ShoppingList {

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com
private:
string Items[100];
int ItemCount;
public:
ShoppingList();
void addItem(string item);
void removeItem(int index);
void viewList();
void clearList();
};

ShoppingList::ShoppingList() {
ItemCount = 0;
}

void ShoppingList::addItem(string item) {


if (ItemCount < 100) {
Items[ItemCount++] = item;
cout << "Item added to the shopping list." << endl;
} else {
cout << "Cannot add more items. Shopping list is full." << endl;
}
}

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

void ShoppingList::removeItem(int index) {


if (index >= 0 && index < ItemCount) {
for (int i = index; i < ItemCount - 1; i++) {
Items[i] = Items[i + 1];
}
ItemCount--;
cout << "Item removed from the shopping list." << endl;
} else {
cout << "Invalid index. No item removed." << endl;
}
}

void ShoppingList::viewList() {
if (ItemCount == 0) {
cout << "Shopping list is empty." << endl;
} else {
cout << "Current items in the shopping list:" << endl;
for (int i = 0; i < ItemCount; i++) {
cout << i + 1 << ". " << Items[i] << endl;
}
}
}

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

void ShoppingList::clearList() {
ItemCount = 0;
cout << "Shopping list cleared." << endl;
}

int main() {
ShoppingList shoppingList;
int choice;
string item;

cout << setw(45) << "Welcome to the Shopping List Manager!" << endl;

do {
// Display menu
cout << "\nMenu:\n"
<< "1. Add item\n"
<< "2. Remove item\n"
<< "3. View list\n"
<< "4. Clear list\n"
<< "5. Exit\n"
<< "Enter your choice: ";
cin >> choice;

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

switch(choice) {
case 1:
cout << "Enter item to add: ";
cin.ignore();
getline(cin, item);
shoppingList.addItem(item);
break;
case 2:
int index;
cout << "Enter index of item to remove: ";
cin >> index;
shoppingList.removeItem(index - 1);
break;
case 3:
shoppingList.viewList();
break;
case 4:
shoppingList.clearList();
break;
case 5:
cout << "Exiting program..." << endl;
break;

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 5);

return 0;
}

CODE OUTPUT SCREENSHOT:

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1
GET MORE SOLUTION FILES FROM
VUStudentspk.com

REGARD - SARIM
WHATSAPP +923162965677

PLEASE NOTE:
Don't copy-paste the same answer.
Make sure you can make some changes to your solution file before
submitting copy paste solution will be marked zero.
If you found any mistake then correct yourself and inform me.
Before submitting an assignment must check your assignment requirement
file.
If you need some help or question about file and solutions feel free to ask.

FOR FREE ASSIGNMENTS SOLUTIONS VISIT

VUStudentspk.com

JOIN WHATSAPP GROUP


https://chat.whatsapp.com/IF8sHHq2GYz8BJwG9XEJB1

You might also like