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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education