CS301 Assignment 1 Solution Spring 2024
CS301 Assignment 1 Solution Spring 2024
VUStudentspk.com
CS301 ASSIGNMENT 1 SOLUTION SPRING 2024
Uploading instructions
For clarity and simplicity, you are required to Upload/Submit only ONE .cpp file.
Download free .cpp file directly from VUStudentspk.com
#include <iostream>
#include <iomanip>
class ShoppingList {
ShoppingList::ShoppingList() {
ItemCount = 0;
}
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;
}
}
}
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;
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;
return 0;
}
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.
VUStudentspk.com