CS302 / Program 1

Sections 15 & 22
Instructor: Colby O'Donnell

Due Date: Friday, Sept 19, 8:30 AM


Program 1 will demonstrate your ability to perform input and output, and compute formulas in C++.

Background

Alfred, a poor and starving grad student, thinks he can support himself better by taking up professional golf. We are going to write a program to help Alfred decide which life, if either, will make him rich. Each tournament that Alfred plays costs him $3,500 to enter (counting travel, equipments, fees, etc). Obviously, the better Alfred plays at each tournament, the more money he is likely to win. We will use the old golfing principle: Drive for show, putt for dough. Each time Alfred makes a one-putt, he wins $2,300.45. However, every time he hits the ball out of bounds, he looses $5,999.99.

Program requirements

You will write a program that does the following in this order:
  1. Asks the user for the average number of one-putts Alfred makes in one tournament.
  2. Asks the user for the average number of times Alfred hits the ball out of bounds in one tournament.
  3. Displays how much money Alfred will make in one tournament.
  4. Asks the user for the number of tournaments held before it snows.
  5. Displays how much money Alfred will make for the golfing season.

Hints and suggestions

  • Test your program. It need not look exactly like the output below, but it must calculate correctly. I will test your program myself using different values.
  • Have your input and output include text describing the values, as well as the values themselves. So instead of just diplaying "$9", be desciptive: "So-and-so earns $9 for such-and-such".
  • Use cin and cout to prompt the user and display information.
  • Use parentheses to clarify your calculation code.
  • Use variables of type double when you need to represent a dollar value. (If you use float, you may get a strange error.)

Example operation

Things the user types are in bold.
How many one-putts does Alfred make: 5
How many times does he hit out of bounds: 1

Alfred makes, on average, $2002.26 per tournament.

How many tournaments for the season: 21

In one season, Alfred will make 42047.46 dollars.

Commenting Your Program:

Comments are required for this and all subsequent programs. They are used to document your program, but are ignored by the compiler. As you develop your program, comments are added for clarification and explanation. In C++ comments follow after // and continue only to the end of the line. You may also use C comments, which are between /* and */ and can span several lines. Comments are found...
  • At the top of the program, including
    • Your name
    • Your e-mail address
    • CS302 and section number
    • The name and e-mail address of your instructor
    • Program number
    • Due date
    • A general description of the program
    This description should tell what the program does and how to use it. Also mention any limitations, unresolved bugs, or special features of the program.
  • After all constant and variable declarations, describing what each is for
  • In the code, to label and briefly explain the main steps of the algorithm.
  • Before any unclear or convoluted code to explain its purpose.
Other things to make your program easier to read:
  • Indent the body of your program as described in class (and in the book).
  • Use "vertical whitespace" (blank lines) to separate logical blocks of your source code.
  • Use meaningful variable names like "onePutts" and "outOfBounds" instead of "p" and "b".

Testing Suggestions

Make sure that you have thoroughly tested your program before turning it in. Try your program out with lots of different sample input data. Check your program's results by using a calculator to compute the formula yourself. Your program will probably crash if the user types in "0" for some of the values; you do not need to prevent this from happening, but this is a known bug that you should mention in a comment at the beginning of the program. Explain for which values the user cannot enter "0" and why the program crashes if they do.

What to turn in

I suggest that you call your Visual C++ Workspace program1 and that you call your CPP file golf.cpp. Use the same hand-in procedure as for program 0. Electronically submit two files:
  1. golf.cpp.
  2. program1.exe, located in the Debug directory after you compile the project.
WARNING: The default Windows behavior for dragging an executable file (a .exe file) is to create a shortcut to it. Creating a shortcut is NOT the same thing as copying. Make sure you COPY the files.

Please do not turn in more than those two files. Remember, your handin directory is P:\course\cs302\colbster\YOURNAME\prog1. Your personal files should be located in U:\private. Drag the files from the U drive to the P drive. When you are done, the P drive should have two files, golf.cpp and program1.exe.

In general, you can always look at your past programs for reference. After I am finished grading a program, I will make it readable for you to look at on the P drive. Or you can just look at your copy on the U drive.

You must turn in your program on time! Late programs will not be accepted, and will receive a zero. It's better to turn in something, than nothing. Remember, start early. Utilize my office hours or the consultants in the lab if you need help. Good luck!


(Last modified: 09/11/97)