Professional Documents
Culture Documents
The resulting program would be: 2. A manufacturer wishes to determine the cost of producing an open-top cylindrical
# include<iostream.h> container. The surface area of the container is the sum of the area of the circular base plus
# include<conio.h> the area of the outside (the circumference of the base times the container height). Write a
// step 1 program to take the radius of the base, the height of the container, the cost per square
# define PI 3.1416 centimeter of the material, and the number of containers to be produced. Calculate the cost
of each container and the total cost of producing all the containers.
void main()
{ 3. Wavelengths of visible light fall approximately into the range 0.4-0.7 microns. The table
// Step 2 below shows the relationship between wavelength and color. Write a program that inputs a
int radius = 0; wavelength and then displays the associated light color. If the wavelength is shorter than
float area = 0; // from step 3 0.4 microns or longer than 0.7, display the message Wavelength outside visual range.
cout << " Enter the radius of the circle\n"; Classify boundary wavelengths as the lower-wavelength color. For example, label a
cin >> radius; wavelength of 0.424 microns as violet.
Color Approximate wavelength range (microns)
// step 3 Violet 0.400-0.424
area= PI * (radius * radius); Blue 0.424-0.491
cout << "\n The area of the circle is"<<area; Green 0.491-0.575
getch(); // pause the program Yellow 0.575-0.585
// program exits after pressing any key Orange 0.585-0.647
} Red 0.647-0.700
The getch() statement belongs to the conio.h library. This extracts a character keyed in by the 4. Write a program that reports the contents of a compressed-gas cylinder based on the
user through the keyboard. This can also be used to pause programs. first letter of the cylinder's color. The program input is a character representing the
observed color of the cylinder: ' Y ' or ' y ' for yellow, ' 0' or ' o ' for orange, and so on.
Another function, the getche(), has the same characteristics except that it displays the character Cylinder colors and associated contents are as follows:
on the screen as being pressed while the getch() does not.
Orange ammonia
Also commonly used is the clrscr() statement. This clears the user screen. Brown carbon monoxide
Yellow hydrogen
Green oxygen
Sample problems:
Your program should respond to input of a letter other than the first letters of the given
1. Write a program to assist in the design of a hydro-electric dam. Prompt the user for the
colors with the message, Contents unknown.
height of the dam and for the number of cubic meters of water that are projected to flow
from the top to the bottom of the dam each second. Predict how many megawatts (MW —
1MW=106W) of power will be produced if 90% of the work done on the water by gravity is