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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started