Search the Community
Showing results for tags 'vectoriterator'.
-
Presupunand ca orice post poate ajuta candva pe cineva , poftim un programel in c++ , un calculator mai exact , bazat pe functia switch si pentru afisarea pe ecran a operatiilor am folosit vectori. #include<iostream> #include<cstdlib> #include<conio.h> #include<vector> /* Autor : BGD 1337 Progamming Language - C++ Scope : Can be useful for a begginer. */ using namespace std; int main(){ int a,b; char choise; vector<string> operatii; vector<string>::iterator iter; cout <<"\t\tCalculator pe sectiuni de operatii\n\n"; operatii.push_back("Inmultire"); operatii.push_back("Adunare"); operatii.push_back("Scadere"); operatii.push_back("Impartire"); restart: cout<<"Alege operatia dorita\n\n"; for (iter = operatii.begin(); iter != operatii.end(); iter++) cout << *iter << endl; int alege; cout<<"\nAlege: ";cin>>alege; switch(alege){ case 1: cout<<"Ai ales operatia de inmultire , acum poti calcula\n\n"; cout<<"a=";cin>>a; cout<<"b=";cin>>b; cout<<"Rezultatul este " <<a*b<<endl; cout <<"\nDoresti sa iesi din program ?[Y/N]\n"; choise=_getch(); if (choise == 'n') goto restart; break; case 2: cout<<"Ai ales operatia de adunare , acum poti calcula\n\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a+b<<endl; cout <<"\nDoresti sa iesi din program ?[Y/N]\n"; choise=_getch(); if (choise == 'n') goto restart; break; case 3: cout<<"Ai ales operatia de scadere , acum poti calcula\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a-b<<endl; cout <<"\nDoresti sa iesi din program ?[Y/N]\n\n"; choise=_getch(); if (choise == 'n') goto restart; break; case 4: cout<<"Ai ales operatia de impartire , acum poti calcula\n\n"; cout <<"a=";cin>>a; cout <<"b=";cin>>b; cout <<"Rezultatul este " <<a/b<<endl; cout <<"\nDoresti sa iesi din program ?[Y/N]\n\n"; choise=_getch(); if (choise == 'n') goto restart; break; default: cout<<"Nu exista aceasta operatie"; cout <<"\nDoresti sa iesi din program ?[Y/N]\n"; choise=_getch(); if (choise == 'n') goto restart; } cin.ignore(cin.rdbuf()->in_avail() +1); getchar(); return 0; }