Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <sstream>
- #include <string>
- using namespace std;
- float secti(float a ,float b) {
- return a + b;
- }
- float odecti(float a ,float b) {
- return a - b;
- }
- float nasob(float a ,float b) {
- return a * b;
- }
- float del(float a ,float b) {
- return a / b;
- }
- // 1
- float (*prvni) (float, float);
- // 2
- float (*calc[])(float,float) = { secti, odecti, nasob, del };
- void handler(void) {
- float cislo;
- float prvni = 5.4f;
- float druhe = 8.0f;
- string in;
- int op = 0;
- string operace[] = { "scitani", "odecitani", "nasobeni", "deleni" };
- cout << "Zadej cisla, pro skonceni stiskni X" << endl;
- /*while (true) {
- if (cin >> cislo) {
- druhe = prvni;
- prvni = cislo;
- } else if (cin >> in) {
- if (in == "X" || in == "x") {
- break;
- }
- }
- }*/
- cout << "Pomoci klaves A a S vyber operaci, klavesa P provede operaci." << endl;
- while (true) {
- cout << operace[op] << endl;
- cin >> in;
- if (in == "P" || in == "p" ) {
- cout << (*calc[op])(prvni,druhe) << endl;
- return;
- }
- if (in == "S" || in == "s" ) {
- op = (++op % 4);
- }
- if (in == "A" || in == "a") {
- if (op == 0) {
- op = 3;
- } else {
- --op;
- }
- }
- }
- }
- int main(int argc, char** argv) {
- handler();
- // 3
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement