CSCE 2004 - Programming Assignment 2
Electronic Submission Due: Thursday 11:55 pm Feb 16, 2012
Hardcopy Due: Turn in at beginn1ing of next class or lab, or in JBHT 504 by noon Friday 17, 2012

1. Problem Statement

The population of town A is less than the population of town B. However, the population of town A is growing faster than the population of town B. The goal of this programming assignment is to develop a program to calculate how many years it takes for the population of town A to be greater than or equal to the population of town B.

At the beginning, the program should print out your name and UARK ID number. The program should then prompt the user to enter the populations and growth rates of each town in turn. You should check that the value entered for the population of town A is less than the value entered for the population of town B, and that the growth rate of town A is greater than that of town B. Next the program should calculate the growth of both towns each year. You will want to write your program with a "while" loop that stops when the the population of town A is greater than or equal to the population of town B. The program should then stop and output the number of years it took for this to occur and the populations of both the towns at that time. The population values entered by the user will be the populations of town A and B at year 0. The populations of town A and B at year 1 will be the populations after applying the growth rates after one year.

For example, suppose that the population of town A is 3000, the growth rate of town A is 5%, the population of town B is 5000, and the growth rate of town B is 3%. You can calculate the populations in year 1 as follows:

1. Town A's Population = 3000 + (5% x 3000) = 3150 
2. Town B's Population = 5000 + (3% x 5000) = 5150

Thus, town A's population is less than town B's population.

For year 2:

1. Town A's Population = 3150 + (5% x 3150) = 3307.5 
2. Town B's Population = 5150 + (3% x 5150) = 5304.5

Thus, in year 2, town A's population is still less than town B's population.

The output should look like the following:


Year      Town A Population      Town B Population
0         3000                   5000
1         3150                   5150
2         3307.5                 5304.5s
. . .

Number of years until population of town A is greater than population of town B = () years.
Town A's Population is ().
Town B's Population is ().

The program should also do some basic error checking to make sure the user enters appropriate values when prompted. For example, if the user enters a negative or invalid number, an error message should be displayed and the program should end.

2. Design

Looking at the requirements above, try to sketch out the "flow" of the program using either a diagram or a sequence of conditional statements written in pseudo-code. Mentally walk through each of the possible paths, and think about what conditions and calculations need to be performed. On a piece of paper work or with a spreadsheet, workout the population of each town after each year and use this to verify that your program is correct. The following algorithm description is designed to help you along in this process:


Read in the population of town A and B
If the population of town A greater than population of town B
   Display an error message on the screen, and terminate the transaction
Else read in the growth rate of town A and B
   If the growth rate of town A less than growth rate of town B
      Display an error message on the screen, and terminate the transaction
   Else
      Define a counter to calculate the number of years
      In a loop manner, do the following:
         Compute the population of town A
         Compute the population of town B
         Print the counter value (year) and the population of each town
      Exit loop when the population of town A is greater than that of town B
      Print how many years it took and the population of each town at that time

3. Implementation

Start your program with comments based on your design and add portions of code a little at a time. Compile and run your program on a regular basis, so you always have something that runs, even if it only does part of the job. Make sure you have completed the first task, e.g., printing your name to the screen, before you start writing code for the second task.

4. Testing

Test your program to check that it operates correctly for all of the requirements listed above. Also check for the error handling capabilities of the code. Save your testing output in text files for submission on the program due date.

To create a test file from your code, you can simply copy and paste the contents in the output window and paste it into a text editor.

5. Documentation

When you have completed your C++ program, write a short report (less than one page long) describing what the objectives were, what you did, and the status of the program. Does it work properly for all test cases? Are there any known problems? Add this report to the testing file to be submitted electronically.

6. Submission

Click on the “Upload Files” button. Next, create a new folder and name it as “HW2”. Then, click on the folder and upload two files; one for the code (Code.cpp or Code.txt) and the other for testing and documentation (Report.txt). Make sure to upload the code in one of the two formats .txt or .cpp format. When you finish uploading, confirm your uploading by clicking on “Send for Marking” button.

The dates on your electronic submission will be used to verify that you met the due date above. More than 3 days late will not be accepted. So hand in your best effort on the due date.

You should also PRINT a copy of these files and hand them in during the first class that follows the assignment deadline. Include the Homework Grading Cover Sheet that is linked from the Projects page. Points will be deducted if the cover page is missing.

7. Late Submission Penalties