Answer to Question #268169 in C++ for oo7

Question #268169

Write a program that has 3 data members of int type the program take sum of 3 members and then return the square of each number by using public inheritance

1
Expert's answer
2021-11-18T06:54:35-0500
#include<iostream>
#include<stack>
using namespace std;

class ThreeInt
{

	int a;
	int b;
	int c;
public:
	ThreeInt():a(0),b(0),c(0){}
	ThreeInt(int _a, int _b, int _c)
	:a(_a),b(_b),c(_c){}
	void Square()
	{
		cout<<"\nThe square of the first value is\t"<<a*a;
		cout<<"\nThe square of the second value is\t"<<b*b;
		cout<<"\nThe square of the third value is\t"<<c*c;
	}
};

class Operation: public ThreeInt
{
	long int sum;
public:
	Operation(int _a, int _b, int _c)
	:ThreeInt(_a,_b,_c)
	{
		sum=_a+_b+_c;
	}
	int GetSum()
	{
		return sum;
	}		
};

int main()
{
	int a,b,c;
	cout<<"Please, enter the first value:\t";
	cin>>a;
	cout<<"Please, enter the second value:\t";
	cin>>b;
	cout<<"Please, enter the third value:\t";
	cin>>c;
	Operation o(a,b,c);
	cout<<"The sum of values is "<<o.GetSum();
	//Using public inheritance of function ThreeInt::Square()
	o.Square();
}

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