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
|
FinalProject
//#include <cstdlib>
#include <iostream>
using namespace std;
class Calculator {
public:
int add(int& ,int);
float add(float&, float);
int sub(int& ,int);
float sub(float&, float);
int mult(int& ,int);
float mult(float&, float);
int div(int& ,int);
float div(float&, float);
};
//void get_input(int& result,int input1);
void get_input(float& result, float input1);
//int result,input1;
float result, input1;
char sign;
int Calculator::add(int& result,int input1)
{
result=result+input1;
}
float Calculator::add(float& result, float input1)
{
result=result+input1;
}
int Calculator::sub(int& result,int input1)
{
result=result-input1;
}
float Calculator::sub(float& result, float input1)
{
result=result-input1;
}
int Calculator::mult(int& result,int input1)
{
result=result*input1;
}
float Calculator::mult(float& result, float input1)
{
result=result*input1;
}
int Calculator::div(int& result,int input1)
{
result=result/input1;
}
float Calculator::div(float& result, float input1)
{
result=result/input1;
}
int main()
{
//int result1, first_num;
float result1, first_num;
get_input(result1, first_num);
// Calculator c;
return (0);
}
//void get_input(int& result,int input1)
void get_input(float& result, float input1)
{
Calculator c;
cout << "Hello, this is a running total calculator. You can add \"+\", subtract \"-\", " << endl;
cout << "multiply \"*\", and divide \"/\". To work this calculator you enter a number " << endl;
cout << "then press [Enter]. You then you enter the operand, \"+,-,*,/\" and [Enter]." <<endl;
cout << "continue this process until you have enter your last number. To get the total, " << endl;
cout << "press \"=\". The functions will work like this: 8+2-4*6/3=12 NOT 8+2-4*6/3=2." <<endl;
cout << "To quit the program, enter \"Q\". Have fun." << endl;
//cout << ">";
cin >> result;
do{
//cout << ">";
cin >> sign;
if (sign== '='){
result;
cout << result << endl;
}else
//cout << ">";
cin >> input1;
if(sign=='+'){
result=c.add(result,input1);
result=result;
}else if(sign=='-'){
result=c.sub(result,input1);
result=result;
}else if(sign=='*'){
result=c.mult(result,input1);
result=result;
}else if(sign=='/'){
result=c.div(result,input1);
result=result;
}
}while((sign != 'q') || (sign != 'Q'));
system("pause");
}
|