Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(2021) CSNB244 Programming II Assignment 1 Student ID: Student Name: Instruction: Answer all questions. Write your answer to the table located on the final page
(2021) CSNB244 Programming II Assignment 1 Student ID: Student Name: Instruction: Answer all questions. Write your answer to the table located on the final page of this document. Do not remove any pages. Do not include any cover page. Question 1 Write a complete C++ program for a shop, Nut Shop. This shop sells three types of nuts: Almond, Peanut and Peas. The nut stocks are initialized to 100kg for each nut. Price list for these nuts are as follows: Nut Type Price/kg Almond 10.00 Peanut 2.00 Peas 5.00 The program should display the list of nuts with the weight stocks available. The weight and price for each nut should be stored in a variable for each value. The program will ask the user to key in the nut that they want to purchase. Then the program will calculate and display the price to pay according to the nut's weight entered by the user. The program will update and display the nut's stock too. Sample output Nut Shop Nut Types Available 1. Almond: 100kg 2. Peanut: 100kg 3. Peas: 100kg Enter the nut code to purchase (1/2/3): 1 Almond Enter the nut weight to purchase (kg): 8 The total price to pay is RM 80 Nut stocks: Nut Types Available 1. Almond: 92kg 2. Peanut: 100kg 3. Peas: 100kg (2021) CSNB244 Programming II Assignment 1 Student ID: Student Name: Question 2 Continue from Question 1. Include the looping feature into the program. The program will terminate when the user decided to end it. Sample output Nut Shop Nut Types Available 1. Almond: 100kg 2. Peanut: 100kg 3. Peas: 100kg Enter the nut code to purchase (1/2/3egative to end purchase): 1 Almond Enter the nut weight to purchase (kg): 10 The price is RM 100 Nut Types Available 1. Almond: 90kg 2. Peanut: 100kg 3. Peas: 100kg Enter the nut code to purchase (1/2/3egative to end purchase): 4 Invalid nut types Nut Types Available 1. Almond: 90kg 2. Peanut: 100kg 3. Peas: 100kg Enter the nut code to purchase (1/2/3egative to end purchase): 3 Peas Enter the nut weight to purchase (kg): 50 The price is RM 250 Nut Types Available 1. Almond: 90kg 2. Peanut: 100kg 3. Peas: 50kg Enter the nut code to purchase (1/2/3egative to end purchase): -1 The total price to pay is RM 350 (2021) CSNB244 Programming II Assignment 1 Student ID: Student Name: Question 3 Continue from Question 2. Apply structure in the program. The typedef structure name is Nut. The structure members of the Nut structure are stock and price. The stock should be initialized in this structure. In the main program, declare three object structures: almond, peanut, and peas. Anything related to the nuts' stocks and default price of the nuts should use this structure members. The price and total price of the nuts purchased by the user shall not assign to this structure member. The output should be similar like in Question 2 but the way of writing the code should be different since the program is now applying structure
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