[C/C#/C++] TAschenRechner ^^

Dieses Thema im Forum "Projekte / Codes" wurde erstellt von w!ns0ck, 27. April 2006 .

Schlagworte:
  1. 27. April 2006
    TAschenRechner ^^

    Hoi,

    bin grad am Lernen von C++ und hab als Übung nen TaschenRechner gecodet..
    Der TaschenRechner is inner Klasse ausgelagert und wird auf dem Heap mittels eines Zeigers erzeugt (Zeiger kann ich net so gut, deswegen die Übung ^^)

    Datei is im Dateianhang, hier der Source-Code:

    main.cpp:
    Code:
    #include "taschenrechner.h"
    
    int main()
    {
     TaschenRechner *pRechner = new TaschenRechner;
     int Eingabe;
     float zahl1, zahl2;
    
     cout << "Willkommen zum TaschenRechner\n";
     cout << "-----------------------------\n";
     cout << " created by w!ns0ck\n\n\n";
    
     do
     {
    
     cout << "Bitte waehlen sie:\n";
     cout << "\t1. Addition\n";
     cout << "\t2. Subtraktion\n";
     cout << "\t3. Multiplikation\n";
     cout << "\t4. Division\n";
     cout << "\t5. Beenden\n";
     cout << "Ihre Wahl: ";
     cin >> Eingabe;
    
     switch (Eingabe)
     {
     case 1:
     {
     cout << "\n\nAddition\nGeben sie den ersten Summand ein: ";
     cin >> zahl1;
     cout << "Geben sie den zweiten Summand ein: ";
     cin >> zahl2;
    
     cout << "Das Ergebnis von " << zahl1 << " + " << zahl2 << " ist: " << pRechner->Addition(zahl1, zahl2) << "\n\n\n";
     break;
     }
     case 2:
     {
     cout << "\nSubtraktion\nGeben sie den Minuend ein: ";
     cin >> zahl1;
     cout << "Geben sie den Subtrahent ein: ";
     cin >> zahl2;
    
     cout << "Das Ergebnis von " << zahl1 << " - " << zahl2 << " ist: " << pRechner->Subtract(zahl1, zahl2) << "\n\n\n";
     break;
     }
     case 3:
     {
     cout << "\nMultiplikation\nGeben sie den 1. Faktor ein: ";
     cin >> zahl1;
     cout << "Geben sie den 2. Faktor ein: ";
     cin >> zahl2;
    
     cout << "Das Ergebnis von " << zahl1 << " * " << zahl2 << " ist: " << pRechner->Multipli(zahl1, zahl2) << "\n\n\n";
     break;
     }
     case 4:
     {
     cout << "\nDivision\nGeben sie den Dividend ein: ";
     cin >> zahl1;
     cout << "Geben sie den Divisor ein: ";
     cin >> zahl2;
    
     cout << "Das Ergebnis von " << zahl1 << " / " << zahl2 << " ist: " << pRechner->Division(zahl1, zahl2) << "\n\n\n";
     break;
     }
     default:
     {
     cout << "\nBitte geben sie eine Zahl von 1-5 an!\n";
     }
    
     }
    
     } while (Eingabe != 5);
    
     delete pRechner;
     return 0;
    }
    taschenrechner.h:
    Code:
    #include <iostream>
    
    using namespace std;
    
    class TaschenRechner
    {
    public:
     float Addition(float, float);
     float Subtract(float, float);
     float Multipli(float, float);
     float Division(float, float);
    };
    
    float TaschenRechner::Addition(float Sum1, float Sum2)
    {
     return Sum1 + Sum2;
    }
    
    float TaschenRechner::Subtract(float min, float sub)
    {
     return min - sub;
    }
    
    float TaschenRechner::Multipli(float fakt1, float fakt2)
    {
     return fakt1*fakt2;
    }
    
    float TaschenRechner::Division(float div, float div2)
    {
     return div / div2;
    }
    Kritik / lob erwünscht
     
  2. 27. April 2006
    RE: TAschenRechner ^^

    jo das programm ist gut...so ziemlich ähnlich wie meiner! du solltest allerdings noch die "NULLDIVISION" berücksichtigen...dann ist alles in bester ordung und es funktioniert einwandfrei!

    mfg juppwatis
     
  3. 18. Juni 2006
    isz in ordnung und ähnlich meinem.
    er kommt ohne funktionen (ok, int main ausgeschlossen) aus und ist relativ kompakter

    hier mein total toller quellcode:

    Code:
    #include <iostream>
    #include <math.h>
    using namespace std;
    
    int main() {
     
     cout<<"Herzlich Willkommen zum Taschenrechner \n";
     cout<<"";
     cout<<" Praesentiert von....Tux Computing";
     
     cout<<" Waehlen sie zwischen \n";
     cout<<" (1) Addition \n";
     cout<<" (2) Subtraktion \n";
     cout<<" (3) Multiplikation \n";
     cout<<" (4) Division \n";
     cout<<" (5) Wurzel ziehen \n";
     
     int wahl;
     cin>> wahl;
     
     switch(wahl)
     {
     {
     case 1: cout<<"Addition: Geben sie die erste Zahl ein \n";
     float fZahl1, fZahl2;
     cin>>fZahl1;
     cout<<"Addition: Geben sie die zweite Zahl ein \n";
     cin>>fZahl2;
     float fResult;
     fResult = fZahl1 + fZahl2;
     cout<<"Die Rechnung " << fZahl1 <<" + " << fZahl2 <<" ist " << fResult <<" ."; 
     break;
     }
     
     case 2: 
     {
     cout<<"Subtraktion: Geben sie die erste Zahl ein \n";
     float fZahl1, fZahl2;
     cin>>fZahl1;
     cout<<"Subtraktion: Geben sie die zweite Zahl ein \n";
     cin>>fZahl2;
     float fResult;
     fResult = fZahl1 - fZahl2;
     cout<<" Die Rechnung " << fZahl1 <<" - " << fZahl2 <<" ist " << fResult <<" ."; 
     break;
     
     }
     case 3:
     {
     cout<<"Multiplikation: Geben sie die erste Zahl ein \n";
     float fZahl1, fZahl2;
     cin>>fZahl1;
     cout<<"Multiplikation: Geben sie die zweite Zahl ein \n";
     cin>>fZahl2;
     float fResult;
     fResult = fZahl1 * fZahl2;
     cout<<" Die Rechnung " << fZahl1 <<" * " << fZahl2 <<" ist " << fResult <<" ."; 
     
     break;
     } 
     
     case 4:
     { 
     cout<<"Division: Geben sie die erste Zahl ein \n";
     float fZahl1, fZahl2;
     cin>>fZahl1;
     cout<<"Division: Geben sie die zweite Zahl ein \n";
     cin>>fZahl2;
     float fResult;
     fResult = fZahl1 / fZahl2;
     
     if(fZahl2==0)
     {
     cout<<"Durch 0 darf nicht geteilt werden ";
     }
     
     else
     {
     cout<<" Die Rechnung " << fZahl1 <<" + " << fZahl2 <<" ist " << fResult <<" ."; 
     } 
     
     break; 
     }
     
     case 5:
     {
     cout<<"Wurzel: Geben sie die Zahl ein \n";
     float fZahl1;
     cin>>fZahl1;
     
     float fResult;
     fResult = sqrt(fZahl1);
     cout<<" Die Rechnung " << fZahl1 <<" Wurzel ist " << fResult <<" ."; 
     
     break;
     }
     
     default:
     {
     cout<<" Die Rechenoperation wurde nicht zulaessig gewaelt, bitte neu starten!";
     
     system("pause");
     return 0;
     }
     }
     
     system("pause");
     return 0;
     }
     
    
     
  4. 18. Juni 2006
    Wenn hier jeder seinen taschenrechner postet dann poste ich meinen auch mal

     
  5. 18. Juni 2006
    ktm 123:

    dein taschenrechner ist ebenfalls sehr hübsch. ich würde jedoch anmerken:

    1.) Es fehlt eine abfrage, falls ein user bei der "wahl der rechenart" ausversehen "e" oder ähnliches eingibt
    2.) Ich würde Variablen immer erst dann initialisieren wenn ich sie brauche, und nicht bei Programmstart alle, die *vieleicht* gebraucht werden - bei kleinen prograammen jedoch nicht wichtig.
    3.) Ist Int für Divisionen gut? weil..es gibt auch restzahlen bzw. jemand könnte 23,45/12,3 rechnen wollen - kritisch. würde float empfehlen.

    mal gucken was wir als nächstes coden
     
  6. 18. Juni 2006
    Jo weixi da haste nen nice Programm gemacht, aber ist es nicht möglich in C++ mit einer Grafischen Oberfläche zu arbeiten ?

    MfG
    Jan225
     
  7. 18. Juni 2006
    doch, ist es.
    es ist jedoch...naja nennen wir es "nicht grade einfach" eine grafische oberfläche in c/c++ zu basteln und diese anzupassen. dazu muss man erfahren sein un dzeit haben - zudem sollte es sich lohnen
     
  8. 18. Juni 2006
    Wie heißt das Programm mit dem ihr den Taschenrechner programmiert. Find das nämliich interessant.
     
  9. 18. Juni 2006
    unsere taschenrechner entstanden mit c++;
    der compiler schimpft sich bei mir "borland c++ compiler".
     
  10. 18. Juni 2006
    1. C++ ist ne Sprache.
    2.
    3. Kostenlos: Bloodshed Software - Dev-C++
     
  11. 18. Juni 2006
    c++ kannst du dir gar nicht runterladen - das wäre als würdest du dir "englisch, deutsch" etc laden wollen - es ist eine sprache die gelernt werden muss. damit der computer sie versteht brauchen wir den compiler, der unser c++ in die maschienensprache übersetzt.

    google mal c++ compiler
     
  12. 22. Juni 2006
    Hab auch einen TRechner auf C++ programmiert. Obwohl ich auf c++ schon ungefahr 4-5 monate nicht mehr programmiert hatte (habe vieles vergessen ). Der Code sind nicht besonders aus aber für einen TRechner reicht denke ich mal aus. Ich habe das programm 1-2 Tage programmiert, besteht eigentlich aus drei Quelltexten.
    Wer sich nicht mit compilieren auseinandersetzen will kann das fertige Programm hier runterladen.



    Das ist "trechner.h"
    ------------------------------------------------------------------------------

    Code:
    #include <iostream.h>
    #include <math.h>
    
    class trechner {
     public:
     float division (float z1, float z2, bool b) ;
     float substraktion (float z1, float z2) {return (z1-z2);} ;
     float multiplikation (float z1, float z2) {return (z1*z2);} ;
     float addition (float z1, float z2) {return (z1+z2);} ;
     float hoch2 (float v) {float sd;sd=v*v;return sd;} ;
     float hoch3 (float v) {float sd;sd=v*v*v;return sd;} ;
     float wurz2 (float a, bool b) ; 
     float wurz3 (float a, bool b) ;
     };
    
    float trechner::division(float z1, float z2, bool b){
     if (b==false)return 0;
     cout<<"Das Ergebniss betraegt: "<<(z1/z2);
     return 0;
     }
    
    float trechner::wurz3(float a, bool b)
    {
     if (b==false)return 0; 
     float tzu=0.000,rt1=0.1,rt2=0.01,rt3=0.001,rt4=0.0001,zui=a; 
     for(;a>tzu*tzu*tzu;tzu+=100){}
     for(;a<tzu*tzu*tzu;tzu-=10){}
     for(;a>tzu*tzu*tzu;tzu++) {}
     if(a==tzu*tzu*tzu){return tzu;}
     for(;zui<tzu*tzu*tzu;tzu-=rt1){}
     for(;zui>tzu*tzu*tzu;tzu+=rt2){}
     for(;zui<tzu*tzu*tzu;tzu-=rt3){}
     for(;zui>tzu*tzu*tzu;tzu+=rt4){}
     cout<<"Das Ergebniss betraegt: "<<tzu;
     return 0;
    }
    
    
     float trechner::wurz2(float a, bool b)
    {
     if (b==false)return 0;
     cout<<"Das Ergebniss betraegt: "<<sqrt(a);
     return 0;
    }
    
    /*------------------------------------------------------------------------------
    Das ist "uberpruefF.h"
    ------------------------------------------------------------------------------*/
    
    
    class uberpruefF {
     public:
     bool nullpr(float a) ;
     bool negativpr(float a) ;
     } ;
     
     bool uberpruefF :: nullpr(float a){
     if (a==0){
     cout << "Diese Zahl darf nich den Wert NULL haben\n";
     system ("pause");
     return false;}
     return true;}
     
     bool uberpruefF::negativpr(float a){
     if(a<0){
     cout<<"Diese Zahl darf nich den NEGATIVEN Wert haben\n"; 
     system ("pause");
     return false;}
     return true;}
     
     
    /*------------------------------------------------------------------------------
    Die wichtigste Datei "rechnermain.cpp"
    ------------------------------------------------------------------------------*/
    
    /* Wenn man diese datei als eins kompiliert braucht man diese zeilen:
    #include "trechner.h"
    #include "uberpruefF.h"
    nicht */
    
    int main(){
     
     uberpruefF prufen;
     trechner ausrechnen;
     
     cout<<"Das Programm ist programmiert von Atombyte TE \n";
     cout<<"Programm ist reine C++ Anwendung\n\n\n-------------------------------------------------"; cout<<"\n\n\n\n"<<endl;
     cout<<"\t\t\t< < Menue > >\n\nWelche Rechenart wollen sie anwenden:\tAddition \t\t( 1 )"; cout<<"\n\t\t\t\t\tSubstraktion \t\t( 2 )\n\t\t\t\t\tMultiplikation \t\t( 3 )\n\t\t\t\t\tDivision \t\t( 4 )";
     cout<<" \n\t\t\t\t\tHoch 2 \t\t\t( 5 )\n\t\t\t\t\tHoch 3\t\t\t( 6 )\n\t\t\t\t\t2te Wurzel ziehen\t( 7 )"; cout<<"\n\t\t\t\t\t3te Wurzel ziehen \t( 8 )";
     
     lbl: 
     int wahl=0;
     char lblz;
     float a=0,b=0;
    
     cout<<"\n\nWaehlt aus: ";
     cin>>wahl;
     
     switch (wahl)
    {
     case 1: cout<<"\nGeben sie die erste Zahl ein: ";
     cin>>a;
     cout<<"Geben sie die zweite Zahl ein: ";
     cin>>b;
     cout<<"Das Ergebniss betraegt: "<<ausrechnen.addition(a,b);break;
    
     case 2: cout<<"\nGeben sie die erste Zahl ein: ";
     cin>>a;
     cout<<"Geben sie die zweite Zahl ein: ";
     cin>>b;
     cout<<"Das Ergebniss betraegt: "<<ausrechnen.substraktion(a,b);break;
    
     case 3: cout<<"\nGeben sie die erste Zahl ein: ";
     cin>>a;
     cout<<"Geben sie die zweite Zahl ein: ";
     cin>>b;
     cout<<"Das Ergebniss betraegt: "<<ausrechnen.multiplikation(a,b);break;
    
     case 4: cout<<"\nGeben sie die erste Zahl ein: ";
     cin>>a;
     cout<<"Geben sie die zweite Zahl ein: ";
     cin>>b;
     ausrechnen.division(a,b,prufen.nullpr(b));break;
     
     case 5: cout<<"\nGeben sie die Zahl ein: ";
     cin>>a;
     cout<<"Das Ergebniss betraegt: "<<ausrechnen.hoch2(a);break;
    
     case 6: cout<<"\nGeben sie die Zahl ein: ";
     cin>>a;
     cout<<"Das Ergebniss betraegt: "<<ausrechnen.hoch3(a);break;
     
     case 7: cout<<"\nGeben sie die Zahl ein: ";
     cin>>a;
     ausrechnen.wurz2(a,prufen.negativpr(a));break;
     
     case 8: cout<<"\nGeben sie die Zahl ein: ";
     cin>>a;
     ausrechnen.wurz3(a,prufen.negativpr(a));break; 
     
     default: cout<<"\nSo eine Option Existiert nicht versuchen sie nochmal";
     goto lbl; 
     
     } 
     
     cout<<"\n\nWollen sie noch was berechnen (J)a oder (N)ein: ";
     cin>>lblz;
     if (lblz == 'j')goto lbl;
     if (lblz == 'J')goto lbl;
     
     return 0;
    }
     
  13. 1. Juli 2006
    mein neuer taschenrechne rauf schlau:

    Code:
    #include <iostream>
    using namespace std;
    
    float add(float summand, float summandii);
    float sub(float minuend, float subtrahend);
    float multi(float faktori, float faktorii);
    float divide(float dividend, float divisor);
    
    
    int main(){
     choose:
     cout<<"Tuxinator sein Taschenrechner!\n";
     cout<<"Es gibt vier Dinge die sie machen koennen:\n";
     cout<<"(1)Addieren, (2)Substrahieren, (3) Multiplizieren, (4) Dividieren\n";
     
     int wahl;
     cin >> wahl;
     
     float a, b;
     
     switch(wahl){
     case 1: 
     cout<<"Addieren: Geben sie die erste Zahl ein!\n";
     
     cin >> a;
     cout<<"Geben sie die zweite Zahl ein\n";
     cin >> b;
     
     cout<<"Die Summe aus "<<a<<" und "<<b<<" ist " <<add(a, b)<<" .";
     break;
     
     case 2:
     
     cout<<"Substrahieren: Geben sie die erste Zahl ein!\n";
     
     cin >> a;
     cout<<"Geben sie die zweite Zahl ein\n";
     cin >> b;
     
     cout<<"Die Differenz aus "<<a<<" und "<<b<<" ist " <<sub(a, b)<<" .";
     break;
     
     case 3:
     
     cout<<"Multiplizieren: Geben sie die erste Zahl ein!\n";
     
     cin >> a;
     cout<<"Geben sie die zweite Zahl ein\n";
     cin >> b;
     
     cout<<"Das Produkt aus "<<a<<" und "<<b<<" ist " <<multi(a, b)<<" .";
     break;
     
     case 4:
     
     cout<<"Dividieren: Geben sie die erste Zahl ein!\n";
     
     cin >> a;
     cout<<"Geben sie die zweite Zahl ein\n";
     cin >> b;
     
     cout<<"Der Quotient aus "<<a<<" und "<<b<<" ist " <<divide(a, b)<<" .";
     break;
     
     default:
     
     cout<<"Eingabe Fehlerhaft, zurueck zur mathematischen Auswahl";
     goto choose;
     
     }
     
     cout<<"Wollen sie noch eine Rechnung machen?\n";
     cout<<"(1)Ja, (2)Nein\n";
     
     int repeat;
     cin >> repeat;
     
     if(repeat=1){
     cout<<"Gut, dann geht es zurueck zur Auswahl\n";
     goto choose;
     };
     
     cout<<"Nun gut, somit ist das Programm beendet!\n\n";
     cout<<"Press any key to continue";
     
     getchar();
     return 0;
     }
     
    float add(float a, float b){
     return a + b;
     }
     
    float sub(float a, float b){
     return a - b;
     }
    float multi(float a, float b){
     return a * b;
     }
    float divide(float a, float b){
     return a / b;
     } 
     
  14. 19. Februar 2007
    AW: TAschenRechner ^^

    hab auch ma einen gemacht, mein erstes prog in c++ *stolz sei und auf kritik wart*

    \\edit: mir fällt grad auf, dass ich net weiß, warum ich math.h eingebunden habe
     
  15. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.