home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c021 / 7.img / EXAMPLES.ZIP / PLOTEMP3.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-04  |  2.5 KB  |  118 lines

  1. /* PLOTEMP3.C--Example from Chapter 7 of Getting Started */
  2.  
  3. /* This program creates a table and a bar chart plot from a
  4.    set of temperature readings */
  5.  
  6. #include <conio.h>
  7. #include <ctype.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. /* Prototypes */
  12.  
  13. void get_temps(void);
  14. void table_view(void);
  15. void min_max(void);
  16. void avg_temp(void);
  17. void graph_view(void);
  18. void save_temps(void);
  19. void read_temps(void);
  20.  
  21. /* Global defines */
  22.  
  23. #define TRUE      1
  24. #define READINGS  8
  25.  
  26. /* Global data structures */
  27.  
  28. int temps[READINGS];
  29.  
  30. int main(void)
  31. {
  32.    char choice;
  33.  
  34.    while (TRUE)
  35.    {
  36.       printf("\nTemperature Plotting Program Menu\n");
  37.       printf("\tE - Enter temperatures for scratchpad\n");
  38.       printf("\tS - Store scratchpad to disk\n");
  39.       printf("\tR - Read disk file to scratchpad\n");
  40.       printf("\tT - Table view of current data\n");
  41.       printf("\tG - Graph view of current data\n");
  42.       printf("\tX - Exit the program\n");
  43.       printf("\nPress one of the above keys: ");
  44.  
  45.       choice = toupper(getch());
  46.       switch   (choice)
  47.       {
  48.          case 'E': get_temps();  break;
  49.          case 'S': save_temps(); break;
  50.          case 'R': read_temps(); break;
  51.          case 'T': table_view(); break;
  52.          case 'G': graph_view(); break;
  53.          case 'X': exit(0);
  54.       }
  55.    }
  56. }
  57.  
  58. /* Function definitions */
  59.  
  60. void get_temps(void)
  61. {
  62.    char inbuf[130];
  63.    int  reading;
  64.  
  65.    printf("\nEnter temperatures, one at a time.\n");
  66.    for (reading = 0; reading < READINGS; reading++)
  67.    {
  68.       printf("\nEnter reading # %d: ", reading + 1);
  69.       gets(inbuf);
  70.       sscanf(inbuf, "%d", &temps[reading]);
  71.  
  72.       /* Show what was read */
  73.       printf("\nRead temps[%d] = %d", reading, temps[reading]);
  74.    }
  75. }
  76.  
  77. void table_view(void)
  78. {
  79.    int reading;
  80.  
  81.    clrscr();       /* clear the screen */
  82.    printf("Reading\t\tTemperature(F)\n");
  83.  
  84.    for (reading = 0; reading <= READINGS; reading++)
  85.       printf("%d\t\t\t%d\n", reading + 1, temps[reading]);
  86.  
  87.    min_max();
  88.    printf("Minimum temperature: \n");
  89.    printf("Maximum temperature: \n");
  90.    avg_temp();
  91.    printf("Average temperature: \n");
  92. }
  93.  
  94. void min_max(void)
  95. {
  96.    printf("\nExecuting min_max().\n");
  97. }
  98.  
  99. void avg_temp(void)
  100. {
  101.    printf("\nExecuting avg_temp().\n");
  102. }
  103.  
  104. void graph_view(void)
  105. {
  106.    printf("\nExecuting graph_view().\n");
  107. }
  108.  
  109. void save_temps(void)
  110. {
  111.    printf("\nExecuting save_temps().\n");
  112. }
  113.  
  114. void read_temps(void)
  115. {
  116.    printf("\nExecuting read_temps().\n");
  117. }
  118.