home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / pcgraphc.zip / BIOPLOT.C next >
C/C++ Source or Header  |  1989-02-04  |  6KB  |  227 lines

  1. /* biorythm plotting program ported from BASIC */
  2.  
  3. #include <stdio.h>
  4. #include "graph.h"
  5. #include <math.h>
  6.  
  7. char *month[13] = { " ", "January", "February", "March", "April", "May",\
  8.     "June", "July", "August", "September", "October", "November",\
  9.     "December" };
  10.  
  11. int i, j, k, a[13] = {0, 10, 8, 5, 5, 3, 4, 4, 6, 9, 10, 8, 8 }, x;
  12. int b, f, h, g, e, c, z;
  13. unsigned m, d, y;
  14. double pi = 3.1415926;
  15. long date;
  16. char instr[160], outmsg[80];
  17.  
  18. void linput ();
  19. void pause();
  20.  
  21. main ()
  22.     {
  23.     linput ( "Do you want an explanation (N/y)? " , instr);
  24.     if ( tolower ( instr[0] ) == 'y' )
  25.         {
  26.         printf ( "\n\n  A biorythm is a theoretical metabolic cycle that is\n" );
  27.         printf ( "constantly going on in piople, starting at birth.  To date,\n" );
  28.         printf ( "3 cycles have been discovered.  They are:\n\n" );
  29.         printf ( "Physical:\n" );
  30.         printf ( "  The physical cycle is 23 days logn.  This cycle is said to\n" );
  31.         printf ( "afffect muscle fibers, and, therefore, physical strength,\n" );
  32.         printf ( "endurance, and general physical well-being.\n\n" );
  33.         printf ( "Sensitivity:\n" );
  34.         printf ( "  The sensitivity cycle is 28 days long.  It is said to be closely\n" );
  35.         printf ( "related to the nervous system, affecting cooperation, friendliness,\n" );
  36.         printf ( "and optimism.  On the down-side of this cycle, one is most likely to\n" );
  37.         printf ( "be irritable, frustrated, and stubborn.\n\n" );
  38.         printf ( "Cognitive:\n" );
  39.         printf ( "  The cognitive cycleis 33 days long.  It affects the thought\n" );
  40.         printf ( "processes, the abilities to privide fast, accurate answers, to\n" );
  41.         printf ( "absorb information, and to create.   The down-side of this cycle\n" );
  42.         printf ( "is probably a good time to review old concepts.\n\n" );
  43.         printf ( "Press ENTER for additional explanations." );
  44.         gets (instr);
  45.         printf ( "\n\nThe up-side of the cycle is the discharge period when you are the\n" );
  46.         printf ( "most able in the areas that the cycle affects.  The down-side of the\n" );
  47.         printf ( "cycle is a recuperative period.  Neither of these is necessarily\n" );
  48.         printf ( "good or bad, but it is a good idea to do the most important things\n" );
  49.         printf ( "on the up-side of the cycle, and to rest on the down-side.\n\n" );
  50.         printf ( "  The critical day, on the other hand, is definitely a bad day.\n" );
  51.         printf ( "A good analogy is a light bulb-- the times it is most likely\n" );
  52.         printf ( "to burn out are when it is turned on or turned off.  The times you\n" );
  53.         printf ( "most likely to face an accident are on the days when the cycles change\n" );
  54.         printf ( "polarity.\n\n" );
  55.         }
  56.     do
  57.         {
  58.         k = 1;
  59.         linput ( "Enter date of birth (MMDDYY) ", instr );
  60.         i = sscanf ( instr, "%ld", &date );
  61.         if ((i == 0) || (i == EOF))
  62.             {
  63.             printf ( "\nInvalid date\n\n" );
  64.             k = 0;
  65.             }
  66.         else
  67.             {
  68.             m = date / 10000;
  69.             if ((m < 1) || (m > 12))
  70.                 {
  71.                 printf ( "Invalid month\n\n" );
  72.                 k = 0;
  73.                 }
  74.             else
  75.                 {
  76.                 d = (unsigned) ((date - m * 10000)) / 100;
  77.                 if ((d < 1) || (d > 31))
  78.                     {
  79.                     printf ( "Invalid day\n\n" );
  80.                     k = 0;
  81.                     }
  82.                 }
  83.             y = date - m * 10000 - d * 100;
  84.             if ((y < 0) || (y > 99))
  85.                 {
  86.                 printf ( "Invalid year\n\n" );
  87.                 k = 0;
  88.                 }
  89.             y = y + 1900 - 100 * (y > 89);    /* test for birthday-year after current year */
  90.             }                /* implies born 100 year ago */
  91.         }
  92.     while (k == 0);
  93.     do
  94.         {
  95.         linput ( "Enter year to be plotted ", instr );
  96.         i = sscanf ( instr, "%d", &x );
  97.         if ((i == 0) || (i == EOF)) printf ( "\nA numeric value is required\n\n" );
  98.         else
  99.             {
  100.             x =  (x > 100) ? x : x + 1900;
  101.             if (x < 1753) printf ( "\nGregorian calendar doesn't begin until 1753\n\n" );
  102.             }
  103.         }
  104.     while ((k == 0) || (k == EOF) || (x < 1753));
  105.  
  106. printf ( "month %d, day %d, year %d, plot year %d\n", m, d, y, x );
  107.     do
  108.         {
  109.         linput ( "Enter number of month to plot ", instr );
  110.         i = sscanf ( instr, "%d", &b );
  111.         if ((i == 0) || (i == EOF))
  112.             printf ( "\nA numeric value is required\n" );
  113.         else
  114.             if ((b < 1) || (b > 12))
  115.                 printf ( "\nMonth number out of range\n" );
  116.         }
  117.     while (( i == EOF) || (i == 0) || ( b < 1) || (b > 12));
  118.     g_init ( CGA_640x200 );
  119.     z = fnt (m + 1) - fnt (m) + fnl (y) * (m == 2) - d;
  120.     c = 365 + fnl (y) * ((m <= 2) && ((m * d) != 58)) - fnt (m + 1) + z;
  121.     if (x == y) 
  122.         c -= (365 + fnl (x) * (b == 1) - fnt (b) );
  123.     else
  124.         {
  125.             if ((x + 1) != y)
  126.                 {
  127.                 for (i = y + 1; i < x; ++i) c += 365 + fnl (i);
  128.                 }
  129.             c += fnt (b) + fnl (x) * (b > 2);
  130.         }
  131.     e = fnt (b + 1) - fnt (b) + fnl (x) * (b == 2);
  132.     scale (0, 88, 0, 68);
  133.     f = a[b];
  134.     f = f + 6;
  135.     csize(5, 0, 0);
  136.     move (44, 60);
  137.     lorg (4);
  138.     labelf ("%s %4d",month[b], x);
  139.     scale (0, 31, -1.5, 1.5);
  140.     move (1, 0);
  141.     for (i = 2; i <= 31; ++i)    /* draw axes of graph */
  142.         {
  143.         draw (i, 0);
  144.         move (i, -.03);
  145.         draw (i, .03);
  146.         if ((i == 7) || (i == 14) || (i == 21) || (i == 28))
  147.             {
  148.             move (i,-.06);
  149.             draw (i, +.06);
  150.             }
  151.         move (i, 0);
  152.         }
  153.     move (1, -1);
  154.     draw (1.15, -1);
  155.     move (1, -1);
  156.     draw (1, 1);
  157.     draw (1.15, 1);
  158.     unclip ();
  159.     lorg (6);
  160.     csize ((15 / 4.54), 0, 0);
  161.     for (i = 7; i <= 28; i += 7)
  162.         {
  163.         move (i, -.10);
  164.         labelf ("%d", i);
  165.         }
  166.     g = 5;
  167.     move (0, 0);
  168.     lorg (5);
  169.     csize (2.8, 0, 0);
  170.     for (h = 23; h <= 33; h += 5)
  171.         {
  172.         line_type (2 * (h - 23) / 5 + 1, 0);
  173.         penup ();
  174.         f = 1;
  175.         for (i = c + 1; i <= c + e; ++i)
  176.             {
  177.             plot (f, .8 * sin (i * (2 * pi / h)) ,1);
  178.             ++f;
  179.             }
  180.         penup ();
  181.         ++g;
  182.         }
  183.     scale (0, 88, 0, 68);
  184.     unclip ();
  185.     lorg (2);
  186.     for (j = 1; j <= 5; j += 2)
  187.         {
  188.         line_type (1,0);
  189.         move (20, 12 - 1.3 * j);
  190.         switch (j)
  191.             {
  192.             case 1: labelf ("Physical");
  193.                 break;
  194.             case 3: labelf ("Sensitivity");
  195.                 break;
  196.             case 5: labelf ("Cognitive");
  197.                 break;
  198.             }
  199.         line_type (j,0);
  200.         move (45, 12 - 1.3 * j);
  201.         draw (65, 12 - 1.3 * j);
  202.         }
  203.     pause ();
  204.     graphics_off ();
  205.     }
  206.  
  207.  
  208. void linput (msg, input) char *msg, *input;
  209.     {
  210.     printf ( "%s ", msg );
  211.     gets ( input );
  212.     sscanf ( input, " %c", input );
  213.     return;
  214.     }
  215. int fnt (x) int x;
  216.     {
  217.     return 31 * (x - 1) - floor ( 2.2 + .4 * x) * (x > 2);
  218.     }
  219. int fnl (x) int x;
  220.     {
  221.     return ((x == (4 * (x / 4))) && (x != (100 * (x / 100))) || (x = (400 * (x / 400))));
  222.     }
  223. void pause ()
  224.     {
  225.     while (getch () != '\r');    /* wait for a <cr> */
  226.     return;
  227.     }