Answer to Question #213577 in C++ for shalini

Question #213577

Create a class called InputData. It has two private data members data_a (int) and data_b (int). Write a function input() to get input for the attributes from the user and a function display() to display the values of the attributes. The values of these two data members can be returned by using two public functions get_a() and get_b().


*Derive a class called Arith_Unit from InputData. It contains the functions add(), sub(),mul(), div() to perform arithmetic operations on data_a and data_b.


1
Expert's answer
2021-07-04T17:11:42-0400
#include<iostream>
using namespace std;
class InputData{
	private:
		int data_a;
		int data_b;
	public:
		void input(){
			cout<<"Enter the first number"<<endl;
			cin>>data_a;
			cout<<"Enter the first number"<<endl;
			cin>>data_b;
		}
		int get_a(){
			return data_a;
		}
		int get_b(){
			return data_b;
		}
		void display(){
			cout<<"The value of first number is "<<get_a()<<endl;
			cout<<"The value of second number is "<<get_b()<<endl;
		}
};
class Arith_unit:public InputData{
	public:
	double	add(){
		return get_a() + get_b();
	}
	double	sub(){
		return get_a() - get_b();
	}
	double	mul(){
		return get_a() * get_b();
	}
	double	div(){
		return get_a() / get_b();
	}
};
int main(){
	Arith_unit t;
	t.input();
	cout<<"The sum is\t"<<t.add()<<endl;
	cout<<"The difference is\t"<<t.sub()<<endl;
		cout<<"The multiplication is\t"<<t.mul()<<endl;
			cout<<"The division is\t"<<t.div()<<endl;
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS