Question
PROGRAMMING PROJECT #1: BUY ITEMS Objectives: Use basic C++ constructs: if, switch, and repetition (looping) Perform simple data type manipulations Solve problem, design solution and
PROGRAMMING PROJECT #1: BUY ITEMS
Objectives:
Use basic C++ constructs: if, switch, and repetition (looping)
Perform simple data type manipulations
Solve problem, design solution and implement using C++
Description:
Write a menu-driven program named BuyItems.cpp that provides the following options:
Buy items by asking for the items description, price per item and the quantity
Show receipts by listing all the purchases
Show summary by listing only the number of purchases and the total purchase cost
Requirements:
The program must produce the provided expected sample output.
The user must enter the correct access code which is one of the followings (12345 or 54321) in order to start the program.
There is no array, just simply use string and string concatenation to keep track of the purchase history.
The program should NOT have any global variables
The program should have at least 3 functions and some documentation including your name and programs description
Required error handling:
The program MUST perform the following checks:
Case-insensitive when to ask the user to confirm exiting the program (e.g. accepting both Y and y)
Check for bad access code and allow up to 3 trials.
Check for negative or invalid price and/or quantity
Check for invalid menu answer
Sample program run 1
D:\>BuyItems
Welcome to my shopping program.
Please enter the access code: 12345
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: -1
Invalid selection. Please try it again.
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 5
Invalid selection. Please try it again.
Shopping Menu:
1. buy
2. show receipt
3. show summary
4. exit the program
Enter your option: Hello
Invalid selection. Please try it again.
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 1
Please enter the description: Book
Please enter the quantity: 10
Please enter the price for each item: 5
ITEM(Book) QUANTITY(10) PRICE($5.00) COST($50.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 1
Please enter the description: CD
Please enter the quantity: 2
Please enter the price for each item: 20
ITEM(CD) QUANTITY(2) PRICE($20.00) COST($40.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 1
Please enter the description: Movie
Please enter the quantity: 4
Please enter the price for each item: 8
ITEM(Movie) QUANTITY(4) PRICE($8.00) COST($32.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 2
List of all purchases:
ITEM(Book) QUANTITY(10) PRICE($5.00) COST($50.00)
ITEM(CD) QUANTITY(2) PRICE($20.00) COST($40.00)
ITEM(Movie) QUANTITY(4) PRICE($8.00) COST($32.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 3
PURCHASES(3) TOTAL_COST($122.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 4
Are you sure that you want to exit the program (y/n)? y
Thank you for using our program.
Thank you for using my program.
D:\>
Sample program run 2 invalid price and quantity input
D:\>BuyItems
Welcome to my shopping program.
Please enter the access code: 54321
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 1
Please enter the description: Book
Please enter the quantity: -1
Invalid quantity. Quantity cannot be negative or string. Please try it again.
Please enter the quantity: -10
Invalid quantity. Quantity cannot be negative or string. Please try it again.
Please enter the quantity: Hello
Invalid quantity. Quantity cannot be negative or string. Please try it again.
Please enter the quantity: 10
Please enter the price for each item: -1
Invalid price. Price cannot be negative or string. Please try it again.
Please enter the price for each item: -10
Invalid price. Price cannot be negative or string. Please try it again.
Please enter the price for each item: Hello
Invalid price. Price cannot be negative or string. Please try it again.
Please enter the price for each item: 5
ITEM(Book) QUANTITY(10) PRICE($5.00) COST($50.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 2
List of all purchases:
ITEM(Book) QUANTITY(10) PRICE($5.00) COST($50.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 3
PURCHASES(1) TOTAL_COST($50.00)
Shopping Menu:
1. buy
2. show receipts
3. show summary
4. exit the program
Enter your option: 4
Are you sure that you want to exit the program (y/n)? y
Thank you for using our program.
Thank you for using my program.
D:>
Sample program run 3 invalid access code
D:\>BuyItems
Welcome to my shopping program.
Please enter the access code: 123
Invalid access code. Please try it again.
Please enter the access code: hello
Invalid access code. Please try it again.
Please enter the access code: 12345
Shopping Menu:
1. buy
2. show receipt
3. show summary
4. exit the program
Enter your option: 2
There is no purchase available.
Shopping Menu:
1. buy
2. show receipt
3. show summary
4. exit the program
Enter your option: 3
PURCHASES( 0 ) TOTAL_COST($0)
Shopping Menu:
1. buy
2. show receipt
3. show summary
4. exit the program
Enter your option: 4
Are you sure that you want to exit the program (y/n)? n
Shopping Menu:
1. buy
2. show receipt
3. show summary
4. exit the program
Enter your option: 4
Are you sure that you want to exit the program (y/n)? y
Thank you for using our program.
Thank you for using my program.
D:\>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started