CPS 06, Spring 2000, Assignment 3

Due before midnight Friday, March 3, 2000 (midnight Friday, February 25 for 5 bonus points)

30 points

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 ~ola/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 Makefile and simpquiz.cpp.

Math Quiz (15 points)

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.

Copy the file using the Unix command cp to a new file named mathquiz.cpp

    cp simpquiz.cpp 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.

Biorhythm (15 points)

Biorhythms are described in Problem 5.16 on page 207 of the book. The basic idea is that there are three traits (a fourth trait, intuition, is used in some online biorhythms, see for example http://www.geocities.com/RainForest/8419/applet.html.)

Each trait is governed by a sinusoidal curve with a periodicity that depends on the trait, so that a physical cycle is 23 days long, an emotional cycle is 28 days long and an intellectual cycle is 33 days long. All cycles start on the day you're born.

Since the emotional cycle is 28 days long, your emotional peak occurs on day 7 of your life (and then on day 28 + 7, 56 + 7, etc.). Your emotional level is at zero on day 14 (and on day 28). Your emotional leval is at its lowest on day 21 (and on day 28 + 21, 56 + 21, etc.).

Because the curve is sinusoidal, it's as though it behaves like the function y = sin( (2.0*PI/28) * x), since the period of this function is 28. Here x could be the number of days a person has been alive, y provides a value between -1 and 1 that can be interpreted as the "level" of a biorhythm cycle (1 is max, 0 is a potential critical crossing). Changing 28 to 33 or 23 provides a different function for each biorhythmic trait.

If all three traits cross the x-axis on the same day, a critical day occurs.

Part I

Write a program called bio.cpp that prompts the user for a birth date, and then prints the dates of the next high and low for each cycle: emotional, physical, and intellectual, that occur on or after the date on which the program is run.

For example, assume the program below is run on September 27, 1999 and uses a birth date of the same day to illustrate the cycles.

prompt> bio
enter birth date, month day year: 9 27 1999

physical high:  October 3 1999
physical low:   October 14 1999


emotional high: October 4 1999
emotional low:  October 18 1999



intellectual high: October 5 1999
intellectual low:  October 22 1999


Low and high days are rounded off so that the physical high which should occur on day 23/4 = 5.75 is rounded to day six after birth. The physical zero is on day 23/2 = 11.5 which is rounded up (all .5 values are rounded up). The physical low is day 23*0.75 = 17.25 = day 17.

Part II

Write a program biograph.cpp that will prompt the user for a birth date and plot the curve representing the intellectual cycle for that birth date starting on the day the program is run and plotting for at least 35 days (see the example below).

To plot using asterisks and other ASCII symbols you'll need to use the value of the sin function that governs the intellectual cycle: y = sin( (2.0*PI/33) * x) and scale it by half the width of the screen, for example. In the plot below the maximum value used is 25 "units".

Each line of output corresponds to a date. Print spaces before (or after) the asterisk and print either a | for the x-axis or a Date/day for every other day (see the output below.)

prompt> biograph
enter birth month day year: 9 27 1999

Birthday: September 27 1999
                               *                            
                               |   *                        
                              29         *                  
                               |               *            
                               1                   *        
                               |                       *    
                               3                         *  
                               |                           *
                               5                           *
                               |                           *
                               7                           *
                               |                       *    
                               9                     *      
                               |                 *          
                              11           *                
                               |       *                    
                              13 *                          
                           *   |                            
                     *        15                            
                 *             |                            
           *                  17                            
       *                       |                            
     *                        19                            
 *                             |                            
 *                            21                            
 *                             |                            
 *                            23                            
   *                           |                            
     *                        25                            
         *                     |                            
             *                27                            
                   *           |                            
                         *    29                            
                             * |                            
                              31   *                        
                               1         *                  
                               |               *            
                               3                   *        
                               |                       *    
                               5                         *  
                               |                           *
                               7                           *
                               |                           *
                               9                           *
                               |                       *    


Extra Credit (worth 5 program points)

Write a program named critical.cpp to find every critical day in a person's life (days on which all three traits have a zero value) assuming a person lives for 80 years.

Submitting

To submit use
  submit_cps006 assign3 mathquiz.cpp bio.cpp biograph.cpp README

In your README include how long you worked on the programs, your impressions of the program and comments you have about the assignment, and list of people with whom you collaborated.

If you did the extra credit, include critical.cpp on the submit line above. The extra credit must be done by the same due date as the assignment.