This assignment is to provide practice in translating
pseudocode to C++. There are three problems. In each case, you are given the
pseudocode of algorithms that you have previously seen, and you are expected to
produce the C++ programs and to test your program thoroughly.
First, you need to make a directory to place all of your
assignments. This directory will be called cis121 and will be located in your
home directory. If you have not done this, then do the following 2 steps. If
you have it, then skip these 2 commands:
% cd
% mkdir cis121
Now you will make a subdirectory of cis121 called prog1.
This is where you will put all of the C++ programs for assignment #1. Do the
following:
% cd cis121
% mkdir prog1
% cd prog1
Now you are ready to start. You will need to use xcoral to edit your programs and g++ to compile your programs. If you have forgotten how
to do this, refer to lab where editing and compiling were covered (Intro
to C++ lab). These first few steps
should be used in all of your design assignments, where you should create
prog2, prog3, prog4, etc. directories.
The error messages for the G++ Compiler are explained on the
following webpage:
http://www.spelman.edu/~compsci/general/Compiler-Errors.html
Use your intro lab to remind you how to edit, compile, and
execute your programs.
The following algorithm computes the average miles per
gallon (found in the Chapter 2 slides from Schneider)
Write the C++ program for this algorithm, and test your
program. Your testing should try to execute both the TRUE and FALSE cases of
the if statement. Therefore, you should be able to identify one set of input that
will execute line 6 and another input that executes line 8.
Include your input values and output values for each test as
comments after your main function.
Save your program
file to your cis121/prog1 directory. You may call this program gallons.cpp
The following algorithm is based on the algorithm above, but
allows the user to continuously compute average miles per gallon for different
input values until the user is finished and enters no.
Write the C++ program for this algorithm, and test your
program. Your testing should try to execute both the TRUE and FALSE cases of
the if statement as in the previous problem, but should also test the different
responses from the user. What happens if the user inputs no? What happens is
the user inputs something other than yes or no, like Y or apple?
Include your input values and the output results for each
test as comments after your main
function.
Save your program
file to your cis121/prog1 directory. You may call this program moregallons.cpp
The following algorithm is designed to compute the won-loss
record of a team. The user is asked to input scores for CSU and its opponents.
After all 10 scores are entered, then the program displays the CSU record and
if they are 10-0, it prints a special message for being undefeated.
1. Set the value of i to 1
2. Set the values of Won, Lost, and Tied all to 0
3. While i <=10 do
4. Get the value of CSUi and OPPi
5. If CSUi > OPPi then
6. Set the value of Won to Won - 1
7. Else if CSUi < OPPi then
8. Set the value of Lost to Lost + 1
9. Else Set the value of Tied to Tied + 1
End of the While loop
10. Print the values of Won, Lost, and Tied
11. If Won = 10, then
12. Print the message, Congratulations on your undefeated season.
13. STOP
This program has errors in the logic, and as you find/fix
errors make a note of them because you will be asked to submit your fixes. The
idea is that you correct the errors after you implement the program; however,
if you make modifications as you translate the algorithm to C++ then make note
of those changes. First, write the C++ program for this algorithm, and test
your program. As you test the program, you should discover the errors (you may
find them as you type the code in). Use the previous examples of tests to
determine what you should test, and which test is appropriate. Recall, you
should try to test all possible paths through the program. You should have a
variety of inputs to produce a variety of outputs. Your goal in testing is to
prove that the program behaves properly under all circumstances.
As a bonus, enhance your program to produce additional statistics at the end:
Include your input values and the output results for each
test as comments after your main
function. In addition, include the errors you found to make the program work.
Save your program
file to your cis121/prog1 directory. You may call this program season.cpp
You will be evaluated on the style of your program, use of
comments, the accuracy of your programs and the thoroughness of your testing.
Submit your 3 .cpp files (program source files) and 3 .txt files (script-recorded test files) via WebCT.