Practice Programs for COP 3223
Variables and Assignment Statement
1)
Write a program that prompts the user for the area of a circle and calculates the radius
of that circle and prints it out.
2)
Write a program that asks the user for two pieces of information: the price of an item,
and the percentage of sales tax, and uses that to calculate the total cost of the item with
tax and print this amount to the screen.
3)
Write a program that asks the user for the price of gasoline per gallon, the number of
gallons of gas currently in their car, the miles per gallon their car gets, and the length of
their road trip in miles and calculates and prints out the amount the user will have to
spend on extra gas to complete the road trip. (You may assume that the user will have to
buy some gas to complete the trip.)
4)
Write a program that asks the user for how many slices are in a whole pizza and how
many people are eating the pizza. Since we must be perfectly fair, all people must get
exactly the same number of slices. Any leftover slices (which must be less than the
number of people) will be given to the family dog. Your program should output how
many slices everyone eats and how many slices the dog gets.
5)
Write a program to guesstimate the total number of jelly beans in a right circular
cylinder. In particular, the user must enter both the radius and the height of the cylinder,
as well as the radius of the jellybean (we'll assume it's a sphere). For simplicity's sake,
assume that the amount of volume a single jellybean takes up is simply the volume of the
cube it would fit into. (Thus, if the radius of a jellybean is 2 units, then the total volume it
takes up in the jar is 8 cubic units.) You should output a guess as to how many jellybeans
are in the jar. Your guess need not be an integer. (If you want to enhance the program you
may output the nearest integer to the actual value.)
If Statement
6)
Write a program that does temperature conversion from either Fahrenheit to Celsius, or
the other way around. Your program should first prompt the user for which type of
conversion they want to do. Then your program should prompt the user for the
temperature they want to convert. Finally, your program should output the proper
converted temperature. Incidentally, the formula for conversion from celsius to fahrenheit
is:
F = 1.8*C + 32
7)
Debbie likes numbers that have the same tens digit and units digit. For example,
Debbie likes 133 and 812355, but she does not like 137 or 4. Write a program that asks
the user for a number and then prints out whether or not Debbie likes the number.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document8)
Write a program that prompts the user for 2 pieces of information: (1) age, (2) amt. of
cash they have. Based upon these inputs, your program should produce one of the four
outputs below for the given situations:
Situation
Output
A<21, M<100
"You have some time before you need more money."
A<21, M>=100
"You have got it made!"
A>=21, M<100
"You need to get a job!"
A>=21, M>=100
"You are right on track."
Loops
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '08
 Guha
 Natural number, Prime number

Click to edit the document details