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
#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();
}
Comments
Leave a comment