CPS 6 Fall 2000: Assignment #3

Due: Monday, Oct. 2 by 11pm
First Late day extended until Friday, Oct 6

30 points

Setup

Assignments are to be your own work. You may consult with UTAs, TAS, professors and other CPS 6 students if you get stuck, but the final writeup is to be yours. Please see the CPS 6 web page for the definition of consult.

See the CPS 6 web page about the late policy for programming assignments. For this assignment only, the first late day is extended until Friday due to the first test. That is if the program is done after Monday 11pm, but by Friday 11pm, then it will be considered late with the 10% penalty.

In your cps006 directory, you should create an assign3 directory to work in. You'll then copy files into this directory to help you get started. That is, type the following unix commands from your account after you login (don't forget the trailing dot on the last line).

cd cps006 mkdir assign3 cd assign3 cp ~rodger/cps006/assign3/* .

If you did these commands correctly, typing pwd should show that you are in your assign3 directory, and typing ls should show the files

Note that 20% of your program grade is based on the readability of your program. This includes things like style, comments, and the naming of variables and functions. Make sure you include a comment at the top of each program with your name, course and purpose of the program specified.

// Name: YOUR NAME HERE // // Course: CPS 6 // // Lecture Section No: // // Lab Section No: // // Purpose: purpose of program here //

Problem 1: (15 pts) Gambling Fool

Refer to the Dice class in Chapter 5 of your textbook for this problem.

Write a program slot.cpp to play the slot machine. The file slot.cpp has been provided for you to help you get started. Your program should do the following.

  1. Ask the gambler how much money he/she wants to spend.
  2. Ask the gambler which dollar machine he/she wants to play (one, five or ten). The gambler will type in the word not the integer (ten, not the number 10). Money is exchanged for the corresponding coins: either 10 dollar coins, 5 dollar coins, or 1 dollar coins.
  3. Spend all the money possible in the slot machine. If the gambler wanted to spend 17 dollars and play the 5 dollar machine, then he/she would spend 15 dollars. Inform the gambler that the extra 2 dollars is not spent.
  4. The slot machine has three wheels that spin. The left and right wheels have the numbers 1-10 on them. The middle wheel has the numbers 1-9 and a special symbol "*" which matches with anything. For each coin entered in the machine, the handle is pulled and the wheels spin, eventually stopping.
  5. The gambler never spends his winnings.
  6. Each time the wheel is spun, show the three numbers (or "*") and print a message if the gambler won.
  7. At the end, print a message indicating how much money the gambler won, and a message indicating if the gambler made money, lost money, or broke even. Money not spent (for example, the 2 dollars in the example above) is not used in the comparison.

In addition, your program should have at least two meaningful functions besides the main function.

Note: Passing Dice to Functions. If you want to pass a dice to a function, you must add the symbol & in the declaration of the function and in any function prototypes, but it is not used when the function is called. For example, consider the function DoSomething shown below.

  int DoSomething(Dice & d, int num);

This function passes a Dice named fritz and an integer num. It might be called as shown below:

   Dice fritz;

   cout << fritz.Roll() << endl;  // roll dice
   int x = DoSomething(fritz, 8);  

Below are two sample runs. Your output does not have to look exactly like this, but should follow the specifications above.

> slot
How many dollars do you want to spend:? 7
Which dollar machine do you wish to play (one, five, or ten)? one
Spinning... Numbers are: 2 9 1
Spinning... Numbers are: 5 * 9
*** Congrats, won $2
Spinning... Numbers are: 8 * 8
*** Congrats, won $10
Spinning... Numbers are: 9 2 2
*** Congrats, won $2
Spinning... Numbers are: 8 7 5
Spinning... Numbers are: 4 * 5
*** Congrats, won $2
Spinning... Numbers are: 9 9 2
*** Congrats, won $2
Total winnings are $18
You won money!
>> slot
How many dollars do you want to spend:? 88
Which dollar machine do you wish to play (one, five, or ten)? ten
You can spend all but 8 dollars
Spinning... Numbers are: 7 2 4
Spinning... Numbers are: 8 7 10
Spinning... Numbers are: 5 7 4
Spinning... Numbers are: 7 4 6
Spinning... Numbers are: 10 * 3
*** Congrats, won $20
Spinning... Numbers are: 2 9 3
Spinning... Numbers are: 4 5 7
Spinning... Numbers are: 3 * 5
*** Congrats, won $20
Total winnings are $40
You lost money!
>


Problem 2: (15 pts) Math Quiz

Program 6.2, simpquiz.cpp is in the book on pages 222-223. It gives a quiz of 1-10 questions where each question involves adding two two-digit numbers.

We have already copied this file for you and named it mathquiz.cpp .

Now modify the program in mathquiz.cpp to ask easy, medium, and hard questions, where these kinds of questions are defined as:

The program should ask a total of ten questions (you may want to test with fewer, but the final program must ask ten questions.) The first three questions asked are easy questions. The running score at any point of the program is calculated by the formula below.

   score = (#easy questions correct) + (#medium questions correct)*2 +
           (#hard questions correct)*3 - (#of incorrect answers)*2
 
So if a user has 3 easy questions correct, 2 medium questions correct, and 1 hard question correct, with 3 questions incorrect, the score is
     3 + 2*2 + 1*3 - 3*2 = 4
(it's possible to get a negative score).

Whenever the running score is less than three, an easy question is asked. If the running score is 3--6 a medium question is asked. If the running score is more than 6 a hard question is asked.

After ten questions are asked the final running score should be displayed as should the number of each type of question the user gets correct.

Design

In writing your program try to make it easy to accommodate changes in how the scoring is done and how it is determined what kind of question is asked. In general, try to create a program that is easy for a new programmer to use in a slightly different way.


Problem 3: EXTRA CREDIT (6 pts) Calendar

Write a program called printcal.cpp to print the calendar for a month, given a particular month and year. The calendar must have a box around each day and include the month, year and a listing of days at the top. Consider using the Date class.

Here is a sample run.

> printcal
Enter month between 1 and 12: 9
Enter year: 2000

       September 2000
 Sun Mon Tue Wed Thu Fri Sat
+---+---+---+---+---+---+---+
|   |   |   |   |   |  1|  2|
+---+---+---+---+---+---+---+
|  3|  4|  5|  6|  7|  8|  9|
+---+---+---+---+---+---+---+
| 10| 11| 12| 13| 14| 15| 16|
+---+---+---+---+---+---+---+
| 17| 18| 19| 20| 21| 22| 23|
+---+---+---+---+---+---+---+
| 24| 25| 26| 27| 28| 29| 30|
+---+---+---+---+---+---+---+


Submit

When all your programs compile and produce the correct output, create a file named README (please use all capital letters in naming the file). In the file include your name, section number, the date, and an estimate of how long you worked on the assignment . You must also include a list of names of all those people with whom you consulted on the assignment. See the CPS 6 web page for the meaning of consult.

To submit your programs electronically you must be in your assign3 directory and type (REPLACE instructor with rodger or ramm depending on who your professor is, for example Prof. Rodger's students would type assign3rodger):

submit_cps006 assign3instructor *.cpp README

You should receive a message telling you that the programs were submitted correctly. If the submit_cps006 command does not work, then try

  ~rodger/bin/submit6 assign2instructor *.cpp README

To see that the programs were submitted correctly, type (REPLACE instructor with rodger or ramm depending on who your professor is, for example Prof. Rodger's students would type assign3rodger):

    submit_cps006 assign3instructor

with no arguments and a list of the files submitted will be shown. PLEASE RUN THIS COMMAND to make sure your programs were submitted correctly.

The submit command with *.cpp submits all of your .cpp programs in your current directory at the same time. You can resubmit again if you realize you made a mistake and want to change something. If you submit more than once, we grade the last submission. If the first submission is on time and the last one is late, then the programs are late. All programs must be turned in together. You cannot submit one program early and the rest late.