1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#ifndef Calculator_H
#define Calculator_H
class Calculator
{
private:
float a;
float b;
public:
Calculator();
float add(float, float);
float Subtract(float, float);
float divide(float, float);
float multiply(float, float);
};
Calculator::Calculator()
{
a = 0;
b = 0;
}
float Calculator::add(float a, float b)
{ return a + b;}
float Calculator::Subtract(float a, float b)
{ return a - b;}
float Calculator::divide(float a, float b)
{ return a / b;}
float Calculator::multiply(float a, float b)
{ return a * b;}
cout<<"You can choose from add, subtract, divide or multiply."<<endl;
cout<<"Do you have 2 numbers to perform a function on? (y/n)";
cin>>op;
cout<<"What function would you like to try? ";
cin>>op;
if(op == "add")
{
cout<<"Type in 2 numbers to add: ";
cin>>a>>b;
cout<<x<<" + "<<y<<" = "<<c.add(a,b)<<endl;
}
else
{
if(op == "subtract")
cout<<"Type in 2 numbers to subtract: ";
cin>>a>>b;
cout<<x<<" - "<<y<<" = "<<c.subtract(a,b)<<endl;
}
else
{
if(op == "divide")
cout<<"Type in 2 numbers to divide: ";
cin>>a>>b;
cout<<x<<" / "<<y<<" = "<<c.divide(a,b)<<endl;
}
else
{
if(op == "multiply")
cout<<"Type in 2 numbers to multiply: ";
cin>>a>>b;
cout<<x<<" * "<<y<<" = "<<c.divide(a,b)<<endl;
}
}
}
cout<<"Try again? ";
cin>>op;
}
}
|