Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions