Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stack>
- using namespace std;
- stack<double> wynik;
- enum dzialania{DODAWANIE=1,ODEJMOWANIE=2,MNOZENIE=3,DZIELENIE=4,CZYSZCZENIE=5};
- float dodaj(double x)
- {
- return wynik.top()+x;
- }
- float odejmij(double x)
- {
- return wynik.top()-x;
- }
- float pomnoz(double x)
- {
- return wynik.top()*x;
- }
- float podziel(double x)
- {
- return wynik.top()/x;
- }
- void wyczysc()
- {
- while(!wynik.empty())
- {
- wynik.pop();
- }
- wynik.push(0);
- }
- void wykonajDzialanie(int a, float b)
- {
- switch(a)
- {
- case DODAWANIE:
- wynik.push(dodaj(b));
- break;
- case ODEJMOWANIE:
- wynik.push(odejmij(b));
- break;
- case MNOZENIE:
- wynik.push(pomnoz(b));
- break;
- case DZIELENIE:
- wynik.push(podziel(b));
- break;
- case CZYSZCZENIE:
- wyczysc();
- break;
- }
- }
- void menu_startowe(double &x, int & y)
- {
- cout << "KALKULATOR" << endl;
- cout << "--------------------------------------------------------------" << endl;
- cout << "1.Dodawanie 2.Odejmowanie 3.Mnozenie 4.Dzielenie 5.Czyszczenie" << endl;
- cout << "--------------------------------------------------------------" << endl;
- cout << "WYNIK: "<<wynik.top()<<endl;
- cout << "Podaj liczbe: ";
- cin >> x;
- wynik.push(x);
- cout <<"Jakie dzialanie: ";
- cin >> y;
- cout <<"Podaj liczbe: ";
- cin >> x;
- }
- void menu(double &x, int &y) //uzyskanie dostêpu do oryginalnych wartoœci a nie ich kopii
- {
- cout<<endl;
- cout << "KALKULATOR" << endl;
- cout << "--------------------------------------------------------------" << endl;
- cout << "1.Dodawanie 2.Odejmowanie 3.Mnozenie 4.Dzielenie 5.Czyszczenie" << endl;
- cout << "--------------------------------------------------------------" << endl;
- cout <<"WYNIK: "<<wynik.top()<<endl;
- cout <<"Jakie dzialanie: ";
- cin >> y;
- if(y!=5)
- {
- cout <<"Podaj liczbe: ";
- cin >> x;
- }
- }
- //główna funkcja programu//
- int main()
- {
- double a;
- int wybor;
- wynik.push(0);
- for(;;)
- {
- if(wynik.top()==0)
- {
- menu_startowe(a,wybor);
- wykonajDzialanie(wybor,a);
- } else
- {
- menu(a,wybor);
- wykonajDzialanie(wybor,a);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement