Fall 2018midterm 1
Fall 2018midterm 1
Question 1: Show exactly what is printed by the following program. (10 points)
Question 2: What will happen if the user enters 0, 7 , 13 ,18 , 21 , 62 , 100, 102? Consider
each case separately. (10 points)
Question 3: Write c++ code to print all of the numbers from -10000 to 10000, their cubes, and
their square roots. Print all 3 values on one line and then go to a newline. (Hint: the cube of a
number is that number multiplied by itself 3 times. The pow(x,y) and sqrt(x) functions may be
handy here). 12 points.
Question 4: What is the output of the code below? 10 points
Question 5: What will the code output if the user enters 10, 12 , 15 ,100 , 200? Consider each
case separately. (8 points)
Question 6
Consider the code below and determine what will be printed if the user enters the following?
Consider each case separately! (7 points)
“senior” 100
“senior” 101
“teenager” 200
“teenager” 1000
“Adult” 2000
string category;
double bill =0;
double discount;
if (category == "senior") {
cout << "You are a senior" << endl;
Write c++ code which will determine if the word in str1 comes alphabetically before, after, or
matches the word in str2; Print an appropriate message in each case. Eg. ‘str1 ‘ comes before
‘str2’ or ‘str1’ comes after ‘str2’ or ‘str2’ is the same as ‘str3’
Question 10: Write a complete c++ program to solve the following problem.(20 points)
You are hired to write a program for the cash register at a local fish market. The program will
ask the cashier to enter an access code (10345) in order to start processing transactions. If the
user enters any other value, the program will not start processing any transactions.
Each transaction will have a unique ID. E.g. the 1st transaction of the day will be #1, the 4th #4,
the 100th #100 etc.
During each transaction, our program will ask the cashier to enter how many pounds of salmon
(quantity) was purchased and will store this value. It will then calculate the total cost. (quantity *
price).
Then, print a summary of the bill in a tabular format. (Hint: “\t”) That is, it will indicate the type of
fish purchased, price per pound (unit cost), and the total (without the discount). See next page
for a hint.
If the customer buys 10 lbs or more of fish, discount $5 from the entire bill. Print the discounted
amount.
Finally, print the total cost after the discount (if necessary). If the customer doesn’t qualify for a
discount, don’t print the total cost again. The value in the table is enough.
After the transaction is complete, the program will ask the user if he wishes to process another
transaction. The user must re-enter the access code if he wishes the program to continue. If he
enters any other value, the program will stop processing transactions.
At the end of the day, after the cashier has stopped processing transactions, print the:
- Message “End of the day!”
- Total Sales (sum of all bills)
- Total number of transactions
- Average customer’s bill
//Sample output if only 1 transaction was done for the entire day
_________________________________________________________________
Transaction # 1
Total is : $32.00
Discount: $5