A simple calculator (c ++)

#include <iostream>
#include <cmath>
using namespace std;

class calc
{
private:
int a,b;
int p,m;
public:
calc(){}

void input();
void input1();
void input2();
void input3();
void input4();
void input5();
double input6();

int jia();
int jian();
int mul();
int div();
//long pow(); //平方

void display1(); //加
void display2(); //减
void display_mul();
void display_div();
int display_pow(int);
};

// The following is the definition of the member function
int :: Calc Jia ()
{
// int SUM;
// SUM = A + B;
// return SUM;
return A + B;
}

int calc::jian()
{
return a-b;
}

int calc::mul()
{
return a*b;
}

Calc :: div int ()
{
IF (b == 0)
{
cout << "Please re-enter the division by zero ...!" << endl;
cout << "Enter two integers:";
cin >> B >> A;
return. 1;
}
the else
return A / B;
}

//long calc::pow()
//{
// return p*p;
//}

:: Calc INPUT void ()
{
COUT << "enter two integers:";
CIN >> A >> B;
}

void calc::input1()
{
input();
jia();
}

void calc::input2()
{
input();
jian();
}

void calc::input3()
{
input();
mul();
}

:: Calc INPUT4 void ()
{
INPUT ();
div ();
}
/ *
void :: Calc Input5 ()
{
INPUT ();
POW ();
}
* /
Double :: Calc Input6 ()
{
COUT << " Please enter an integer, the square root of the number: ";
CIN >> m;
Double Q = sqrt (m);
return Q;
}

:: Calc Display1 void ()
{
COUT << "two numbers =" << Jia () << endl;
}

:: Calc Display2 void ()
{
COUT << "difference between two numbers =" << Jian () << endl;
}

:: Calc display_mul void ()
{
COUT << "the product of two numbers =" << MUL () << endl;
}

:: Calc display_div void ()
{
COUT << "List of two numbers =" << div () << endl;
}

int calc::display_pow(int q)
{
return q*q;
}

//菜单
void menu()
{
cout<<"*********************************"<<endl;
cout<<endl;
cout<<" ===简单计算器==="<<endl;
cout<<endl;
cout<<" ---1.加---"<<endl;
cout<<endl;
cout<<" ---2.减---"<<endl;
cout<<endl;
cout<<" ---3.乘---"<<endl;
cout<<endl;
cout<<" ---4.除---"<<endl;
cout<<endl;
cout<<" ---5.平方---"<<endl;
cout<<endl;
cout<<" ---6.平方根---"<<endl;
cout<<endl;
cout<<" ---0.退出---"<<endl;
cout<<endl;
cout<<"*********************************"<<endl;
}

// exit the menu
void _exit ()
{
cout << "*********************************" << endl ;
cout << endl;
cout << "Welcome to this system" << endl;
cout << endl;
cout << endl;
cout << "goodbye --- ---" << endl;
cout << endl;
<< COUT "*********************************" << endl;
}

//////////// main function /////////////
int main ()
{
Calc the Add;
Calc Sub;
Calc MUL;
Calc div;
Calc POW;
Calc sqrt;

c int;
the MENU (); // call the main menu

the while (. 1)
{
COUT << "Select:";
CIN >> C;
Switch (C)
{
Case. 1:
add.input1 ();
add.display1 ();
BREAK;
Case 2:
sub.input2 ();
sub.display2 ();
BREAK;
Case. 3:
mul.input3 ();
mul.display_mul ();
BREAK;
Case. 4:
div.input4 ();
div.display_div ();
BREAK;
Case. 5:
//pow.input5 ();
int P;
COUT << "Please enter a positive integer:";
CIN >> P;
COUT << "is the square of the number:" << pow.display_pow (P) << endl;
BREAK;
Case. 6 :
COUT << "is the square root of the number:" << sqrt.input6 () << endl ;
break;
case 0:
system("cls");
_exit ();
Exit (. 1);
BREAK;
default:
"! input error" << endl << COUT;
BREAK;
}
}
return. 1;
}

 

Guess you like

Origin www.cnblogs.com/duanqibo/p/11111044.html