I havent studied C# for about 2 yrs and was recently given this simple problem but I'm a little lost on how to start solving this any help would be great

Write a program to grade a set of true/false tests. There are 15 true/false questions. True is represented by T, and false is represented by F. The key to the quiz and the student responses is on a file called “quiz.dat, which you create. The first line of the file is the key, each subsequent line is comprised of a student’s responses immediately followed by the student’s name. For each student write out the name followed by the number answered correctly and the number missed. You do not know how many student records are in the file. Use stream failure to terminate processing.

Input

The data as describe in the above problem statement. Create a data file that contains information for at least 10 students. Below are the first three lines of the input file. Remember, you do not know how many student records are in the file. Your program should be able to handle a data file of 5 or 500 lines without any code changes.

FTFTFTTTFFFTFFT
TFFTFTTFTFFTFFTJoe Jones
FTFTFTTFFFTFFFTJanet Jerome

Output

Print to the screen, each student’s name followed by the number of correct answers and the number of incorrect answers.

Im not trying for an easy answer just some useful tips I know i need to initialize with include fstream iostream and create my dat folder and use getline to call it but i just dont really know what to do from there any little hints would be great.

Start by reading the key:

#include <string>

std::string key;
std::getline(fin, key);

Then work your way through each of the records:

while (true) {
  int n = 0; // Number of correct answers

  // Scores first
  for (std::string::size_type i = 0; i < key.length(); i++) {
    char tf;

    if (!fin.get(tf))
      break;
    else if (tf == key[i])
      ++n;
  }
  if (!fin)
    break;

  // Get the student's name
  std::string student;
  std::getline(fin, student);

  // Display the result
  std::cout<< student <<": "<< n <<std::endl;
}

Thanks for the help, this was pretty much the outline i needed thanks again.

This article has been dead for over six months. Start a new discussion instead.