Dear visitor, welcome to Coder Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include <iostream> using namespace std; int main () { Schleife1: int zeichen; cout << " " << endl; cout << "Geben Sie die Rechenart ein ( (1) -> + (2) -> - (3) -> * (4) -> / ) "; cin >> zeichen; if ((zeichen >= 1) && (zeichen <=4)) { cout << " " << endl; int anzahl; cout << "Geben Sie die Anzahl der Operanden ein: " ; cin >> anzahl; int eins; cout << "Geben Sie den ersten Operanden ein: "; cin >> eins; cout << " " << endl; int zwei; cout << "Geben Sie den zweiten Operanden ein: "; cin >> zwei; cout << " " << endl; int ergebnis; if (zeichen==1) { ergebnis = eins+zwei; cout << eins << " + " << zwei << " = " << ergebnis << endl; } if (zeichen==2) { ergebnis = eins-zwei; cout << eins << " - " << zwei << " = " << ergebnis << endl; } if (zeichen==3) { ergebnis = eins*zwei; cout << eins << " * " << zwei << " = " << ergebnis << endl; } if (zeichen==4) { ergebnis = eins/zwei; cout << eins << " / " << zwei << " = " << ergebnis << endl; } } else goto Schleife1; system ("pause"); } |
Quoted
Aufgabe 2 (Punkte: 5)
Schreiben Sie ein C++ Programm, welches einen einfachen Taschenrechner simuliert. Gehen
Sie dabei folgendermaßen vor: Lesen Sie als erstens den arithmetischen Operator ein. Lesen
Sie dann die benötigten Operanden in Variablen vom Typ int ein. Prüfen Sie vor der Berechnung,
ob diese mit den eingelesenen Werten zulässig ist. Als Operationen sollen + (Addition),
- (Subtraktion), * (Multiplikation) und / (Division) möglich sein.
Geben Sie das Ergebnis der Berechnung in folgender Form aus:
Operand1 Operator Operand2 = Ergebnis
Quoted from ""void""
Dann ist doch alles ok.
Der Taschenrechner soll doch nur mit 2 Operanden arbeiten.
Hätte mich ehrlich gesagt auch gewundert,wenn nicht.
Sonst wäre nämlich nen Parsebaum angesagt,der eigentlich eher im Informatikstudium als in Programmieranfängeraufgaben Platz findet.
Gruß void
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#include <iostream> using namespace std; int main () { Schleife1: int zeichen; cout << " " << endl; cout << "Geben Sie die Rechenart ein ( (1) -> + (2) -> - (3) -> * (4) -> / )" << endl; cout << ", nur Zahlen groesser als 0 werden aktzeptiert. "; cin >> zeichen; if ((zeichen >= 1) && (zeichen <=4)) { cout << " " << endl; OP1: cout << "Operandeneingabe - nur Zahlen groesser als 0 werden aktzeptiert. " << endl; int eins; cout << "Geben Sie den ersten Operanden ein: "; cin >> eins; cout << " " << endl; if (eins>=1) { OP2: int zwei; cout << "Geben Sie den zweiten Operanden ein: "; cin >> zwei; cout << " " << endl; if (zwei>=1) { int ergebnis; if (zeichen==1) { ergebnis = eins+zwei; cout << eins << " + " << zwei << " = " << ergebnis << endl; } if (zeichen==2) { ergebnis = eins-zwei; cout << eins << " - " << zwei << " = " << ergebnis << endl; } if (zeichen==3) { ergebnis = eins*zwei; cout << eins << " * " << zwei << " = " << ergebnis << endl; } if (zeichen==4) { ergebnis = eins/zwei; cout << eins << " / " << zwei << " = " << ergebnis << endl; } } else goto Schleife1; } else goto OP1; } else goto OP1; system ("pause"); } |
Quoted from ""cewbie""
ähm ist Informatikstudium :oops:
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#include <iostream> using namespace std; int main () { Schleife1: int zeichen; cout << " " << endl; cout << "Geben Sie die Rechenart ein ( (1) -> + (2) -> - (3) -> * (4) -> / ) "; cin >> zeichen; if ((zeichen >= 1) && (zeichen <=4)) { cout << " " << endl; OP1: int eins; cout << "Geben Sie den ersten Operanden ein: "; cin >> eins; cout << " " << endl; if (eins>=1) { OP2: int zwei; cout << "Geben Sie den zweiten Operanden ein: "; cin >> zwei; cout << " " << endl; if (zwei>=1) { int ergebnis; if (zeichen==1) { ergebnis = eins+zwei; cout << eins << " + " << zwei << " = " << ergebnis << endl; } if (zeichen==2) { ergebnis = eins-zwei; cout << eins << " - " << zwei << " = " << ergebnis << endl; } if (zeichen==3) { ergebnis = eins*zwei; cout << eins << " * " << zwei << " = " << ergebnis << endl; } if (zeichen==4) { ergebnis = eins/zwei; cout << eins << " / " << zwei << " = " << ergebnis << endl; } } else goto OP2; } else goto OP1; } else goto Schleife1; system ("pause"); } |

Aber danke ich werds so ändern, dass die GO TOs passen.|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
//Taschenrechner C++.cpp #include <iostream> #include <math.h> using namespace std; int menu() { int i; cout << "Dies ist ein Taschenrechnerprogramm. Damit koennen sie weiterrechnen, wenn das verrunzte Gehirn nicht mehr moechte. "; cout << "Waehlen sie nun die Rechenart aus. Dabei benutzen Sie bitte eine Zahl zwischen 1 und 4. Und jetzt wuensche ich viel Spass, sie Mathegenie"; cout << "\n\t<---------Taschenrechner----------->" << "\n\t(1) Addieren" << "\n\t(2) Subtrahieren" << "\n\t(3) Multiplizieren" << "\n\t(4) Diviedieren" << "\n\t<----------------------------------->"; cin >> i; return i; } int main() { bool quit=false; int schluss; long double a, b; int aus=menu(); do { switch (aus) { case 1: case 2: case 3: case 4: cout << "\n\n\tBitte erste Zahl eingeben"; cin >> a; cout << "\n\n\tBitte zweite Zahl eingeben"; cin >> b; switch(aus) { case 1: cout << "\n\t" << a << " + " << b << " = " << a + b << endl; break; case 2: cout << "\n\t" << a << " - " << b << " = " << a - b << endl; break; case 3: cout << "\n\t" << a << " * " << b << " = " << a * b << endl; break; case 4: cout << "\n\t" << a << " / " << b << " = " << a / b << endl; break; } quit=true; break; default: cout << "\n\tFalsche eingabe"; break; } }while (!quit); cout << "\n\tBeliebige Taste und dann enter druecken zum beenden"; cin >> schluss; return 0; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// Taschenrechner simpel // ToDo: // Operanten -> int oder besser ? // Bei der Division Sicherheitsabfrage einfügen! // Wenn der Rechner mehr leisten soll, dann ergaenzt ihn #include <iostream> using namespace std; int main () { int zeichen; int O1, O2; bool bigloop; do { cout << "Bitte geben Sie den 1. Operanten ein: "; cin >> O1; bool loop = false; do { cout << "Geben Sie die Rechenart ein ( (1) -> + (2) -> - (3) -> * (4) -> / )" << endl; cout << ", nur Zahlen von 1 bis 4 werden aktzeptiert. "; cin >> zeichen; if ((zeichen >= 1) && (zeichen <=4)) { loop = true; } else { cout << endl << " Rechenart nicht implementiert" << endl; } }while(!loop); cout << "Bitte geben Sie den 2. Operanten ein: "; cin >> O2; cout << endl; switch(zeichen) { case 1: cout << O1 << " + " << O2 << " = " << O1 + O2 << endl; break; case 2: cout << O1 << " - " << O2 << " = " << O1 - O2 << endl; break; case 3: cout << O1 << " * " << O2 << " = " << O1 * O2 << endl; break; case 4: cout << O1 << " / " << O2 << " = " << O1 / O2 << endl; break; default: cout << "\n\tSomething go's wrong"; break; } bigloop = true; cout << endl << " Zeichen eingeben - 9 für neue Aufgabe" << endl; // statt der 9 etwa in J/N oder Y/N aendern cin >> zeichen; if (zeichen == 9) { bigloop = false; } }while(!bigloop); } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
#include <cstdlib> #include <iostream> using namespace std; double func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() {string exit; do{ int auswahl; cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Exit\n"; cin>>auswahl; system("cls"); switch (auswahl) { case 1: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 + *pzahl2<<endl; system("pause"); system("cls"); break; } case 2: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 * *pzahl2<<endl; system("pause"); system("cls"); break; } case 3: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 / *pzahl2<<endl; system("pause"); system("cls"); break; } case 4: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 - *pzahl2<<endl; system("pause"); system("cls"); break; } case 5: { double a,b; cout<<"Bitte geben Sie eine Zahl ein :"; cin>>a; cout<<"Geben Sie die Potenz an :"; cin>>b; cout<<"Das Ergebniss betraegt : "<<potenz(a,b)<<endl; system("pause"); system("cls"); break; } case 6: return 0; default: cout<<"Falsche Eingabe!\n"; } cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// double func (double *pzahl1,double *pzahl2) { cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
#include <cstdlib> #include <iostream> using namespace std; double prozent1 (double w,double p); double prozent2 (double g,double p); double prozent3 (double w,double g); double func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() {string exit; do{ int auswahl; cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Prozentrechnung\n"; cout<<"(7) Exit\n"; cin>>auswahl; system("cls"); switch (auswahl) { case 1: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 + *pzahl2<<endl; system("pause"); system("cls"); break; } case 2: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 * *pzahl2<<endl; system("pause"); system("cls"); break; } case 3: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 / *pzahl2<<endl; system("pause"); system("cls"); break; } case 4: { double zahl1,zahl2; double *pzahl1=&zahl1; double *pzahl2=&zahl2; func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<*pzahl1 - *pzahl2<<endl; system("pause"); system("cls"); break; } case 5: { double a,b; cout<<"Bitte geben Sie eine Zahl ein :"; cin>>a; cout<<"Geben Sie die Potenz an :"; cin>>b; cout<<"Das Ergebniss betraegt : "<<potenz(a,b)<<endl; system("pause"); system("cls"); break; } case 6: {int aus; cout<<"Was moechten Sie Berechnen?\nWaehlen Sie aus:\n"; cout<<"(1) Grundwert [G]\n"; cout<<"(2) Prozentwert [W]\n"; cout<<"(3) Prozentsatz [p]\n"; cin>>aus; system("cls"); switch (aus) { case 1: { double w,p; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"G= 100*p/W = "<<prozent1(w,p)<<"\n"; system("pause"); system("cls"); break; } case 2: { double p,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"W= G*p/100 = "<<prozent2(p,g)<<"\n"; system("pause"); system("cls"); break; } case 3: { double w,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"p= 100*W/G = "<<prozent3(w,g)<<" %\n"; system("pause"); system("cls"); break; } } break; } case 7: return 0; default: cout<<"Falsche Eingabe!\n"; } cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// double func (double *pzahl1,double *pzahl2) { cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } /////////////////////////////////// double prozent1 (double w,double p) { return 100*p/w; } //////////////////////////////////////// double prozent2 (double g,double p) { return g*p/100; } ///////////////////////////////////////// double prozent3 (double w,double g) { return 100*w/g; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
#include <cstdlib> #include <iostream> #include <string> using namespace std; double prozent1 (double w,double p); double prozent2 (double g,double p); double prozent3 (double w,double g); void func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() { string exit; double zahl1,zahl2; do{ int auswahl; cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Prozentrechnung\n"; cout<<"(7) Exit\n"; cin>>auswahl; system("cls"); switch (auswahl) { case 1: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 + zahl2)<<endl; break; case 2: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 * zahl2)<<endl; break; case 3: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 / zahl2)<<endl; break; case 4: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 - zahl2)<<endl; break; case 5: cout<<"Bitte geben Sie eine Zahl ein :"; cin>>zahl1; cout<<"Geben Sie die Potenz an :"; cin>>zahl2; cout<<"Das Ergebnis betraegt : "<<potenz(zahl1,zahl2)<<endl; break; case 6: int aus; cout<<"Was moechten Sie Berechnen?\nWaehlen Sie aus:\n"; cout<<"(1) Grundwert [G]\n"; cout<<"(2) Prozentwert [W]\n"; cout<<"(3) Prozentsatz [p]\n"; cin>>aus; system("cls"); switch (aus) { case 1: { double w,p; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"G= 100*p/W = "<<prozent1(w,p)<<"\n"; break; } case 2: { double p,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"W= G*p/100 = "<<prozent2(p,g)<<"\n"; break; } case 3: { double w,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"p= 100*W/G = "<<prozent3(w,g)<<" %\n"; break; } } break; case 7: return 0; } if (auswahl < 1 || auswahl > 7) cout<<"Falsche Eingabe!\n"; else { system("pause"); system("cls"); } cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); return 0; } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// void func (double *pzahl1,double *pzahl2) { cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } /////////////////////////////////// double prozent1 (double w,double p) { return 100*p/w; } //////////////////////////////////////// double prozent2 (double g,double p) { return g*p/100; } ///////////////////////////////////////// double prozent3 (double w,double g) { return 100*w/g; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
#include <cstdlib> #include <iostream> #include <string> using namespace std; double prozent1 (double w,double p); double prozent2 (double g,double p); double prozent3 (double w,double g); void func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() { string exit; double zahl1,zahl2; do{ int auswahl; cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Prozentrechnung\n"; cout<<"(7) Exit\n"; cin>>auswahl; system("cls"); switch (auswahl) { case 1: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 + zahl2)<<endl; break; case 2: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 * zahl2)<<endl; break; case 3: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 / zahl2)<<endl; break; case 4: func(&zahl1,&zahl2); cout<<"Das Ergebnis betraegt : "<<(zahl1 - zahl2)<<endl; break; case 5: cout<<"Bitte geben Sie eine Zahl ein :"; cin>>zahl1; cout<<"Geben Sie die Potenz an :"; cin>>zahl2; cout<<"Das Ergebnis betraegt : "<<potenz(zahl1,zahl2)<<endl; break; case 6: int aus; cout<<"---------------------------\n"; cout<<"Was moechten Sie Berechnen?\n" cout<<"---------------------------\n"<<"Waehlen Sie aus:\n"; cout<<"(1) Grundwert [G]\n"; cout<<"(2) Prozentwert [W]\n"; cout<<"(3) Prozentsatz [p]\n"; cin>>aus; system("cls"); switch (aus) { case 1: double w,p; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"G= 100*W/p = "<<prozent1(w,p)<<"\n"; break; case 2: { double p,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"W= G*p/100 = "<<prozent2(p,g)<<"\n"; break; } case 3: { double w,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"p= 100*W/G = "<<prozent3(w,g)<<" %\n"; break; } } break; case 7: return 0; default: cout<<"Falsche Eingabe!\n"; } cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); return 0; } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// void func (double *pzahl1,double *pzahl2) { cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } /////////////////////////////////// double prozent1 (double w,double p) { return 100*w/p; } //////////////////////////////////////// double prozent2 (double g,double p) { return g*p/100; } ///////////////////////////////////////// double prozent3 (double w,double g) { return 100*w/g; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
#include <cstdlib> #include <iostream> #include <string> #include <conio.h> using namespace std; double prozent1 (double w,double p); double prozent2 (double g,double p); double prozent3 (double w,double g); double func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() { string exit; double zahl1,zahl2; do { cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Prozentrechnung\n"; cout<<"(7) Exit\n"; switch (getch()) { case '1': { func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<zahl1 + zahl2<<endl; system("pause"); system("cls"); break; } case '2': { func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<zahl1 * zahl2<<endl; system("pause"); system("cls"); break; } case '3': { func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<zahl1 / zahl2<<endl; system("pause"); system("cls"); break; } case '4': { func(&zahl1,&zahl2); cout<<"Das Ergebniss betraegt : "<<zahl1 - zahl2<<endl; system("pause"); system("cls"); break; } case '5': { system("cls"); double a,b; cout<<"Bitte geben Sie eine Zahl ein :"; cin>>a; cout<<"Geben Sie die Potenz an :"; cin>>b; cout<<"Das Ergebniss betraegt : "<<potenz(a,b)<<endl; system("pause"); system("cls"); break; } case '6': { system("cls"); cout<<"Was moechten Sie Berechnen?\nWaehlen Sie aus:\n"; cout<<"(1) Grundwert [G]\n"; cout<<"(2) Prozentwert [W]\n"; cout<<"(3) Prozentsatz [p]\n"; switch (getch()) { case '1': { system("cls"); double w,p; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"G = 100*p/W = "<<prozent1(w,p)<<"\n"; system("pause"); system("cls"); break; } case '2': { system("cls"); double p,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"W= G*p/100 = "<<prozent2(p,g)<<"\n"; system("pause"); system("cls"); break; } case '3': { system("cls"); double w,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"p= 100*W/G = "<<prozent3(w,g)<<" %\n"; system("pause"); system("cls"); break; } } break; } case '7': return 0; default: cout<<"Falsche Eingabe!\n"; } cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// double func (double *pzahl1,double *pzahl2) {system("cls"); cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } /////////////////////////////////// double prozent1 (double w,double p) { return 100*p/w; } //////////////////////////////////////// double prozent2 (double g,double p) { return g*p/100; } ///////////////////////////////////////// double prozent3 (double w,double g) { return 100*w/g; } |
|
|
C Quellcode |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
#include <cstdlib> #include <iostream> #include <string> #include <conio.h> using namespace std; double prozent1 (double w,double p); double prozent2 (double g,double p); double prozent3 (double w,double g); double func (double *zahl1, double *pzahl2); double potenz(double a,double b); int main() { string exit; double zahl1,zahl2; do { cout<<"-------------------\n"; cout<<"Mein Taschenrechner\n"; cout<<"-------------------\n"; cout<<"\nWaehlen Sie aus : \n"; cout<<"(1) Addition\n"; cout<<"(2) Multiplikation\n"; cout<<"(3) Division\n"; cout<<"(4) Subtraktion\n"; cout<<"(5) Potenzrechnung\n"; cout<<"(6) Prozentrechnung\n"; cout<<"(7) Exit\n"; switch (getch()) { case '1': { func(&zahl1,&zahl2); cout<<zahl1<<" + "<<zahl2<<" = "<<zahl1 + zahl2<<endl; break; } case '2': { func(&zahl1,&zahl2); cout<<zahl1<<" * "<<zahl2<<" = "<<zahl1 * zahl2<<endl; break; } case '3': { func(&zahl1,&zahl2); if (zahl1>0 ,zahl2>0) { cout<<zahl1<<" / "<<zahl2<<" = "<<zahl1 / zahl2<<endl; } else { if(zahl1>0,zahl2==0) { cout<<"Teilen durch 0 unmoeglich!"; } else cout<<zahl1<<" / "<<zahl2<<" = 0"<<endl; } break; } case '4': { func(&zahl1,&zahl2); cout<<zahl1<<" - "<<zahl2<<" = "<<zahl1 - zahl2<<endl; break; } case '5': { system("cls"); double a,b; cout<<"Bitte geben Sie eine Zahl ein :"; cin>>a; cout<<"Geben Sie die Potenz an :"; cin>>b; cout<<"Das Ergebniss betraegt : "<<potenz(a,b)<<endl; break; } case '6': { system("cls"); cout<<"Was moechten Sie Berechnen?\nWaehlen Sie aus:\n"; cout<<"(1) Grundwert [G]\n"; cout<<"(2) Prozentwert [W]\n"; cout<<"(3) Prozentsatz [p]\n"; switch (getch()) { case '1': { system("cls"); double w,p; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"G = 100*p/W = "<<prozent1(w,p)<<"\n"; break; } case '2': { system("cls"); double p,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentsatz p ein: "; cin>>p; cout<<"W= G*p/100 = "<<prozent2(p,g)<<"\n"; break; } case '3': { system("cls"); double w,g; cout<<"bitte geben Sie den Grundwert G ein: "; cin>>g; cout<<"bitte geben Sie den Prozentwert W ein: "; cin>>w; cout<<"p= 100*W/G = "<<prozent3(w,g)<<" %\n"; break; } } break; } case '7': return 0; default: cout<<"Falsche Eingabe!\n"; } system("pause"); system("cls"); cout<<"Moechten Sie das Programm beenden j/n ? :"; cin>>exit; system("cls"); } while (exit=="n"); } ////////////////////////////// double potenz (double a,double b) { if (b==0) return 1; else return a * potenz(a,b-1); } ////////////////////////////////// double func (double *pzahl1,double *pzahl2) { system("cls"); cout<<"Bitte Geben Sie die erste Zahl ein :"; cin>>*pzahl1; cout<<"Bitte Geben Sie die zweite Zahl ein :"; cin>>*pzahl2; } //////////////////////////////////////// double prozent1 (double w,double p) { return 100*p/w; } //////////////////////////////////////// double prozent2 (double g,double p) { return g*p/100; } //////////////////////////////////////// double prozent3 (double w,double g) { return 100*w/g; } //////////////////////////////////////// |