Computer Science 173
Intermediate Computer Programming

Denison
CS173 Homework 2


Homework 2

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

Problem 1

Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A loop should then iterate once for each floor. In each iteration, the loop should ask the user for the number of rooms on the floor and how many of them are occupied. After all the iterations, the program should display how many rooms the hotel has, how many of them are occupied, how many of them are unoccupied, and the percentage of the rooms that are occupied.

Note that it is traditional that most hotels do not have a thirteenth floor. The loop in this program should skip the entire thirteenth iteration. The program should also perform input validation. Do not accept a value less than 1 for the number of floors. Do not accept a number less than 10 for the number of rooms on a floor.

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

Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month.

After all iterations, the program should display the number of months, the total inches of rainfall, and the average rainfall per month for the entire period.

Validate input: do not accept a number less than 1 for the number of years, and do not accept negaqtive numbers for the monthly rainfall.

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

Write a program with a loop that lets the user enter a series of integers. The user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.

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