home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / tcpp / examples / barchart.c next >
Encoding:
C/C++ Source or Header  |  1990-06-10  |  1.5 KB  |  58 lines

  1. #include           <stdio.h>
  2. #include           <stdlib.h>
  3. #include           <float.h>
  4. #include           <graphics.h>
  5. #include           <math.h>
  6.  
  7. #define            MAX        50
  8. #define            ARRAYMAX   10
  9.  
  10. void makegraph(float p[]);
  11.  
  12. void main(void)
  13. {
  14.   int              i;
  15.   int              scores[ARRAYMAX];
  16.   float            percents[ARRAYMAX], mantissa;
  17.  
  18.   for (i = 0; i < ARRAYMAX; i++)
  19.     {
  20.     printf("\nBewertung zwischen 0 und %d eingeben:  ", MAX);
  21.     scanf("%d", &scores[i]);
  22.     }
  23.   for (i = 0; i < ARRAYMAX; i++)
  24.     percents[i] = ((float) scores[i]) / MAX;
  25.  
  26.   printf("\n\n\n\tBEWERTUNG\tPROZENT");
  27.   for (i = 0; i < ARRAYMAX; i++)
  28.     printf("\n%d. \t%d\t\t%3.0f", i + 1, scores[i], (percents[i] * 100));
  29.   getch();
  30.   makegraph(percents);
  31. }
  32.  
  33. void makegraph(float p[])
  34. {
  35.   int              g_driver, g_mode;
  36.   int              i, left, top, wide, bottom, deep;
  37.   int              midx, midy;
  38.  
  39.   detectgraph(&g_driver, &g_mode);
  40.   initgraph(&g_driver, &g_mode, "..\\bgi");
  41.   wide = (int)((getmaxx()) / ((ARRAYMAX * 2 ) + 1));
  42.   bottom = getmaxy() - 20;
  43.   deep = (int) (wide / 4);
  44.   left = wide;
  45.   for (i = 0; i < ARRAYMAX; i++)
  46.     {
  47.     top = (bottom) - ((int)(p[i] * 300));
  48.     bar3d(left, top, (left + wide), bottom, deep, 1);
  49.     left += (wide * 2);
  50.     midx = getmaxx()/2 - (textwidth("Prozentanteile, Exam 1A")/2);
  51.     midy = getmaxy() - 10;
  52.     outtextxy(midx, midy, "Prozentanteile, Exam 1A");
  53.     }
  54.   getch();
  55.   closegraph();
  56.   return;
  57. }
  58.