Exercise 1 (10 marks) Write a program that takes two integers L and H (i.e. lowest and highest integer), and calls a function CalculateSum that computes the sum of all the numbers between L and H. Finally, the program will print the average of all these integer numbers by dividing the sum by the number of integers between L and H. The program should assert if L is less than or equal to H. |
|
|
Exercise 2 (50 marks) A store has 6 items. Each item has a price and a bar-code that uniquely identifies it. To simulate such a store, the program offers a menu showing the codes, their corresponding items, and their prices. The user chooses one or several items to buy, and pays for them. The program then returns the right change (big bills first). For example, if the user pays 150 QR and the items cost 101 QR, then the amount returned is 49 QR. So, the change will be four 10 bills, one 5 bill, and four 1 bills. We assume that the user will buy one or more items and checkout by choosing the code 0. If the amount is not sufficient, the user is asked to repay for the items. The codes, the items, and the prices to use are shown in the following table (The code 0 is used to signal that the user completed the shopping): Code Item Price 0 - - 1 Bread 5 2 Oil 8 3 Pizza 43 4 Laptop 1199 5 Macaroni 20 6 Tuna 7 Due to the problem of debugging and understanding programs with global variables, your implementation must not contain any global variables. 1- [5 pts] Decompose the program into small tasks (to be implemented as functions). Document your program decomposition and highlight the design rational (why did you decompose your solution the way you did) - max 1 page document - 2- [10 pts] Draw a flowchart diagram (manual and scan it or use any drawing tool, PowerPoint or Word) illustrating how the program algorithm and control flow. 3- [25 pts] Implement the functions identified in question 1. 4- [5 pts] Add the main method to your implementation 5- [5 pts] Run and test the program with following scenarios: The user buys Pizza (item 3) and pays 45. The user buys Laptop (item 4) and pays 1500. The user did not buy anything by choosing the code zero. The user buys two Pizzas (3), Macaroni (5), and Oil (2). The user pays 100. Capture screen shots of the results of each scenario as evidence that your program is working correctly. Add the captured screen shots to your program documentation (a word document that you should add to your submitted zip file). |
|
|
|
|
n=H - L;
, a for loop
|
|
cout<<"if you don't want to continue shopping Enter 0 else Enter any other number"<<endl;
but the while-loop while (n!=0){...}
ends if there's a 0 as input. If you wonna continue shopping as long as input equals 0 take while (n==0){}
. Otherwise change your output in "if you wonna stop shopping Enter 0... "
|
|
price += GetPrice(code)*Quantity;
. To use this you have to change the first line of main into int n=1,cash,price=0,code,remain,Quantity;
|
|
|
|