home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / HR / HR022.ZIP / VEFC21.C next >
Text File  |  1989-05-25  |  7KB  |  223 lines

  1. /**********************************************************************/
  2. /***  vefc.c                            WA8YCD  ***/
  3. /***  Ver 2.1                         25 May 89  ***/
  4. /***                                    ***/
  5. /***  This utility is made available to all amateurs or potential   ***/
  6. /***  amateurs for use in training and examinations. For VEs, it    ***/
  7. /***  can be used to create legal tests for any level. For the        ***/
  8. /***  student, it can be used to generate sample tests.         ***/
  9. /***                                    ***/
  10. /***  Compiled using Turbo C Version 1.0 under MS-DOS 3.2        ***/
  11. /***  ___________________________________________            ***/
  12. /***  Copyright (c) 1989 Robert L. West, Jr.                ***/
  13. /***                                    ***/
  14. /***  Distribution of this program is allowed provided no monetary  ***/
  15. /***  compensation beyond reasonable reproduction costs is made.    ***/
  16. /***  The question pools are in the public domain. The program is   ***/
  17. /***  provided as a public service to the amateur community.        ***/
  18. /**********************************************************************/
  19.  
  20. #include <stdio.h>
  21.  
  22. #define  MIN_LTR      65
  23. #define  MAX_LTR      91
  24. #define  MIN_NUM      48
  25. #define  MAX_NUM      58
  26. #define  PERIOD       46
  27. #define  COMMA          44
  28. #define  DN          47
  29. #define  QUERY          63
  30. #define  BT          45
  31. #define  AR          64
  32. #define  SK          36
  33. #define  LENGTH_5     25
  34. #define  LENGTH_13    65
  35. #define  LENGTH_20   100
  36. #define  TRUE           1
  37. #define  FALSE           0
  38.  
  39. main(argc, argv)
  40. int argc;
  41. char *argv[];
  42. {
  43.   int     i, inch=0, no_zeros=1, output_to_file;
  44.   long     counts[256];
  45.   float  test_time_5, test_time_13, test_time_20;
  46.   char    c;
  47.   FILE  *fopen(), *infile, *outfile;
  48.  
  49. /* first, see if the correct number of parameters are given... */
  50.   if (argc < 2)
  51.   { printf("\nusage:\n    freq input-filename [output-filename]\n");
  52.     printf("\n   if output-filename is omitted display appears \n");
  53.     printf("   on the screen.\n\n");
  54.     exit();
  55.   }
  56.  
  57. /* next, see if the first parameter can be opened as an input file... */
  58.   if ((infile = fopen(argv[1], "rb")) == NULL)
  59.   { printf("\nUnable to open input file, \"%s\"!\n\n", argv[1]);
  60.     printf("vefc:  abnormal termination.\n");
  61.     exit();
  62.   }
  63.  
  64. /* now, see if the second parameter can be opened as an output file... */
  65.   if (argc == 3)
  66.   { if ((outfile = fopen(argv[2], "w")) == NULL)
  67.     { printf("\nUnable to open output file, \"%s\"!\n\n", argv[2]);
  68.       printf("vefc:  abnormal termination.\n");
  69.       exit();
  70.     }
  71.   }
  72.   else
  73.   { if ((outfile = fopen("CON", "w")) == NULL)
  74.     { printf("\nUnable to open console for output!\n\n");
  75.       printf("vefc:  abnormal termination.\n");
  76.       exit();
  77.     }
  78.   }
  79.  
  80. /*************************************************************************/
  81. /***                                       ***/
  82. /*************************************************************************/
  83.  
  84.   fprintf(outfile, "- VE CODE EXAM VALIDATER ver 2.1,  05/25/89 -\n");
  85.   fprintf(outfile, "\n");
  86.   fprintf(outfile, "      ....5...10...15...20...25\n");
  87.   fprintf(outfile, "%5d ", inch);
  88.  
  89.   for (i=0; i<256; i++)
  90.     counts[i]=0;
  91.  
  92.   while((c=getc(infile)) != EOF)
  93.   {
  94.     if (c>='a' && c<='z')
  95.       c=c-'a'+'A';
  96.  
  97.     switch((int)c)
  98.     {
  99.       case 'A': case 'F': case 'K': case 'P': case 'U':
  100.       case 'B': case 'G': case 'L': case 'Q': case 'V':
  101.       case 'C': case 'H': case 'M': case 'R': case 'W':
  102.       case 'D': case 'I': case 'N': case 'S': case 'X':
  103.       case 'E': case 'J': case 'O': case 'T': case 'Y':
  104.       case 'Z': case '/': case '@': case '$': case '-':
  105.     counts[(int)c]++;
  106.     fprintf(outfile, "%c", c);
  107.     if  ( !(++inch % 25) )
  108.       fprintf(outfile, "\n%5d ", inch);
  109.     break;
  110.  
  111.       case '0': case '1': case '2': case '3': case '4':
  112.       case '5': case '6': case '7': case '8': case '9':
  113.       case '.': case ',': case '?':
  114.     counts[(int)c]++;
  115.     fprintf(outfile, "%c", c);
  116.     if  ( !(++inch % 25) )
  117.       fprintf(outfile, "\n%5d ", inch);
  118.     fprintf(outfile, "_");
  119.     if  ( !(++inch % 25) )
  120.       fprintf(outfile, "\n%5d ", inch);
  121.     break;
  122.  
  123.       default:
  124.     break;
  125.     }
  126.   }
  127.   fclose(infile);     /* We're finished with the input file, so close it */
  128.  
  129.   no_zeros = TRUE;
  130.   for (i=MIN_LTR; i<MAX_LTR; i++)
  131.     no_zeros = no_zeros && counts[i];
  132.   for (i=MIN_NUM; i<MAX_NUM; i++)
  133.     no_zeros = no_zeros && counts[i];
  134.   no_zeros = no_zeros && counts[PERIOD];
  135.   no_zeros = no_zeros && counts[COMMA];
  136.   no_zeros = no_zeros && counts[DN];
  137.   no_zeros = no_zeros && counts[QUERY];
  138.   no_zeros = no_zeros && counts[BT];
  139.   no_zeros = no_zeros && counts[AR];
  140.   no_zeros = no_zeros && counts[SK];
  141.  
  142.   if (no_zeros)
  143.   {
  144.     fprintf(outfile, "\n");
  145.     fprintf(outfile, "\n");
  146.     fprintf(outfile, "All required characters are contained in this test.\n");
  147.   }
  148.   else
  149.   {
  150.     fprintf(outfile, "\n");
  151.     fprintf(outfile, "\n");
  152.     fprintf(outfile, "The following characters are in this test:\n");
  153.  
  154.     for (i=MIN_LTR; i<MAX_LTR; i++)
  155.       if (counts[i])
  156.     fprintf(outfile, "%s ", &i);
  157.  
  158.     for (i=MIN_NUM; i<MAX_NUM; i++)
  159.       if (counts[i])
  160.     fprintf(outfile, "%s ", &i);
  161.  
  162.     if (counts[PERIOD])
  163.       fprintf(outfile, "%c ", PERIOD);
  164.     if (counts[COMMA])
  165.       fprintf(outfile, "%c ", COMMA);
  166.     if (counts[DN])
  167.       fprintf(outfile, "%c ", DN);
  168.     if (counts[QUERY])
  169.       fprintf(outfile, "%c ", QUERY);
  170.     if (counts[BT])
  171.       fprintf(outfile, "%c ", BT);
  172.     if (counts[AR])
  173.       fprintf(outfile, "%c ", AR);
  174.     if (counts[SK])
  175.       fprintf(outfile, "%c ", SK);
  176.  
  177.     fprintf(outfile, "\n");
  178.     fprintf(outfile, "The following characters are not in this test:\n");
  179.  
  180.     for (i=MIN_LTR; i<MAX_LTR; i++)
  181.       if (!counts[i])
  182.     fprintf(outfile, "%s ", &i);
  183.  
  184.     for (i=MIN_NUM; i<MAX_NUM; i++)
  185.       if (!counts[i])
  186.     fprintf(outfile, "%s ", &i);
  187.  
  188.     if (!counts[PERIOD])
  189.       fprintf(outfile, "%c ", PERIOD);
  190.     if (!counts[COMMA])
  191.       fprintf(outfile, "%c ", COMMA);
  192.     if (!counts[DN])
  193.       fprintf(outfile, "%c ", DN);
  194.     if (!counts[QUERY])
  195.       fprintf(outfile, "%c ", QUERY);
  196.     if (!counts[BT])
  197.       fprintf(outfile, "%c ", BT);
  198.     if (!counts[AR])
  199.       fprintf(outfile, "%c ", AR);
  200.     if (!counts[SK])
  201.       fprintf(outfile, "%c ", SK);
  202.  
  203.     fprintf(outfile, "\n");
  204.   }
  205.  
  206.   test_time_5  = (float) inch / LENGTH_5;
  207.   test_time_13 = (float) inch / LENGTH_13;
  208.   test_time_20 = (float) inch / LENGTH_20;
  209.  
  210.   fprintf(outfile, "\n");
  211.   fprintf(outfile, "This test contains %5d characters\n", inch);
  212.   fprintf(outfile, "\n");
  213.   fprintf(outfile, "This test lasts %8.2f minutes at  5 wpm.\n",
  214.            test_time_5);
  215.   fprintf(outfile, "This test lasts %8.2f minutes at 13 wpm.\n",
  216.            test_time_13);
  217.   fprintf(outfile, "This test lasts %8.2f minutes at 20 wpm.\n",
  218.            test_time_20);
  219.  
  220.   fclose(outfile);
  221.   printf("\n\nvefc:  normal termination.\n");
  222. }
  223.