Question: Using C++ Language. Microsoft Visual Studio 2019 Adding on to your last assignment code (see below), design an Addition class and a Multiplication class that

Using C++ Language. Microsoft Visual Studio 2019

Adding on to your last assignment code (see below), design an Addition class and a Multiplication class that is children to your Math class (Main Class). Make sure that your program uses inheritance. Think, what variables/methods can I use from the parent class instead of recreating it in the child class? Your addition and multiplication code should work with n numbers. Create objects in your main to show inheritance.

In a block of code in your program, in the text entry describe how your program is using inheritance.

Last Assignment C++ Code for reference:

#include

using namespace std;

class Math

{

public:

int sum;

Math() {

}

int addition(int n, int arr[]) {

sum = 0;

for (int i = 0; i < n; i++) {

sum += arr[i];

}

for (int i = 0; i < n; i++) {

cout << arr[i];

if (i != n - 1)

cout << " + ";

}

return sum;

}

void print(int result) {

cout << " = " << result;

}

};

int main() {

Math a;

int n, value;

cout << "Enter the total number of elements to add: ";

cin >> n;

int arr[n];

for (int i = 0; i < n; i++) {

cout << "Enter value: ";

cin >> arr[i];

}

value = a.addition(n, arr);

a.print(value);

cout << endl;

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!