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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
#include <iostream>
using namespace std;
class calc
{
public:
void add()
{
double a,b,c;
cout<<"Put in the first number: ";
cin>>a;
cout<<"\n";
cout<<"Put in the second number: ";
cin>>b;
cout<<"\n";
c = a + b;
cout<<c;
}
void sub()
{
double a,b,c;
cout<<"Put in the first number: ";
cin>>a;
cout<<"\n";
cout<<"Put in the second number: ";
cin>>b;
cout<<"\n";
c = a - b;
cout<<c;
}
void mult()
{
double a,b,c;
cout<<"Put in the first number: ";
cin>>a;
cout<<"\n";
cout<<"Put in the second number: ";
cin>>b;
cout<<"\n";
c = a * b;
cout<<c;
}
void div()
{
double a,b,c;
cout<<"Put in the first number: ";
cin>>a;
cout<<"\n";
cout<<"Put in the second number: ";
cin>>b;
cout<<"\n";
c = a / b;
cout<<c;
}
void sq()
{
double a,b;
cout<<"Put in the number to be squared: ";
cin>>a;
cout<<"\n";
b = a*a;
cout<<b;
}
void over()
{
char a;
cout<<"My good sir I believe you have gone over the limit."<<endl;
cout<<"Would you like a do-over?"<<endl;
cout<<"y or n?"<<endl;
cin>>a;
if (a=='y') {main();cout<<"\n";}
else if (a=='n') {cout<<"Then my good sir, get out.";}
}
};
int main()
{
int choice;
char a;
calc calcob;
cout<<"Do you want to do addition, subtraction, etc.?"<<endl;
cout<<"1 - Addition"<<endl;
cout<<"2 - Subtraction"<<endl;
cout<<"3 - Multiplication"<<endl;
cout<<"4 - Division"<<endl;
cout<<"5 - Square a Number"<<endl;
cin>>choice;
cout<<"\n";
if (choice==1) calcob.add();
else if (choice==2) calcob.sub();
else if (choice==3) calcob.mult();
else if (choice==4) calcob.div();
else if (choice==5) calcob.sq();
else calcob.over();
cout<<endl;
cout<<endl;
cout<<endl;
cout<<"Do you want to calculate more, y or n?"<<endl;
cin>>a;
if (a=='y')
{
cout<<endl;
cout<<endl;
cout<<endl;
main();
}
cin.get();
cin.get();
return 0;
}
|