Implementing interactive Online Shopping in C++
- Users will be able to purchase laptops, Mobile, Computer Courses.
- Users will be able to add items.
- Users will be able to reduce the quantity or delete the item.
- Users will be able to print the bill.
Firstly a menu will be displayed to the customer. After the selection, all the products with their prices will be displayed. Then the customer will select the products and chooses the quantity(number of products). This process continues until the shopping is completed. Whenever the customer completes his shopping, the items, quantity, cost, and finally the total amount to be paid are displayed.
Below is the implementation of the above functionality:
Let us suppose, someone need to buy 2 Redmi mobiles, 1 HP Laptop and a Java course.
Step 1: Firstly, a map(say map<string, long double> items ) is constructed, which stores products with their costs. Construct another map (say map<string, long double>selected_items ), which is used to push the selected items with their quantity. Then initiate total_amount(which stores the total amount) to 0. Use flag and initiate to 0. In case if wrong input is given by the customer, then the flag changes to 1 and gets exited directly by printing items with their prices and then print the total amount.
Step 2: Ask for details For example- the name of the customer. In our code customerDetails() function is constructed for this purpose. toupper() is used for converting all the characters of a string into uppercase.
Step 3: Display the menu to the user. showMenu() function is created for this purpose.
Step 4: Ask the user whether he likes to continue. Here do-while loop is used, this loop continues till flag changes to 1. Whenever the flag changes to 1, it directly prints the bill.
- If yes, he needs to enter Y/y then ask the user to input the respective number from the menu. If the wrong number is entered then the flag changes to 1.
- If the input is valid, show the products of the selected type. Ask the user to input the respective number. If it is not valid, then the flag changes to 1.
- As there are many products, a switch case is used, where the parameter is the number(respective number of the item) entered by user.
- Now respective case gets executed. Firstly, ask the quantity and then ask the user if he is sure about the quantity entered. If he is not sure (or) if the quantity is not an integer, then he will be asked again till both conditions are satisfied.
- If he is sure about the quantity of the product selected, then that product along with its quantity gets pushed into the selected_items map.
- This process goes on till the flag gets changed to 1.
- Else, he can type any other letter except Y/y. Then the flag changes to 1.
Below are some screenshots showing what will be the screen like, when the particular selection is done by the user-
- If mobile is selected: The below screenshot shows the Mobile Menu:
- If laptop is selected: The below screenshot shows the Laptop Menu:
- If computer course is selected: The below screen shows the Computer Course Menu:
- If the flag changed to 1, we print the bill using printBill() function.