Biorhythms

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://arakni.com/biorhythm/main.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 are 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 level is at its lowest on day 21 (and on day 28 + 21, 56 + 21, etc.).

Because the curve is sinusoidal, it is 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 biorhythms.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 easily illustrate the cycles.

enter birth date (month day year): 9 27 1999
Birthday:  September 27 1999
Today:     September 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.)

enter birth month day year: 9 27 1999
Birthday:  September 27 1999
Today:     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                           *
                               |                       *

Part III

Write a program named bioritical.cpp that finds 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.

For example, assume the program below is run for someone whose birth date is September 27, 1999.

enter birth date (month day year): 9 27 1999
Birthday:  September 27 1999

September 27 1999
October 30 2028
December 3 2057