Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some assistance with this C++ assignment... Note: Interface/menu must be

ID: 3845290 • Letter: I

Question

I need some assistance with this C++ assignment...
Note: Interface/menu must be separate from implementation (ie. classes separated out into separate files, with .h files)


- I need to write a program that will read questions and their answers from a separate input file (questions.txt).

- Read the questions and answers into an appropriate data structure, then display the first question and accept an answer from the the user.

- If the answer is correct, the program should go on to the next question. If it is not correct, store the question in a list.

- When the question list is exhausted, the questions that were missed should be displayed again (in their original order).

- Keep a count of the correct answers and display the final count.

- Record the users name and score and write it out to a file.

- Also, display the correct answer when necessary in the second round of questioning.

- Write a "supervisor" program that will allow a supervisor to add new questions, and review student grades.


Example setup of questions.txt:

Which metal is heavier, silver or gold?
Answer: Gold

How many legs do butterflies have?
Answer: Six

Which is the country with the most people?
Answer: China

Which indoor sport is the most popular in the US?
Answer: Basketball

What is Aurora Borealis commonly known as?
Answer: Northern Lights

Which is the non contagious disease that is the most common in the world?
Answer: Tooth Decay

Which famous person was the teddy bear named?
Answer: Theodore Roosevelt

Thanks in advance for the help!

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{
   ifstream myfile("questions.txt");
   string line, question, answer, user_answer;

   vector<string> skipped_question;
   vector<string>::iterator itr1;

   map<string, string> question_answer_list;
   map<string, string>::iterator itr2;
   int score=0;

   if(myfile.is_open())
   {
       while(getline(myfile, line))
       {
           question = line;
           getline(myfile, answer);
           answer = answer.substr(8);
           question_answer_list[question] = answer;

           cout<<question<<" ";
           cin>>user_answer;
           if(user_answer.compare(answer)==0)
           {
               score++;
           }
           else
           {
               skipped_question.push_back(question);
           }
       }

       cout<<"Second turn for skipped or wrong questions: ";
       for(itr1 = skipped_question.begin(); itr1!=skipped_question.end(); ++itr1)
       {
           cout<<*itr1<<" ";
           cin>>user_answer;
           if(user_answer.compare(question_answer_list[*itr1])==0)
           {
               score++;
           }
       }

       cout<<"Correct answers to all questions are as follows: ";
       for(itr2 = question_answer_list.begin(); itr2!=question_answer_list.end(); ++itr2)
       {
           cout<<" "<<itr2->first<<" "<<itr2->second;
       }

       cout<<" Final score is: "<<score<<" ";
       myfile.close();
   }
   return 0;
}

Supervisor's Program-

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
   ofstream myfile;
   string question, answer;
   myfile.open("questions.txt", fstream::app);
   getline(cin, question);
   getline(cin, answer);
   myfile<<" "<<question<<" Answer: "<<answer;
   return 0;
}