Mralko99

Calcolatrice

May 19th, 2014
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.52 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <math.h>
  4. #ifdef __cplusplus__
  5.   #include <cstdlib>
  6. #else
  7.   #include <stdlib.h>
  8. #endif#include <curses.h>
  9.  
  10. using namespace std;
  11.  
  12. int main(int argc, char *argv[])
  13. {   int a, ax, ay;
  14.     double x, y, z, bq, dq, x1, x2, d, b;
  15.    
  16.     cout<<"Questo programma e' una vera e propria calcolatrice spero possa esserti utile\n";
  17.    
  18.     cout<<"\n1-Addizione\n2-Sottrazione\n3-Moltiplicazione\n4-Divisione\n5-Divisione di numeri interi con resto\n6-Potenza\n7-Radice\n8-Equazioni di secondo grado\n";
  19.     cout<<"\nInserisci l' operatore: ";
  20.     cin>>a;
  21.    
  22.     if (a==1)
  23.     {
  24.             cout<<"\nInserisci il primo numero: ";
  25.             cin>>x;
  26.    
  27.             cout<<"\nInserisci secondo numero: ";
  28.             cin>>y;
  29.            
  30.             cout<<"\n\n"<<x<<" + "<<y<<" = "<<x+y<<"\n\n";
  31.              
  32.     }
  33.    
  34.     else if (a==2)
  35.     {
  36.             cout<<"\nInserisci il primo numero: ";
  37.             cin>>x;
  38.    
  39.             cout<<"\nInserisci secondo numero: ";
  40.             cin>>y;
  41.    
  42.             cout<<"\n\n"<<x<<" - "<<y<<" = "<<x - y<<"\n\n";
  43.     }
  44.    
  45.     else if (a==3)
  46.     {
  47.             cout<<"\nInserisci il primo numero: ";
  48.             cin>>x;
  49.    
  50.             cout<<"\nInserisci secondo numero: ";
  51.             cin>>y;
  52.    
  53.             cout<<"\n\n"<<x<<" x "<<y<<" = "<<x * y<<"\n\n";
  54.     }
  55.    
  56.     else if (a==4)
  57.     {
  58.             cout<<"\nInserisci il primo numero: ";
  59.             cin>>x;
  60.    
  61.             cout<<"\nInserisci secondo numero: ";
  62.             cin>>y;
  63.    
  64.             cout<<"\n\n"<<x<<" / "<<y<<" = "<<x / y<<"\n\n";
  65.     }
  66.    
  67.     else if (a==5)
  68.     {
  69.             cout<<"\nInserisci il primo numero: ";
  70.             cin>>ax;
  71.    
  72.             cout<<"\nInserisci secondo numero: ";
  73.             cin>>ay;
  74.    
  75.             cout<<"\n\n"<<ax<<" / "<<ay<<" = "<<ax / ay<<"resto"<<ax % ay;
  76.     }
  77.    
  78.     else if (a==6)
  79.     {
  80.  
  81.              cout<<"\nInserisci il numero: ";
  82.              cin>>x;
  83.              cout<<"\nInserisci l'esponete: ";
  84.              cin>>y;
  85.              z=pow(x,y);
  86.              cout<<"\n"<<x<<"^"<<y<<" = "<<z<<"\n\n";
  87.              
  88.     }
  89.    
  90.     else if (a==7)
  91.     {
  92.  
  93.              cout<<"\nInserisci il numero: ";
  94.              cin>>x;
  95.              cout<<"\nInserisci il radice: ";
  96.              cin>>y;
  97.              z=pow(x,1/y);
  98.              cout<<"\nRadice "<<y<<" di "<<x<<" = "<<z<<"\n\n";
  99.              
  100.     }
  101.    
  102.     else if (a==8)
  103.     {
  104.  
  105.              cout<<"\nInserisci il valore della x^2: ";
  106.              cin>>x;
  107.              cout<<"\nInserisci il valore della x: ";
  108.              cin>>y;
  109.              cout<<"\nInserisci il termine noto: ";
  110.              cin>>z;
  111.              bq=pow(y,2);
  112.              d=bq-4*x*z;
  113.              
  114.              if (d>=0)
  115.              {
  116.               dq=pow(d,0.5);
  117.               x2=((0-y)+dq)/(2*x);
  118.               x1=((0-y)-dq)/(2*x);
  119.              
  120.               if (x1==x2)
  121.               cout<<"\nLa soluzione e'"<<x1<<"\n\n";
  122.              
  123.               else
  124.               cout<<"\nLe soluzioni sono "<<x1<<" e "<<x2<<"\n\n";
  125.              
  126.               }
  127.              
  128.              else
  129.              {cout<<"\nLe soluzioni non esistono \n\n";}
  130.              
  131.              
  132.     }
  133.    
  134.     else
  135.     cout<<"\nErrore nella forma.\n\n";
  136.  
  137.     cout<<"\n1-Ritorna all' inizio\n2-Esci\n\n";
  138.  
  139.     cin>>b;
  140.  
  141. while (b==1)
  142. {
  143.      
  144.      
  145.         if (system("CLS")) system("clear");
  146.  
  147.  
  148.  
  149.      
  150.   cout<<"1-Addizione\n2-Sottrazione\n3-Moltiplicazione\n4-Divisione\n5-Divisione di numeri interi con resto\n6-Potenza\n7-Radice\n8-Equazioni di secondo grado\n";
  151.     cout<<"\nInserisci l' operatore: ";
  152.     cin>>a;
  153.    
  154.     if (a==1)
  155.     {
  156.             cout<<"\nInserisci il primo numero: ";
  157.             cin>>x;
  158.    
  159.             cout<<"\nInserisci secondo numero: ";
  160.             cin>>y;
  161.            
  162.             cout<<"\n\n"<<x<<" + "<<y<<" = "<<x+y<<"\n\n";
  163.              
  164.     }
  165.    
  166.     else if (a==2)
  167.     {
  168.             cout<<"\nInserisci il primo numero: ";
  169.             cin>>x;
  170.    
  171.             cout<<"\nInserisci secondo numero: ";
  172.             cin>>y;
  173.    
  174.             cout<<"\n\n"<<x<<" - "<<y<<" = "<<x - y<<"\n\n";
  175.     }
  176.    
  177.     else if (a==3)
  178.     {
  179.             cout<<"\nInserisci il primo numero: ";
  180.             cin>>x;
  181.    
  182.             cout<<"\nInserisci secondo numero: ";
  183.             cin>>y;
  184.    
  185.             cout<<"\n\n"<<x<<" x "<<y<<" = "<<x * y<<"\n\n";
  186.     }
  187.    
  188.     else if (a==4)
  189.     {
  190.             cout<<"\nInserisci il primo numero: ";
  191.             cin>>x;
  192.    
  193.             cout<<"\nInserisci secondo numero: ";
  194.             cin>>y;
  195.    
  196.             cout<<"\n\n"<<x<<" / "<<y<<" = "<<x / y<<"\n\n";
  197.     }
  198.    
  199.     else if (a==5)
  200.     {
  201.             cout<<"\nInserisci il primo numero: ";
  202.             cin>>ax;
  203.    
  204.             cout<<"\nInserisci secondo numero: ";
  205.             cin>>ay;
  206.    
  207.             cout<<"\n\n"<<ax<<" / "<<ay<<" = "<<ax / ay<<"resto"<<ax % ay;
  208.     }
  209.    
  210.     else if (a==6)
  211.     {
  212.  
  213.              cout<<"\nInserisci il numero: ";
  214.              cin>>x;
  215.              cout<<"\nInserisci l'esponete: ";
  216.              cin>>y;
  217.              z=pow(x,y);
  218.              cout<<"\n"<<x<<"^"<<y<<" = "<<z<<"\n\n";
  219.              
  220.     }
  221.    
  222.     else if (a==7)
  223.     {
  224.  
  225.              cout<<"\nInserisci il numero: ";
  226.              cin>>x;
  227.              cout<<"\nInserisci il radice: ";
  228.              cin>>y;
  229.              z=pow(x,1/y);
  230.              cout<<"\nRadice "<<y<<" di "<<x<<" = "<<z<<"\n\n";
  231.              
  232.     }
  233.    
  234.     else if (a==8)
  235.     {
  236.  
  237.              cout<<"\nInserisci il valore della x^2: ";
  238.              cin>>x;
  239.              cout<<"\nInserisci il valore della x: ";
  240.              cin>>y;
  241.              cout<<"\nInserisci il termine noto: ";
  242.              cin>>z;
  243.              bq=pow(y,2);
  244.              d=bq-4*x*z;
  245.              
  246.              if (d>=0)
  247.              {
  248.               dq=pow(d,0.5);
  249.               x2=((0-y)+dq)/(2*x);
  250.               x1=((0-y)-dq)/(2*x);
  251.              
  252.               if (x1==x2)
  253.               cout<<"\nLa soluzione e'"<<x1<<"\n\n";
  254.              
  255.               else
  256.               cout<<"\nLe soluzioni sono "<<x1<<" e "<<x2<<"\n\n";
  257.              
  258.               }
  259.              
  260.              else
  261.              {cout<<"\nLe soluzioni non esistono \n\n";}
  262.              
  263.              
  264.     }
  265.    
  266.     else
  267.     cout<<"\nErrore nella forma.\n\n";
  268.    
  269.     cout<<"\n1-Ritorna all' inizio\n2-Esci\n\n";
  270.  
  271.     cin>>b;
  272. }
  273.  
  274.    
  275.     return EXIT_SUCCESS;
  276. }
Advertisement
Add Comment
Please, Sign In to add comment