[ fromfile: cppintro.xml id: x-simpletypes ]
Write a short program that asks the user to enter a Celsius value, and then computes the equivalent Fahrenehit temperature. It should use a QInputDialog to get the value from the user, and a QMessageBox to display the result. After that, it should print out a table of celsius to fahrenheit values from 0 to 100 by increments of 5, to the standard output.
If you #include <cstdlib>, you can make use of the rand() function, that generates a sequence of pseudo-random long ints, in the range from 0 to RAND_MAX, which can be used in many interesting ways. It works by computing the next number in its sequence from the last number that it generated. The function srand(unsigned int seed) sets its argument as the initializing value (seed) for the random sequence. Write a short program that tests this function by allowing the user to supply the seed from the keyboard and then generates a list of pseudo-random numbers.
If you want your program's behavior to change each time you run it, you can use srand(time(0)) to seed the rand() function. Since time(0) returns the number of seconds since some initial starting point, the seed will be different each time you run the program. This allows you to write programs that have usefully unpredictable behavior patterns. Write a program that simulates a dice game that the user can play with the computer. Here are the rules to apply to your game:
The game is about repeated “throws” of a pair of dice.
Each die has six faces, numbered 1 through 6.
A throw results in a number which is the total of the two top faces.
The first throw establishes the player's number.
If that number is 7 or 11, the player automatically wins.
If that number is 2, the player automatically loses.
Otherwise, the player continues throwing until she wins (by matching her number) or loses (by throwing a 7 or an 11).
Write a program that accepts two values from the user (customer): the total purchase amount and the amount submitted for payment.
Each of these values can be stored in a variable of type double. Compute and display the change that will be given to the user. Express the change in terms of the number of $10 bills, $5 bills, $1 bills, quarters, dimes, nickels, and pennies. (Presumably, this output could be sent to a machine that dispenses those items automatically.)
For example, if the total purchase amount is $73.82 and the customer pays with a $100 bill then the change should be: two $10 bills, a $5 bill, a $1 bill, no quarters, a dime, a nickel, and three pennies.
| Tip | |
|---|---|
Convert the amount that is owed the customer to pennies, which can be stored as an |
| Generated: $Date: 2009-09-08 12:15:32 -0400 (Tue, 08 Sep 2009) $ | © 2009 Alan Ezust and Paul Ezust. |