User You are required to implement a simple Shopping List Manager using ArrayList data structure. The program must meet the following requirements. 1. Write a C++ program that allows users to manage a shopping list. 2. Use ArrayList data structure to store items in the shopping list. 3. Your program should contain the following functionalities. a. Add item to the shopping list. b. Remove items from the shopping list. c. View current items in the shopping list. d. Clear the shopping list (i.e. remove all items). e. Exit the program. 4. The program should display a menu to the user and allow them to choose options using numbers. 5. Ensure error handling for invalid inputs. 6. Use Object oriented programing principles where applicable. An output screenshot is given at the end of this file for your complete understanding and reference. Note: Don’t use ArrayList Built in library . You must follow the following program structure for naming and to build the program. Program Structure: Class: ShoppingList Attributes: 1. Items[100] : string 2. ItemCount: int Explicit Default Constructor: 1. ShoppingList() Functions: 1. addItem(…) //Where … represents function takes parameters. 2. removeItem(…) //Where … represents function takes parameters. 3. viewList() 4. clearList() Default Function: 1. main()
Question
User You are required to implement a simple Shopping List Manager using ArrayList data structure. The program must meet the following requirements.
- Write a C++ program that allows users to manage a shopping list.
- Use ArrayList data structure to store items in the shopping list.
- Your program should contain the following functionalities. a. Add item to the shopping list. b. Remove items from the shopping list. c. View current items in the shopping list. d. Clear the shopping list (i.e. remove all items). e. Exit the program.
- The program should display a menu to the user and allow them to choose options using numbers.
- Ensure error handling for invalid inputs.
- Use Object oriented programing principles where applicable. An output screenshot is given at the end of this file for your complete understanding and reference.
Note: Don’t use ArrayList Built in library . You must follow the following program structure for naming and to build the program. Program Structure: Class: ShoppingList Attributes:
- Items[100] : string
- ItemCount: int
Explicit Default Constructor:
- ShoppingList() Functions:
- addItem(…) //Where … represents function takes parameters.
- removeItem(…) //Where … represents function takes parameters.
- viewList()
- clearList()
Default Function:
- main()
Solution
Sure, here is a simple implementation of the Shopping List Manager in C++.
#include<iostream>
#include<string>
using namespace std;
class ShoppingList {
string items[100];
int itemCount;
public:
ShoppingList() {
itemCount = 0;
}
void addItem(string item) {
if(itemCount < 100) {
items[itemCount] = item;
itemCount++;
} else {
cout << "List is full!" << endl;
}
}
void removeItem(string item) {
for(int i = 0; i < itemCount; i++) {
if(items[i] == item) {
for(int j = i; j < itemCount-1; j++) {
items[j] = items[j+1];
}
itemCount--;
return;
}
}
cout << "Item not found!" << endl;
}
void viewList() {
for(int i = 0; i < itemCount; i++) {
cout << items[i] << endl;
}
}
void clearList() {
itemCount = 0;
}
};
int main() {
ShoppingList list;
int choice;
string item;
while(true) {
cout << "1. Add item\n2. Remove item\n3. View list\n4. Clear list\n5. Exit\nEnter your choice: ";
cin >> choice;
switch(choice) {
case 1:
cout << "Enter item: ";
cin >> item;
list.addItem(item);
break;
case 2:
cout << "Enter item: ";
cin >> item;
list.removeItem(item);
break;
case 3:
list.viewList();
break;
case 4:
list.clearList();
break;
case 5:
return 0;
default:
cout << "Invalid choice!" << endl;
}
}
return 0;
}
This program creates a ShoppingList object and provides a menu for the user to add items, remove items, view the list, clear the list, or exit the program. The addItem function adds an item to the list if there is space. The removeItem function removes an item from the list if it is found. The viewList function displays all items in the list. The clearList function removes all items from the list. The main function handles user input and calls the appropriate functions based on the user's choice.
Similar Questions
Objective: The objective of this activity is to implement a basic inventory management system using Java programming concepts such as user-defined methods, scanner, arrays, loops, and conditions.Task Overview:1. Create a new Java class named `InventorySystem`.2. Declare the following static variables inside the `InventorySystem` class: - `MAX_ITEMS`: an integer constant to define the maximum number of items in the inventory (set it to 10). - `items`: a string array to store the names of the items in the inventory (initialize it with the size of `MAX_ITEMS`). - `quantities`: an integer array to store the quantities of the items in the inventory (initialize it with the size of `MAX_ITEMS`).3. Implement the `main` method inside the `InventorySystem` class: - Create a `Scanner` object named `scanner` to read user input from the console. - Use a `while` loop to keep the program running until the user chooses to exit. - Inside the loop, display a menu of options to the user: 1. Add item to inventory 2. Sell item from inventory 3. Display inventory 4. Exit - Use a `switch` statement to execute the corresponding action based on the user's choice (1, 2, 3, or 4). - If the user selects option 1, call the `addItem` method. - If the user selects option 2, call the `sellItem` method. - If the user selects option 3, call the `displayInventory` method. - If the user selects option 4, exit the program.Sample Output 4. Implement the `displayInventory` method: - Iterate through the `items` and `quantities` arrays and display the name and quantity of each item in the inventory.Sample OutputNote: For other displayInventory functions, check the sample output in the addItem and in the sellItem methods. 5. Implement the `addItem` method: - Prompt the user to enter the name of the item to be added. - Check if the item already exists in the inventory by searching for its name in the `items` array. - If the item does not exist, add it to the list. Automatically it will have value of 1. - If the item already exists, prompt the user to enter the quantity to be added. - Update the quantity of the existing item in the `quantities` array.Sample Output6. Implement the `sellItem` method: - Prompt the user to enter the name of the item to be sold. - Check if the item exists in the inventory by searching for its name in the `items` array. - If the item does not exist or if its quantity is 0, display an error message. - If the item exists and its quantity is greater than 0, prompt the user to enter the quantity to be sold. - Update the quantity of the sold item in the `quantities` array.Sample Output7. Compile and run the `InventorySystem` class to test the inventory management system.8. Test the system by adding items to the inventory, selling items, and displaying the current inventory.9. When exit is chosen, the program will terminate
An Inventory Management System for a retail store that sells various products. The system allows the store to keep track of its inventory, manage stock levels, and analyze inventory statistics. The retail store can use this Inventory Management System to maintain an organized record of its products. Store managers can input new inventory items, update existing item details, and analyze inventory statistics. The system helps in making informed decisions regarding stock replenishment, pricing strategies, and product promotions. The Inventory Management System is going to perform four operations initially that is Inventory Tracking, Displaying Inventory Details, Inventory Analysis, and Reporting. In an Inventory tracking option, the user inputs the number of items to be tracked in the inventory. For each item, the user inputs details such as name, quantity, price, and category. The system stores this information in an array of structures representing inventory items. After the user inputs all the inventory details, the system displays the details of each item entered. The details include the name, quantity, price, and category of each item. Inventory Analysis, the system includes functions to calculate the total stock value and find the most expensive item in the inventory. The total stock value is calculated by multiplying the quantity of each item by its price and summing up these values. The most expensive item is determined by comparing the prices of all items and identifying the one with the highest price. Once the inventory details are displayed, the system generates a report with the following information, Total stock value: The sum of the values of all items in the inventory. Most expensive item: The name of the item with the highest price. Inventory Management System Input the number of items to be tracked in the inventory Name Quantity Price Category Display the details of each item in the inventory Name Quantity Price Category Calculate and display the total stock value Find and display the most expensive item Sample input: 3 Laptop 20 50000 Electronics Jeans 50 1000 Apparel Headphones 60 900 Accessories Sample output Laptop 20 50000.00 Electronics Jeans 50 1000.00 Apparel Headphones 60 900.00 Accessories 1104000.00 Laptop code in c language
you are tasked with developing a canteen management system for a university campus. The canteen offers three main categories of items: snacks, beverages, and meals. Each category has specific attributes. Using classes, objects, function overloading, constructors, and access specifiers, create a system that allows the user to add and display details of items available in the canteen, including their quantity.Instructions:Implement three classes: Snack, Beverage, and Meal.Each class should have private attributes for storing item details, including name, price, quantity, expiration date, and additional attributes specific to each category.Overload constructors for each class to initialize objects with different sets of parameters.Create functions to add and display details of items in the canteen.Sample InputEnter Snack Details:Name: CookiesPrice: 1.5Quantity: 100Expiration Date: 2024-05-31Enter Beverage Details:Name: LemonadePrice: 1.25Quantity: 75Expiration Date: 2024-06-15Volume: 16 ozType: Soft DrinkEnter Meal Details:Name: SpaghettiPrice: 10.75Quantity: 50Expiration Date: 2024-05-20Ingredients: Pasta, Tomato Sauce, MeatballsCooking Time: 45 minutesType: DinnerSample OutputCanteen Items Details:Snack Details:Name: CookiesPrice: $1.5Quantity available: 100Expiration Date: 2024-05-31Beverage Details:Name: LemonadePrice: $1.25Quantity available: 75Expiration Date: 2024-06-15Volume: 16 ozType: Soft DrinkMeal Details:Name: SpaghettiPrice: $10.75Quantity available: 50Expiration Date: 2024-05-20Ingredients: Pasta, Tomato Sauce, MeatballsCooking Time: 45 minutesType: Dinner
Hotel Management SystemTask Overview:To create a Java program for managing hotels using List and Set data structures. The program should allow users to perform operations such as adding hotels, removing hotels, searching for hotels, and displaying the list of hotels.Instructions:1. Hotel Class: - Create a Java class named Hotel with attributes such as name, location, rating, and price. - Implement appropriate constructor(s), getter and setter methods, and toString method for the Hotel class.2. Main Program: - In the main program, create a List to store hotels. - Utilize a Set to ensure that hotels with duplicate names cannot be added to the list. - Provide options for users to: - Add a new hotel to the list. - Remove a hotel from the list. - Search for a hotel by name or location. - Display the list of hotels with their details. - Exit the program.3. Input Handling: - Use Scanner for user input to add, remove, search, or display hotels. - Ensure error handling for invalid inputs and edge cases.4. Hotel Operations: - Implement methods to add a hotel, remove a hotel, search for a hotel, and display the list of hotels. - Use List and Set operations to perform these tasks efficiently.5. Testing: - Test the program by adding multiple hotels, searching for hotels, removing hotels, and displaying the list of hotels. - Verify that hotels with duplicate names are not added to the list.Sample OutputHotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: MidoriEnter hotel location: Clark, PampangaEnter hotel rating: 5Enter hotel price: 5500Hotel added successfully.Hotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: SogoEnter hotel location: Mabalacat City, PampangaEnter hotel rating: 3Enter hotel price: 800Hotel added successfully.Hotel Management System1. Add Hotel2. Remove Hotel3. Search Hotel4. Display All Hotels5. ExitEnter your choice: 1Enter hotel name: Bestwestern HotelEnter hotel location: Angeles City, PampangaEnter hotel rating: 4Enter hotel price: 2500Hotel added successfully.
Hotel Management SystemTask Overview:To create a Java program for managing hotels using List and Set data structures. The program should allow users to perform operations such as adding hotels, removing hotels, searching for hotels, and displaying the list of hotels.Instructions:1. Hotel Class: - Create a Java class named `Hotel` with attributes such as name, location, rating, and price. - Implement appropriate constructor(s), getter and setter methods, and toString method for the Hotel class.2. Main Program: - In the main program, create a List to store hotels. - Utilize a Set to ensure that hotels with duplicate names cannot be added to the list. - Provide options for users to: - Add a new hotel to the list. - Remove a hotel from the list. - Search for a hotel by name or location. - Display the list of hotels with their details. - Exit the program.3. Input Handling: - Use Scanner for user input to add, remove, search, or display hotels. - Ensure error handling for invalid inputs and edge cases.4. Hotel Operations: - Implement methods to add a hotel, remove a hotel, search for a hotel, and display the list of hotels. - Use List and Set operations to perform these tasks efficiently.5. Testing: - Test the program by adding multiple hotels, searching for hotels, removing hotels, and displaying the list of hotels. - Verify that hotels with duplicate names are not added to the list.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.