Computer Science 173
Intermediate Computer Programming

Denison
CS173 Homework 1


Homework 1

Overall homework comments:

Program grading will not be based solely on whether or not the programs "works." It will also be based on the organization, structure, and documentation (in the form of program comments) for the submitted work.

Be sure and document your code well. Include:

  1. Your name in a comment block at the top of every source file.
  2. A high level description of the problem solved by the program.
  3. Descriptive comments for each function.

Please see the C++ Programming Style Guide and follow the conventions described there. Up to 40% of the grade for this homework will be based on following these conventions and practicing good documentation.

Problem 1

You often hear someone make the claim that by using his or her "system" you can double your investment in a few months or years. The "Rule of 72" provides an easy way to compute how long it takes to double your money. The formula for this rule is:

years to double investment = 72.0 / (interest rate)

where the interest rate (as a % of 100) is the interest you earn annually on the investment. The rule is based on the assumpution that interest is compounded annually and is not taxed.

Create a program that asks the user for an annual interest rate, computes the time for an investment to double, and outputs that time to the console in an informative message. Name your source file rule72.cpp.

Also, design and write down a test plan for your program. A test plan has a description of a set of test cases and (in tabular or matrix form) gives input data for the test case , the expected result, and a place to indicate whether or not the test was checked against the program.

Problem 2

An important consideration when "bundling up" on a cold winter's day is the projected windchill factor. The windchill factor is the themperature without wind that has the same effect on exposed human skin as a given combination of wind and temperature -- that is, the temperature you _feel_ because of the wind. Approximate windchill factor formulas can be derived for winds of various speeds. The windchill temperature in degrees Farenheit for wind speeds of 10, 25, and 40 mph are as follows:

For 10 mph wind: (1.23)(actual temp) - 22
For 25 mph wind: (1.48)(actual temp) - 44
For 40 mph wind: (1.58)(actual temp) - 53

Create a program named chilly.cpp whose input is the actual temperature and whose output is the resultant windchill factor for winds of 10, 25, and 40 mph.

Design and write down a test plan for your program. Test cases should be chosen wisely and have a reason for each choice.

Problem 3

Clothing stores sometimes have sales during the year to attract customers and clear inventory. The final sale price of an item is calculated by deducting the sale percentage from the original price and then adding the tax percentage to the price. Given an original price of an item, a sale percentage, and a tax percentage, write a program to calculate the final sale price.

Before creating the program, answer the following questions:

  1. What are the inputs, and what data type should each be?
  2. What are the outputs, and what data type should each be?
  3. How do you get from the inputs you have to the outputs you want?
  • Write down the algorithm
  • Identify any additional variables beside the input and output variables required

Create a program named pricing.cpp that solves this problem, and again include a test plan.