CS 54 - Lab 2


Lab Assignment

Justin is a computer science grad student with a bunch of coins but can't figure out how much the coins are worth because he's no good at arithmetic. Since he's busy pondering such deep computer science problems such as whether P = NP, he asked you to write a program to help count his change.


Lab Assignment - Part I (Required)

Write a program that asks the user how many quarters, dimes, nickels, and pennies Justin has. Then find the final amount he has by using the following formula:
y = 0.25q + 0.1d + 0.05n + 0.01p
for q quarters, d dimes, n nickels, and p pennies. Find the total y and report it to the user. Here is what the output of such a program may look like:

How many quarters do you have? 3
How many dimes you have? 2
How many nickels do you have? 4
How many pennies do you have? 4
You have $1.19 in US coins.


Lab Assignment - Part II (Optional - Extra Credit)

Suppose Justin also had a pile of Mexican coins from his recent trip to Michoacán, México. Mexican pesos come in 1, 2, 5, and 10 peso denominations. As of the time of this writing, one peso was worth approximately $0.092 in US currency. Extend the program from Part I to ask how many of each peso coin he has and then converts the value in Mexican Pesos to US Dollars. The converted value should be added to the final amount, y, from Part I to create a new, aggregate grand total. This total should be reported to the user. The output from Part II may look like this:

(previous output from Part I omitted)
How many 1 peso coins do you have? 3
How many 2 peso coins do you have? 2
How many 5 peso coins do you have? 3
How many 10 peso coins do you have? 2
You have $5.054 in all currencies.


Grading & Submission

Part I is worth 10 points. Part II is worth 12 points (Part I + 2 points extra credit). The lab is out of 10 points. When you're done, submit your lab02.cpp file on Blackboard. I will be grading your program on the following criteria:


[Dilbert]