#ifndef CALC_H #define CALC_H class calc { double numb1; double numb2; public: calc(); void FUN_SUM(); void FUN_Subtraction(); void FUN_Multiplication(); void FUN_Division(); void FUN_Power(); void FUN_Squareroot(); void FUN_Switch(); void FUN_Loob(); }; #endif // CALC_H #include "calc.h" #include <iostream> #include <cmath> using namespace std; calc::calc() { numb1 = 0; numb2 = 0; } void calc::FUN_SUM() { cout << "Enter number 1 " << endl; cin >> numb1; cout << "Enter number 2 " << endl; cin >> numb2; double Result_Of_Sum; Result_Of_Sum = numb1+numb2; cout << "The result of Sum = " << Result_Of_Sum << endl; } void calc::FUN_Subtraction() { cout << "Enter number 1 " << endl; cin >> numb1; cout << "Enter number 2 " << endl; cin >> numb2; double Result_Of_Subtraction; Result_Of_Subtraction = numb1 - numb2; cout << "The result of Subtraction = " << Result_Of_Subtraction << endl; } void calc::FUN_Multiplication() { cout << "Enter number 1 " << endl; cin >> numb1; cout << "Enter number 2 " << endl; cin >> numb2; double Result_Of_Multiplication; Result_Of_Multiplication = numb1*numb2; cout << "The result of Multiplication = " << Result_Of_Multiplication << endl; } void calc::FUN_Division() { cout << "Enter number 1 " << endl; cin >> numb1; cout << "Enter number 2 " << endl; cin >> numb2; double Result_Of_Division ; Result_Of_Division = numb1/numb2; cout << "The result of Division = " << Result_Of_Division << endl; } void calc::FUN_Power() { cout << "Enter number 1 " << endl; cin >> numb1; cout << "Enter number 2 " << endl; cin >> numb2; double Result_Of_Power; Result_Of_Power = pow(numb1,numb2); cout << "The result of Power = " << Result_Of_Power << endl; } void calc::FUN_Squareroot() { cout << "Enter the tow number you want Square root \n"; cin >> numb1; double Result_Of_Square_root; Result_Of_Square_root = sqrt(numb1); cout << "The result of Square root = " << Result_Of_Square_root << endl; } void calc::FUN_Switch() { int S; cout << "Enter the number you operator do you want do it " << endl; cout << "1- Addition" << endl; cout << "2- Subtraction" << endl; cout << "3- Multiplication" << endl; cout << "4- Division" << endl; cout << "5- Power" << endl; cout << "6- Square Root" << endl; cout << "7- Exit" << endl; cin >> S; switch (S) { case 1: FUN_SUM(); break; case 2: FUN_Subtraction(); break; case 3: FUN_Multiplication(); break; case 4: FUN_Division(); break; case 5: FUN_Power(); break; case 6: FUN_Squareroot(); break; default : break; } } void calc::FUN_Loob() { char L; do { FUN_Switch(); cout << "Do you want do another operator ( 'y' or 'n'?) \n"; cin >> L; if (L== 'y' || L=='Y' || L=='n' || L=='N') continue; else cout << "you are enter roang later\n"; } while (L == 'Y' || L == 'y' ); } #include <iostream> #include "calc.h" using namespace std; int main() { cout << "Welcome to my simple Calculator\n"; calc simple_calc; simple_calc.FUN_Loob(); cout << "\n Tank you for use my App :) :) " << endl; return 0; }
我的问题是如何使用常规计算器等运算符启用用户计算任何值
例如 1+9*8-1+5 我希望我的程序这样做,但我不知道怎么做??:( :(