Answer to Question #286343 in C for Rupa

Question #286343

Write a simple application to conduct a computer based quiz. The quiz consists of questions with answers true or false only. Suppose the questions are present in a text file Questions.txt, in the following format:


First line of the file consists of the number of questions present in the file and the rest of the file consists of the question followed by answer in separate lines. Your program should display questions one by one, and prompt the user to enter his answer, at the end display the score of the user. And also display the questions the user has wrongly answered along with the correct answer. (You can assume that each question is of length at most 80 characters). Use command line arguments to provide the text file to the program.


A sample Questions.txt file:

3

There are one thousand years in a CENTURY.

False

DOZEN is equivalent to 20.

False

The past tense of FIND is FOUND.

True


1
Expert's answer
2022-01-11T09:44:35-0500
#include <string>
#include <fstream>
#include <iostream>


using namespace std;



int main(int argc, char* argv[])
{
    ifstream infile("quizfile.txt");
    string line;
    int score = 0;
    string answer = "";
    int count = 0;
    while (std::getline(infile, line))
    {
      
        cout << line;
        
        cin >> answer;
        std::getline(infile, line);
        if (answer == line)
        {
            score++;
        }
    }
    std::cout << score << std::endl;


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS