Write a Math Class will perform the basic functions (+, -, *, /). Write two classes the SimpleCalculator and ScientificCalculator that will inherit the Math class.
Write specific methods, attributes to the classes and show the results.
#include <iostream>
using namespace std;
class Math{
private:
int n1;
int n2;
public:
void setNum1(int a){
n1=a;
}
void setNum2(int b){
n1=b;
}
int getNum1(){
return n1;
}
int getNum2(){
return n2;
}
};
class SimpleCalculator: public Math{
public:
void add(){
cout<<"\nThe sum of "<<getNum1()<<" and "<<getNum2()<<" is = "<<getNum1()+getNum2();
}
void sub(){
cout<<"\nThe sub of "<<getNum1()<<" and "<<getNum2()<<" is = "<<getNum1()-getNum2();
}
};
class ScientificCalculator: public Math{
public:
void mul(){
cout<<"\nThe mul of "<<getNum1()<<" and "<<getNum2()<<" is = "<<getNum1()*getNum2();
}
void division(){
cout<<"\nThe division of "<<getNum1()<<" and "<<getNum2()<<" is = "<<getNum1()/getNum2();
}
};
int main()
{
Math m;
m.setNum1(10);
m.setNum2(20);
SimpleCalculator c1;
c1.add();
c1.sub();
ScientificCalculator c2;
c2.mul();
c2.division();
return 0;
}
Comments
Leave a comment