) |
|
C/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 179 180 181 182 183 184 185 186 187 188 189 190 191 |
#include <iostream> #include <conio.h> #include <stdlib.h> #include <cmath> #include <iomanip> using namespace std; long double calculate(int ausw, long double x, long double y); //deklaration der funktion 'calculate' long double prozent(int ausw, long double x, long double y); //deklaration der funktion 'prozent' float winkel(int ausw, float x); //deklaration der funktion 'winkel' int main() { int auswahl; //deklaration der Variablen für die Funktion 'main' long double a = 0.0; long double b = 0.0; long double ergebnis = 0.0; char antwort; do //Schleife fürs Auswahl-Menü die nur solange gilt { //wie die Antwort gleich 'j' ist cout << "Calculator v0.9_RC_1\n" << endl; cout << "|==============|\n\n"; cout << "[1]Addition\n"<< "[2]Subtraktion\n"<< //Auswahl-Menü "[3]Multiplikation\n"<< "[4]Division\n"<< "[5]Quadrieren\n"<< "[6]Wurzel ziehen\n"<< "[7]Prozentrechnung\n"<< "[8]Sinus\n"<< "[9]Cosinus\n"<< "[10]Tangens\n"<< "[0]Beenden\n\n"; cout << "Waehlen sie eine Option aus: "; cin >> auswahl; //Einlesen der Menü-Auswahl if( auswahl == 0 ) //Programm beenden wenn 0 gewählt wird return 0; while (!(cin >> auswahl)) { cout << "Falsche Eingabe du Heinz!"; cin.clear(); cin.ignore(10000, '\n'); cout << "\n\nNeuer Versuch: "; cin >> auswahl; } system("cls"); //Bildschirminhalt löschen cout << "Kommazahlen muessen mit einem Punkt statt eines Kommas eingegeben werden!\n\n"; if ( auswahl >= 1 && auswahl <= 4 ) { cout << "\n1.Zahl: "; //Erste Zahl einlesen cin >> a; cout << "\n2.Zahl: "; cin >> b; //Zweite Zahl einlesen } else if( auswahl >= 5 && auswahl <= 6 ) { cout << "\nBasis: "; //Basis einlesen cin >> a; cout << "\nExponent: "; //Exponent einlesen cin >> b; } else if( auswahl == 7 ) //Werte für Prozentrechnung einlesen { cout << "Geben sie den Grundwert G an: "; cin >> a; cout << "\n\nGeben sie den Prozentsatz an: "; cin >> b; } else if ( auswahl >=8 && auswahl <=10 ) { cout << "Geben sie den Winkel ohne Grad an: "; cin >> a; } ergebnis = calculate(auswahl, a, b); ergebnis = prozent(auswahl, a, b); ergebnis = winkel(auswahl, a); cout << "\nDas Ergebnis lautet: " << setprecision(3) << fixed << ergebnis; cout << "\n\nWollen sie eine weitere Berechnung durchfuehren?\n"; cout << "<J/N>"; //Abfrage ob weitergerechnet werden soll oder nicht cin >> antwort; while( antwort != 'j' && antwort != 'n' ) { cout << "Falsche Eingabe, wiederholen: "; //Fehlerabfang falls Zahl anstatt Buchstabe eingegeben wird cin >> antwort; } system("cls"); //Bildschirminhalt löschen }while (antwort == 'j' ); //Bedingung der Do-While-Schleife return 0; } long double calculate (int ausw,long double x,long double y) //Funktion zum berechnen der einzelnen Werte { long double res = 0.0; //Definition des Ergebnis-Wertes switch(ausw) //Switch-Anweisung für Menü-Auswahl { case 1 : //Berechnung zur Addition { res = x + y; break; } case 2 : //Berechnung zur Subatraktion { res = x - y; break; } case 3 : //Berechnung zur Multiplikation { res = x * y; break; } case 4 : //Berechnung zur Division { res = x / y; if (y == 0) //Fehlerabfang falls durch 0 dividiert wird { cout << "\nDivision durch 0 nicht moeglich!"; } break; } case 5 : { res = pow (x, y); //Berechnung zu Potenzierung break; } case 6 : { res = pow(x, 1.0 / y); //Berechnung zur Wurzelziehung break; } } return res; } long double prozent(int ausw, long double x, long double y) //Funktion zur Prozentrechnung { long double res = 0.0; switch(ausw) { case 7 : { res = x * y / 100; break; } } return res; } float winkel(int ausw, float x) { float res = 0.0; switch(ausw) { case 8 : { res = sin(x * M_PI / 180); cout << "Der Sinus von " << x << " lautet: " << setprecision(3) << fixed << res; break; } case 9 : { res = cos(x * M_PI / 180); cout << "Der Cosinus von " << x << " lautet: " << setprecision(3) << fixed << res; break; } case 10 : { res = tan(x * M_PI / 180); cout << "Der Tangens von " << x << " lautet: " << setprecision(3) << fixed << res; break; } } } |

|
|
C/C++ Quellcode |
1 2 3 |
ergebnis = calculate(auswahl, a, b); ergebnis = prozent(auswahl, a, b); ergebnis = winkel(auswahl, a); |
|
|
C/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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
#include <iostream> #include <cstdlib> #include <cmath> #include <iomanip> using namespace std; long double calculate(int ausw, long double x, long double y); //deklaration der funktion 'calculate' long double prozent(int ausw, long double x, long double y); //deklaration der funktion 'prozent' float winkel(int ausw, float x); //deklaration der funktion 'winkel' int main() { int auswahl; //deklaration der Variablen für die Funktion 'main' long double a = 0.0; long double b = 0.0; long double ergebnis = 0.0; char antwort; do //Schleife fürs Auswahl-Menü die nur solange gilt { //wie die Antwort gleich 'j' ist cout << "Calculator v0.9_RC_1\n" << endl; cout << "|==============|\n\n"; cout << "[1]Addition\n"<< "[2]Subtraktion\n"<< //Auswahl-Menü "[3]Multiplikation\n"<< "[4]Division\n"<< "[5]Quadrieren\n"<< "[6]Wurzel ziehen\n"<< "[7]Prozentrechnung\n"<< "[8]Sinus\n"<< "[9]Cosinus\n"<< "[10]Tangens\n"<< "[0]Beenden\n\n"; cout << "Waehlen sie eine Option aus: "; while (!(cin >> auswahl)) { cout << "Falsche Eingabe du Heinz!"; cin.clear(); cin.ignore(10000, '\n'); cout << "\n\nNeuer Versuch: "; cin >> auswahl; } if ( auswahl == 0 ) //Programm beenden wenn 0 gewählt wird return 0; cout << "Kommazahlen muessen mit einem Punkt statt eines Kommas eingegeben werden!\n\n"; if ( auswahl >= 1 && auswahl <= 4 ) { cout << "\n1.Zahl: "; //Erste Zahl einlesen cin >> a; cout << "\n2.Zahl: "; cin >> b; //Zweite Zahl einlesen ergebnis = calculate(auswahl, a, b); } else if ( auswahl >= 5 && auswahl <= 6 ) { cout << "\nBasis: "; //Basis einlesen cin >> a; cout << "\nExponent: "; //Exponent einlesen cin >> b; ergebnis = calculate(auswahl, a, b); } else if ( auswahl == 7 ) //Werte für Prozentrechnung einlesen { cout << "Geben sie den Grundwert G an: "; cin >> a; cout << "\n\nGeben sie den Prozentsatz an: "; cin >> b; ergebnis = prozent(auswahl, a, b); } else if ( auswahl >=8 && auswahl <=10 ) { cout << "Geben sie den Winkel ohne Grad an: "; cin >> a; ergebnis = winkel(auswahl, a); } cout << "\nDas Ergebnis lautet: " << setprecision(3) << fixed << ergebnis; cout << "\n\nWollen sie eine weitere Berechnung durchfuehren?\n"; cout << "<J/N>"; //Abfrage ob weitergerechnet werden soll oder nicht cin >> antwort; while ( std::tolower(antwort) != 'j' && std::tolower(antwort) != 'n' ) { cout << "Falsche Eingabe, wiederholen: "; //Fehlerabfang falls Zahl anstatt Buchstabe eingegeben wird cin >> antwort; } }while (std::tolower(antwort) == 'j' ); //Bedingung der Do-While-Schleife return 0; } long double calculate (int ausw,long double x,long double y) //Funktion zum berechnen der einzelnen Werte { long double res = 0.0; //Definition des Ergebnis-Wertes switch (ausw) //Switch-Anweisung für Menü-Auswahl { case 1 : //Berechnung zur Addition { res = x + y; break; } case 2 : //Berechnung zur Subatraktion { res = x - y; break; } case 3 : //Berechnung zur Multiplikation { res = x * y; break; } case 4 : //Berechnung zur Division { res = x / y; if (y == 0) //Fehlerabfang falls durch 0 dividiert wird { cout << "\nDivision durch 0 nicht moeglich!"; } break; } case 5 : { res = pow (x, y); //Berechnung zu Potenzierung break; } case 6 : { res = pow(x, 1.0 / y); //Berechnung zur Wurzelziehung break; } } return res; } long double prozent(int ausw, long double x, long double y) //Funktion zur Prozentrechnung { long double res = 0.0; switch (ausw) { case 7 : { res = x * y / 100; break; } } return res; } float winkel(int ausw, float x) { float res = 0.0; switch (ausw) { case 8 : { res = sin(x * M_PI / 180); cout << "Der Sinus von " << x << " lautet: " << setprecision(3) << fixed << res; break; } case 9 : { res = cos(x * M_PI / 180); cout << "Der Cosinus von " << x << " lautet: " << setprecision(3) << fixed << res; break; } case 10 : { res = tan(x * M_PI / 180); cout << "Der Tangens von " << x << " lautet: " << setprecision(3) << fixed << res; break; } } return res; } |
This post has been edited 2 times, last edit by "darthdespotism" (Apr 25th 2008, 11:06pm)
.Soweit schonmal danke.|
|
C/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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
#include <iostream> #include <cstdlib> #include <cmath> #include <iomanip> using namespace std; long double calculate(int ausw, long double x, long double y);//deklaration der funktion 'calculate' long double prozent(int ausw, long double x, long double y);//deklaration der funktion 'prozent' float winkel(int ausw, float x);//deklaration der funktion 'winkel' float arcus (int ausw, float x); int main() { int auswahl; //deklaration der Variablen für die Funktion 'main' long double a = 0.0; long double b = 0.0; long double ergebnis = 0.0; char antwort; do //Schleife fürs Auswahl-Menü die nur solange gilt { //wie die Antwort gleich 'j' ist cout << "Calculator v0.9_RC_1\n" << endl; cout << "|==============|\n\n"; cout << "[-]Grundrechenarten\n"<< "[1]Addition\n"<< //Auswahl-Menü "[2]Subtraktion\n"<< "[3]Multiplikation\n"<< "[4]Division\n"<< "[5]Quadrieren\n"<< "[6]Wurzel ziehen\n"<< "[-]Prozentrechnung\n"<< "[7]Grundwert berechnen\n"<< "[8]Prozentwert berechnen\n"<< "[9]Prozentsatz berechnen\n"<< "[-]Winkelfunktionen\n"<< "[10]Sinus\n"<< "[11]Cosinus\n"<< "[12]Tangens\n"<< "[13]Arcus-Sinus\n"<< "[14]Arcus-Cosinus\n"<< "[15]Arcus-Tangens\n"<< "[0]Beenden\n\n"<< cout << "Waehlen sie eine Option aus: "; while (!(cin >> auswahl)) { cout << "Falsche Eingabe du Heinz!"; cin.clear(); cin.ignore(10000, '\n'); cout << "\n\nNeuer Versuch: "; cin >> auswahl; } if ( auswahl == 0 ) //Programm beenden wenn 0 gewählt wird return 0; system ("cls"); cout << "Kommazahlen muessen mit einem Punkt statt eines Kommas eingegeben werden!\n\n"; if ( auswahl >= 1 && auswahl <= 4 ) { cout << "\n1.Zahl: "; //Erste Zahl einlesen cin >> a; cout << "\n2.Zahl: "; cin >> b; //Zweite Zahl einlesen ergebnis = calculate(auswahl, a, b); } else if ( auswahl >= 5 && auswahl <= 6 ) { cout << "\nBasis: "; //Basis einlesen cin >> a; cout << "\nExponent: "; //Exponent einlesen cin >> b; ergebnis = calculate(auswahl, a, b); } /*else if ( auswahl == 7 ) //Werte für Prozentrechnung einlesen { cout << "Geben sie den Grundwert G an: "; cin >> a; cout << "\n\nGeben sie den Prozentsatz an: "; cin >> b; ergebnis = prozent(auswahl, a, b); }*/ else if ( auswahl >=10 && auswahl <=12 ) { float c = 0.0; cout << "Geben sie den Winkel ohne Grad an: "; cin >> c; ergebnis = winkel(auswahl, c); } else if ( auswahl >= 13 && auswahl <=15 ) { if ( auswahl == 13 ) { cout << "Geben sie Ihren Sinus an: "; cin >> a; ergebnis = arcus(auswahl, a); } else if ( auswahl == 14 ) { cout << "Geben sie Ihren Cosinus an: "; cin >> a; ergebnis = arcus(auswahl, a); } else if ( auswahl == 15 ) { cout << "Geben sie Ihren Tangens an: "; cin >> a; ergebnis = arcus(auswahl, a); } } cout << "\nDas Ergebnis lautet: " << setprecision(3) << fixed << ergebnis; cout << "\n\nWollen sie eine weitere Berechnung durchfuehren?\n"; cout << "<J/N>"; //Abfrage ob weitergerechnet werden soll oder nicht cin >> antwort; system ("cls"); while ( std::tolower(antwort) != 'j' && std::tolower(antwort) != 'n' ) { cout << "Falsche Eingabe, wiederholen: "; //Fehlerabfang falls Zahl anstatt Buchstabe eingegeben wird cin >> antwort; } }while (std::tolower(antwort) == 'j' ); //Bedingung der Do-While-Schleife return 0; } long double calculate (int ausw,long double x,long double y) //Funktion zum berechnen der einzelnen Werte { long double res = 0.0; //Definition des Ergebnis-Wertes switch (ausw) //Switch-Anweisung für Menü-Auswahl { case 1 : //Berechnung zur Addition { res = x + y; break; } case 2 : //Berechnung zur Subatraktion { res = x - y; break; } case 3 : //Berechnung zur Multiplikation { res = x * y; break; } case 4 : //Berechnung zur Division { res = x / y; if (y == 0) //Fehlerabfang falls durch 0 dividiert wird { cout << "\nDivision durch 0 nicht moeglich!"; } break; } case 5 : { res = pow (x, y); //Berechnung zu Potenzierung break; } case 6 : { res = pow(x, 1.0 / y); //Berechnung zur Wurzelziehung break; } } return res; } long double prozent(int ausw, long double x, long double y) //Funktion zur Prozentrechnung { long double res = 0.0; switch (ausw) { case 7 : { res = x * y / 100; break; } } return res; } float winkel(int ausw, float x) { float res = 0.0; switch (ausw) { case 8 : { res = sin(x * M_PI / 180); break; } case 9 : { res = cos(x * M_PI / 180); break; } case 10 : { res = tan(x * M_PI / 180); break; } } return res; } float arcus (int ausw, float x) { float res = 0.0; switch(ausw) { case 13 : { res = asin(x) * 180 / M_PI; break; } case 14 : { res = acos(x) * 180 / M_PI; break; } case 15 : { res = atan(x) * 180 / M_PI; break; } } return res; } |