2010 Homework #2

Choose 6 programs below and write them. Choose 3 from the first group, and 3 from the second group.

Write your programs in your /2010/2/ folder on Odin.

  Notice:
  Program file names are all lower-case.

Name your programs according to which challenge it is.
For example, if you choose programs 2,3,4,10,11,12, then name your programs:

prog2.cpp
prog3.cpp
prog4.cpp
prog10.cpp
prog11.cpp
prog12.cpp

Include comment lines at the top of each program with your name and information about which programming challenge you are writing.

Your program output should indicate something about which program you are writing. Program output will be neat, clean, and organized.
All programs will have some neat and clean output to the terminal.

Coding style will be neat and readable with perfect indenting, and no lines wrapping on an 80-character window.

Program input
Most of the programs ask you to work with numbers, do a calculation, and then display a result.
You may ask the user to enter one of the values in the program using the cin command.
When getting a number, first display a prompt for the user, then use the cin command to get the number.

Practice program - we will do this one in class together on Friday.
99. Fill a swimming pool with water 

Name your program: prog99.cpp

Write a program that calculates the cost of filling a pool.
Your pool is 30-feet long, 20-feet wide, and 6-foot average depth.
The cost of water is $0.022 per gallon.
One cubic foot of water is 7.48052 gallons.
Display the cost to fill your pool.

Your program output should make clear to the user what they are seeing.

Optional: prompt the user to enter cost per gallon, or pool dimensions.

Choose from these program ideas:

 1. Sum of Two Numbers 

Write a program that stores the integers 50 and 100 in variables, and stores
the sum of these two in a variable named total. Display some information
about the program when it is run.
2. Sales Prediction

The East Coast sales division of a company generates 58 percent of total sales.
Based on that percentage, write a program that will predict how much the
East Coast division will generate if the company has $8.6 million in sales
this year.

Your program may ask the user for the sales number.
3. Sales Tax

Write a program that will compute and display the total sales tax on
a $95 purchase. Assume the state sales tax is 4 percent and the county
sales tax is 2 percent.

You can ask the user to enter the purchase amount.
4. Restaurant Bill

Write a program that computes the tax and tip on a restaurant bill for a patron
with a $88.67 meal charge. The tax should be 6.75 percent of the meal cost.
The tip should be 20 percent of the total after adding the tax. Display the
meal cost, tax amount, tip amount, and total bill on the screen.

You may ask for the meal cost.
5. Average of Values

To get the average of a series of values, you add the values up and then divide
the sum by the number of values. Write a program that stores the following
values in five different variables: 28, 32, 37, 24, and 33. The program should
first calculate the sum of these five variables and store the result in a
separate variable named sum. Then, the program should divide the sum variable
by 5 to get the average. Display the average on the screen.
6. Annual Pay

Suppose an employee gets paid every two weeks and earns $2,200 each pay period.
In a year the employee gets paid 26 times. Write a program that defines the
following variables:

payAmount   This variable will hold the amount of pay the employee earns each
            pay period. Initialize the variable with 2200.0.

payPeriods  This variable will hold the number of pay periods in a year.
            Initialize the variable with 26.

annualPay   This variable will hold the employee's total annual pay, which will
            be calculated.

The program should calculate the employee's total annual pay by multiplying the
employee's pay amount by the number of pay periods in a year and store the
result in the annualPay variable. Display the total annual pay on the screen.
7. Ocean Levels

Assuming the ocean's level is currently rising at about 1.5 millimeters per
year, write a program that displays:

. The number of millimeters higher than the current level that the ocean's
  level will be in 5 years

. The number of millimeters higher than the current level that the ocean's
  level will be in 7 years

. The number of millimeters higher than the current level that the ocean's
  level will be in 10 years

Advanced option:
Show millimeters converted to inches.
8. Total Purchase

A customer in a store is purchasing five items. The prices of the five items are

Price of item 1 = $15.95
Price of item 2 = $24.95
Price of item 3 =  $6.95
Price of item 4 = $12.95
Price of item 5 =  $3.95

Write a program that holds the prices of the five items in five variables.
Display each item's price, the subtotal of the sale, the amount of sales tax,
and the total. Assume the sales tax is 7%.
9. Cyborg Data Type Sizes

You have been given a job as a programmer on a Cyborg supercomputer. In order
to accomplish some calculations, you need to know how many bytes the following
data types use: char, int, float, and double.
You do not have any manuals, so you can't look this information up. Write a
C++ program that will determine the amount of memory used by these types and
display the information on the screen.
Choose 3 below
10. Miles per Gallon

A car holds 15 gallons of gasoline and can travel 375 miles before refueling.
Write a program that calculates the number of miles per gallon the car gets.
Display the result on the screen.

Hint: Use the following formula to calculate miles per gallon (MPG):
      MPG = Miles Driven / Gallons of Gas Used

You may ask the user to input the gas-tank capacity in gallons.
11. Distance per Tank of Gas

A car with a 20-gallon gas tank averages 23.5 miles per gallon when driven in
town and 28.9 miles per gallon when driven on the highway. Write a program that
calculates and displays the distance the car can travel on one tank of gas when
driven in town and when driven on the highway.

Hint: The following formula can be used to calculate the distance:
      Distance = Number of Gallons x Average Miles per Gallon
12. Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that
calculates the number of acres in a tract of land with 391,876 square feet.
Display some appropriate output.

You may ask the user to input the total square feet.
13. Circuit Board Price

An electronics company sells circuit boards at a 35 percent profit.
Write a program that will calculate the selling price of a circuit
board that costs $14.95. Display the result on the screen.

Your program may ask for the cost of the circuit board.
14. Personal Information

Write a program that displays the following pieces of information, each on a
separate line:

 . Your name
 . Your address, with city, state, and ZIP code
 . Your telephone number
 . Your major at the University

Use only a single cout statement to display all of this information.

You do not have to display your own real information.
You can display a fake person.

You may also ask the user to enter some of the information, then display it.
15. Triangle Pattern

Write a program that displays the following pattern on the screen:

         *
        ***
       *****
      *******

If you choose this program, then do not choose #16 also.
16. Diamond Pattern

Write a program that displays the following pattern:

         *
        ***
       *****
      *******
       *****
        ***
         *

If you choose this program, then do not choose #15 also.
17. Stock Commission

Kathryn bought 750 shares of stock at a price of $35.00 per share. She must
pay her stockbroker a 2 percent commission for the transaction. Write a
program that calculates and displays the following:

 . The amount paid for the stock alone (without the commission)
 . The amount of the commission
 . The total amount paid (for the stock plus the commission)

Your program may ask the user to enter the number of shares purchased.
18. Energy Drink Consumption

A soft drink company recently surveyed some customers. The exact number of
customers surveyed was between 10,000 and 20,000. Generate a random number of
customers between 10,000 and 20,000.

The company found that approximately 15 percent of those surveyed purchase one
or more energy drinks per week. Of those customers who purchase energy drinks,
approximately 58 percent of them prefer citrus-flavored energy drinks.

Write a program that displays the following:

 . The number of customers surveyed.

 . The approximate number of customers in the survey who purchase
   one or more energy drinks per week

 . The approximate number of customers in the survey who prefer
   citrus-flavored energy drinks


There is no extra credit for writing more than 6 programs.
You may write them all, but put just 6 of them in your class folder.