Skip to content

Instantly share code, notes, and snippets.

@WIttyJudge
Last active October 25, 2018 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WIttyJudge/b30f61578075899d0de45433c059077f to your computer and use it in GitHub Desktop.
Save WIttyJudge/b30f61578075899d0de45433c059077f to your computer and use it in GitHub Desktop.
Feature of this programm: 1) Division by zero isn't possible. 2) You've the opportunity to resume working with calculator.
#include <iostream>
#include <Windows.h>
using namespace std;
class calculator
{
private:
float answer;
public:
void strokeUP() //stars appear at the beginning for beauty.
{
for (int i = 1; i < 51; i++)
{
cout << "*";
Sleep(4.5);
}
cout << endl;
}
void Body()
{
cout << "What function do u wanna use? " << endl;
cout << "1 - Addition " << endl;
cout << "2 - Subtraction " << endl;
cout << "3 - Multiplication " << endl;
cout << "4 - Division " << endl;
cout << "Input: ";
}
void enter_first_number_text()
{
cout << "Please enter first number: ";
}
void enter_second_number_text()
{
cout << "Please enter second number: ";
}
void animation() //animation of data reading.
{
for (int i = 1; i < 101; i++)
{
system("cls");
cout << "Loading: " << i << "%" << endl;
}
}
int Addition(float firstN, float secondN)
{
answer = firstN + secondN;
return answer;
}
int Subtraction(float firstN, float secondN)
{
answer = firstN - secondN;
return answer;
}
int Multiplication(float firstN, float secondN)
{
answer = firstN * secondN;
return answer;
}
int Division(float firstN, float secondN)
{
if (secondN == 0)
{
cout << "Division by zero isn't possible";
}
else
{
answer = firstN / secondN;
}
return answer;
}
};
int main()
{
int action;
float firstN, secondN;
char returnToAction='y';
calculator calc;
do // we can resume work with calculator.
{
calc.strokeUP();
calc.Body();
cin >> action;
cout << endl;
switch (action)
{
case 1:
{
calc.enter_first_number_text();
cin >> firstN;
calc.enter_second_number_text();
cin >> secondN;
calc.animation();
cout << "Result: " << firstN << " + " << secondN << " = ";
cout << calc.Addition(firstN, secondN);
cout << endl;
break;
}
case 2:
{
calc.enter_first_number_text();
cin >> firstN;
calc.enter_second_number_text();
cin >> secondN;
calc.animation();
cout <<"Recult: "<< firstN << " - " << secondN << " = ";
cout << calc.Subtraction(firstN, secondN);
cout << endl;
break;
}
case 3:
{
calc.enter_first_number_text();
cin >> firstN;
calc.enter_second_number_text();
cin >> secondN;
calc.animation();
cout << "Result: " << firstN << " * " << secondN << " = ";
cout << calc.Multiplication(firstN, secondN);
cout << endl;
break;
}
case 4:
{
calc.enter_first_number_text();
cin >> firstN;
calc.enter_second_number_text();
cin >> secondN;
calc.animation();
cout << "Result: " << firstN << " / " << secondN << " = ";
cout << calc.Division(firstN, secondN);
cout << endl;
break;
}
default:
cout << "Invalid Input..." << endl;
}
cout << "Would u like to continue working with calculator? (y/n): ";
cin >> returnToAction;
cout << endl;
} while (returnToAction == 'Y' || returnToAction == 'y'); // condition of resuming work with calculator.
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment