Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ ,PLEASE I NEED THIS FAST IN THIS CODE NEEDS TO FIXING #include using namespace std; class AdditionQ { private: string question; string answer;

IN C++ ,PLEASE I NEED THIS FAST

IN THIS CODE NEEDS TO FIXING

#include  using namespace std; class AdditionQ { private: string question; string answer; unsigned int weight; public: AdditionQ(int pts) : question(""), answer(""), weight(pts) { } virtual void generate() { int num1 = rand() % 10; int num2 = rand() % 10; answer = to_string(num1 + num2); question = to_string(num1) + "+" + to_string(num2) + "?"; } bool check(string answer) const { return this->answer == answer; } void ask() const { cout answer == answer; } void ask() const { cout  " + to_string(num2) + " "; question += "3. " + to_string(num1) + " = " + to_string(num2) + " "; question += "Enter 1, 2 or 3: "; if (num1  num2) answer = "2"; else answer = "3"; } bool check(string answer) const { return this->answer == answer; } void ask() const { cout > ans; if (q1.check(ans)) { cout > ans; if (q2.check(ans)) { cout > ans; if (q3.check(ans)) { cout > ans; if (q4.check(ans)) { cout > ans; if (q5.check(ans)) { cout > ans; if (q6.check(ans)) { cout  

image text in transcribed

Ex 1. Refactoring the Classes (66 points) Fix the code duplication in the three Question classes using inheritance. Your solution is expected to contain a single base class named Question that is abstract (with at least one pure virtual function). You will be graded based on the following: The choice of the data members in the base class. The choice and implementation of the constructors in the base class and derived classes. The choice and implementation of the non-pure functions in the base class. The choice of the pure virtual function(s) in the base class and its/their implementation in the derived classes. How clean your design is from an OOP perspective. Ex 2. Refactoring the Program (34 points) Fix the code duplication in main(). Your solution is expected to create an array of 6 Question objects and loop through the array to perform exactly the same thing the original code performs

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 6th Asian Conference Aciids 2014 Bangkok Thailand April 7 9 2014 Proceedings Part I 9 2014 Proceedings Part 1 Lnai 8397

Authors: Ngoc-Thanh Nguyen ,Boonwat Attachoo ,Bogdan Trawinski ,Kulwadee Somboonviwat

2014th Edition

3319054759, 978-3319054759

More Books

Students also viewed these Databases questions

Question

5. Give examples of variations in contextual rules.

Answered: 1 week ago