Solution Roadmap



#include <fstream>
#include <iostream>
#include <iomanip>
#include <assert.h>   

using namespace std ;

/*  Function prototypes (see function definitions below for comments 
    explaining what each function should do. */

void makeRepTitles() ;
void getKey (char key[], ifstream & infile) ;
void doGrading(char key[], ifstream & infile) ;
void gradeOneTest (int studentNum, char key[], ifstream & infile) ;

int main(void)   
{   
   /*
      The main steps in this program could be:

      Declare and open input file.

      Declare array for the key.

      Call getKey to copy the key from the file to the array.

      Call makeRepTitles to make the headings on the screen.

      Call doGrading to do the grading and put the results on the screen.

      Close the input file.

   */
   return 0;
}   

void makeRepTitles()
{
   /* This could be a function that puts the following on the screen:  
      Student Number      Number Correct       PASS/FAIL
      (put the appropriate number of blank lines before and after.)  */
}

void getKey (char key[], ifstream & infile)
{
   /* In this function, you could declare a loop control variable, and make a
      for-loop that reads/copies the key, one character at a time into the
      array.  */
}

void doGrading(char key[], ifstream & infile)
{
   /* In this function you could:
       * Declare a variable to represent the number of tests to grade.

       * Read/copy the value of the integer (number of tests) 
         from the input file stream into the variable.   

       * Declare a variable to use to control a for-loop.

       * Make a for-loop that calls gradeOneTest for each test.

       * Finish by printing any blank lines that may be needed for the display.
   */
}

void gradeOneTest (int studentNum, char key[], ifstream & infile)
{
   /* Steps that would work here:

      Declare int numCorrect to represent the number of correct answers.

      Initialize numCorrect to 25.
  
      Declare a variable int questionNum to control a for-loop.

      Declare a variable char theAnswer for storing one test answer at a time.

      Make a for-loop that reads 25 answers.  
      Each time through the for-loop, it reads one answer into 
      this variable: theAnswer,
      and executes an if-statement:  
      If theAnswer is not equal to key[questionNum]
      then subtract 1 from numCorrect.

      After the end of the for-loop, place code that writes studentNum 
      and numCorrect on the screen in the appropriate locations.
      After that, if numCorrect is 15 or more, write "PASS" 
      else write "FAIL".
      In the code that puts the results on the screen, 
      Use setw() manipulators to make the columns line up.
   */
}