CS 135: Computer Science I
Spring 2008
Use the prettyPrint functions in the file prettyPrint.cpp on the class webpage to ensure that your program output follows our specifications. Your instructor will go over a sample program that uses those functions in class and/or lab. There are two parts to the assignment.
Design, code, and test a complete C/C++ program that gets information about game-players and computes their game scores for a game like "Dance, Dance, Revolution (DDR)." The program should read (from standard input)
In addition to your information, your program should also read your dance partner's information. That is, the program should read
The program should then print both your names, handles, score information, and scores. A player's score can be computed and printed by calling the function whose prototype is:
void computePrintScore(int right, int wrong){
The line above starts the definition of the function and its formal
parameters. Subsequently we declare a variable of type double
for holding the value of the computed score.
double computedScore;We then compute the score using the formula
computedScore = 1000.0 * ((double) right / (double) (right + wrong));Finally, the function computePrintScore calls another function prettyPrintDouble to print the computed score.
prettyPrintDouble(computedScore);The last two lines return from the function and close the opening brace on the first line.
return; }
Copy the above code (retype the 6 lines of code) and use it. Here is sample interaction with your program:
sushil@xpc:~/samba/classes/135/assignments/as1/code$ ./ddrScore
Enter your first name :
John
Enter your game handle:
sjl
Enter the number of correct dance steps you made:
100
Enter the number of dance steps you missed:
20
Enter your partner's first name :
Jill
Enter your partner's game handle:
JJ
Enter the number of correct dance steps your partner made:
120
Enter the number of dance steps your partner missed:
0
John sjl 100 20 833.33
Jill JJ 120 0 1000.00
sushil@xpc:~/samba/classes/135/assignments/as1/code$
Your output must look as neat and as lined up as it does above and you must use the following filename for writing your code: ddrScore.cpp
Design, code, and test a complete C/C++ program that gets information about baseball pitchers and the speed of their fastball (typically the fastest a pitcher can throw the ball) and computes the time taken for the ball to travel from the pitcher's mound to home plate. The batter must react and bring the baseball bat around to try hit the ball within this time or get a strike. Your program should read the following information from standard input.
Remember that you will have to declare this function's prototype before you call the function. Annotated code for the definition of computePrintTime follows:
void computePrintTime(double s){
This function only takes a single formal parameter, s, the pitch
speed. Now, an identifier like s could mean anything to someone
reading your function's definition. A much better identifier name for
a variable used to hold a baseball's speed is speed or baseballSpeed. There's more to type but the code is much, much
easier to understand! If you like, you can modify our code and use a
different and better variable name.
The rest of the function is similar to computePrintScore from
part 1 and uses the well known
formula
to compute the time taken.
feet is the distance from the
pitching mound to home plate.
double timeTaken = 66.5/s; prettyPrintDouble(timeTaken); return; }
Copy the above code and use it. Here is sample interaction with your program.
sushil@xpc:~/samba/classes/135/assignments/as1/code$ ./bbTimer
Enter pitcher's name :
Clemens
Enter pitch speed:
143.7333
Clemens 143.73 0.46
Chris 55.00 1.21
sushil@xpc:~/samba/classes/135/assignments/as1/code$ ./bbTimer
Enter pitcher's name :
smolz
Enter pitch speed:
136.4
smolz 136.40 0.49
Chris 55.00 1.21
Your output must look as neat and as lined up as it does above and you must use the following filename for writing your code: bbTimer.cpp.
Assume that this format will be used for all your laboratory assignments throughout the semester unless otherwise specified.
Turn in a Folder (Binder) containing:
This document was generated using the LaTeX2HTML translator Version 2002-2-1 (1.71)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
The command line arguments were:
latex2html -split 1 as1S08
The translation was initiated by Sushil Louis on 2008-01-27