Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Calcolatrice C++ Modificata - Modificata.cpp

Modificata.cpp

Caricato da:
Scarica il programma completo

  1. #include <iostream>
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. using namespace std;
  6.  
  7. void potenza();
  8. void radice();
  9. void calcolatrice();
  10.  
  11.      void potenza()
  12.       {
  13.           float numero_pot, esponente, potenza=1;
  14.           int for_potenza;
  15.             cout << endl << " :: Numero: "; cin >> numero_pot;
  16.              cout << " :: Potenza: "; cin >> esponente;
  17.               for(for_potenza=0;for_potenza<esponente;for_potenza++)
  18.                potenza=potenza*numero_pot;
  19.               cout << endl << " :: Risultato: " << potenza << endl;
  20.              cout << endl << " :: Premi un tasto";
  21.             system("pause>nul");
  22.         }
  23.       void radice()
  24.        {
  25.          float radice, risultato_radice;
  26.           cout << endl << " :: Numero: "; cin >> radice;
  27.            risultato_radice=sqrt(radice);
  28.              cout << endl << " :: Risultato: " << risultato_radice << endl;
  29.             cout << endl << " :: Premi un tasto";
  30.            system("pause>nul");
  31.        }
  32.     void calcolatrice()
  33.     {
  34.        int primo_numero, secondo_numero, resto; char operazione; float risultato;
  35.        
  36.          cout << endl << " :: Num1    Operazione    Num2" << endl;
  37.            cout << " :: > "; cin >> primo_numero >> operazione >> secondo_numero;
  38.          switch(operazione) {
  39.             case '+':
  40.                  risultato=primo_numero+secondo_numero;
  41.                   cout << endl << " :: Risultato: " << risultato;
  42.                    cout << endl << " :: Premi un tasto";
  43.                   system("pause>nul");
  44.             break;
  45.             case '-':
  46.                  risultato=primo_numero-secondo_numero;
  47.                   cout << endl << " :: Risultato " << risultato;
  48.                    cout << endl << " :: Premi un tasto";
  49.                  system("pause>nul");
  50.             break;
  51.             case '*':
  52.                  risultato=primo_numero*secondo_numero;
  53.                   cout << endl << " :: Risultato " << risultato;
  54.                    cout << endl << " :: Premi un tasto";
  55.                  system("pause>nul");
  56.             break;
  57.             case '/':
  58.                 risultato=primo_numero/secondo_numero;
  59.                  cout << endl << " :: Risultato " << risultato;
  60.                   resto=primo_numero%secondo_numero;
  61.                    cout << " :: Resto: " << resto;
  62.                  cout << endl << " :: Premi un tasto";
  63.                 system("pause>nul");
  64.             break;
  65.         }
  66. }
  67. int main()
  68. {
  69.    int scelta_menu;
  70.  do {
  71.      system("cls");
  72.     cout << endl << "   .:::::::::::::::::::::::::.";
  73.     cout << endl << " .: Calcolatrice C++ by SkirK :.";
  74.     cout << "\n" << " :::::::::::::::::::::::::::::::";
  75.     cout << endl << " :: 1 Calcolatrice            ::";
  76.     cout << endl << " :: 2 Potenza                 ::";
  77.     cout << endl << " :: 3 Radice Quadrata         ::";
  78.     cout << endl << " :: 4 Esci                    ::";
  79.     cout << endl << "  :...........................:" << endl;
  80.     cout << endl << " :: > "; cin >> scelta_menu;
  81.         switch(scelta_menu) {
  82.                             case 1:
  83.                                  calcolatrice();
  84.                             break;
  85.                             case 2:
  86.                                  potenza();
  87.                             break;
  88.                             case 3:
  89.                                  radice();
  90.                             break;
  91.                             }
  92.         }while(scelta_menu!=4);
  93.     return 0;
  94. }