C++ Provide a different implementation of ChoiceQuestion. Instead of storing the choices in a vector, the add_choice function should add the choice to the question text. For this purpose, an add_line function has been added to the Question class. Complete the following file: choicequestion.cpp  Use the following files: choicequestion.h #ifndef CHOICEQUESTION_H #define CHOICEQUESTION_H #include using namespace std; #include "question.h" class ChoiceQuestion : public Question { public: /** Constructs a choice question with a given text and no choices. @param question_text the text of this question */ ChoiceQuestion(string question_text); /** Adds an answer choice to this question. @param choice the choice to add @param correct true if this is the correct choice, false otherwise */ void add_choice(string choice, bool correct); private: int num_choices; }; #endif question.h #ifndef QUESTION_H #define QUESTION_H #include using namespace std; class Question { public: /** Constructs a question with empty question and answer. */ Question(); /** @param line the line of text to add to this question */ void add_line(string line); /** @param correct_response the answer for this question */ void set_answer(string correct_response); /** @param response the response to check @return true if the response was correct, false otherwise */ virtual bool check_answer(string response) const; /** Displays this question. */ virtual void display() const; private: string text; string answer; }; #endif questiondemo.cpp

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 2RQ
icon
Related questions
Question

C++

Provide a different implementation of ChoiceQuestion. Instead of storing the choices in a vector, the add_choice function should add the choice to the question text. For this purpose, an add_line function has been added to the Question class.

Complete the following file:

choicequestion.cpp 

Use the following files:

choicequestion.h

#ifndef CHOICEQUESTION_H #define CHOICEQUESTION_H #include <string> using namespace std; #include "question.h" class ChoiceQuestion : public Question { public: /** Constructs a choice question with a given text and no choices. @param question_text the text of this question */ ChoiceQuestion(string question_text); /** Adds an answer choice to this question. @param choice the choice to add @param correct true if this is the correct choice, false otherwise */ void add_choice(string choice, bool correct); private: int num_choices; }; #endif

question.h

#ifndef QUESTION_H #define QUESTION_H #include <string> using namespace std; class Question { public: /** Constructs a question with empty question and answer. */ Question(); /** @param line the line of text to add to this question */ void add_line(string line); /** @param correct_response the answer for this question */ void set_answer(string correct_response); /** @param response the response to check @return true if the response was correct, false otherwise */ virtual bool check_answer(string response) const; /** Displays this question. */ virtual void display() const; private: string text; string answer; }; #endif

questiondemo.cpp

#include <iostream> #include <string> #include <sstream> using namespace std; #include "question.h" #include "choicequestion.h" int main() { string response; cout << boolalpha; // Make a quiz with two questions const int QUIZZES = 2; Question* quiz[QUIZZES]; quiz[0] = new Question; quiz[0]->add_line("Who was the inventor of C++?"); quiz[0]->set_answer("Bjarne Stroustrup"); ChoiceQuestion* cq_pointer = new ChoiceQuestion( "In which country was the inventor of C++ born?"); cq_pointer->add_choice("Australia", false); cq_pointer->add_choice("Denmark", true); cq_pointer->add_choice("Korea", false); cq_pointer->add_choice("United States", false); quiz[1] = cq_pointer; // Check answers for all questions for (int i = 0; i < QUIZZES; i++) { quiz[i]->display(); cout << "Your answer: "; getline(cin, response); cout << response << endl; cout << quiz[i]->check_answer(response) << endl; cout << endl; } return 0; }

choicequestion.cpp
1 #include <iostream>
2 #include <string>
3 #include <sstream>
4 using namespace std;
5
6 #include "question.h"
7 #include "choicequestion.h"
8
9 ChoiceQuestion::ChoiceQuestion(string question_text)
10
{
11
12 }
13
14 void ChoiceQuestion::add_choice(string choice, bool correct)
15 {
16
17 }
Transcribed Image Text:choicequestion.cpp 1 #include <iostream> 2 #include <string> 3 #include <sstream> 4 using namespace std; 5 6 #include "question.h" 7 #include "choicequestion.h" 8 9 ChoiceQuestion::ChoiceQuestion(string question_text) 10 { 11 12 } 13 14 void ChoiceQuestion::add_choice(string choice, bool correct) 15 { 16 17 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning