0% found this document useful (0 votes)
437 views9 pages

CS301 Assignment 1 Solution 2024

Uploaded by

ahsan shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
437 views9 pages

CS301 Assignment 1 Solution 2024

Uploaded by

ahsan shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Assignment Header
  • ShoppingList Class Definition
  • Function Implementations
  • Menu and Output
  • References and Notices

GET MORE SOLUTION FILES FROM

[Link]
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 [Link]

CPP CODE Solution:

#include <iostream>
#include <iomanip>

using namespace std;

class ShoppingList {

JOIN WHATSAPP GROUP


[Link]
GET MORE SOLUTION FILES FROM
[Link]
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


[Link]
GET MORE SOLUTION FILES FROM
[Link]

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


[Link]
GET MORE SOLUTION FILES FROM
[Link]

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


[Link]
GET MORE SOLUTION FILES FROM
[Link]

switch(choice) {
case 1:
cout << "Enter item to add: ";
[Link]();
getline(cin, item);
[Link](item);
break;
case 2:
int index;
cout << "Enter index of item to remove: ";
cin >> index;
[Link](index - 1);
break;
case 3:
[Link]();
break;
case 4:
[Link]();
break;
case 5:
cout << "Exiting program..." << endl;
break;

JOIN WHATSAPP GROUP


[Link]
GET MORE SOLUTION FILES FROM
[Link]
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 5);

return 0;
}

CODE OUTPUT SCREENSHOT:

JOIN WHATSAPP GROUP


[Link]
GET MORE SOLUTION FILES FROM
[Link]

JOIN WHATSAPP GROUP


[Link]
GET MORE SOLUTION FILES FROM
[Link]

JOIN WHATSAPP GROUP


[Link]
GET MORE SOLUTION FILES FROM
[Link]

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

[Link]

JOIN WHATSAPP GROUP


[Link]

You might also like