Hier ist ein Rechner mit Punkt vor Strich funktion, allerdings mehr als 250 Zeilen musst halt überflüssiges rauslöschen (ascii codes etc.)
//*****************************************************************
//Autor:
//Datum: 2001-05-10
//Name: rechner2.cpp
//System: Borland Compiler Ver. 5.00
//Aufgabe: Erstellung eines Rechners, bei dem man beliebig viele
// Variablen und Rechenoperatoren eingeben kann.
//*****************************************************************
#include <iostream.h>
#include <conio.h>
void anfang();
void hilfefunktion();
float plus(float);
float minus(float);
float mal(float);
float durch(float);
float hoch(float);
float eingabe();
void verteiler();
char operant;
int counter;
float eingabe() {
float zahl;
cin >> zahl;
if (zahl < 10)
counter = counter + 2;
if (zahl >= 10 && zahl < 100)
counter = counter + 3;
if (zahl >= 100 && zahl < 1000)
counter = counter + 4;
if (zahl >= 1000 && zahl < 10000)
counter = counter + 5;
if (zahl >= 10000 && zahl < 100000)
counter = counter + 6;
if (zahl >= 100000 && zahl < 1000000)
counter = counter + 7;
if (zahl >= 1000000 && zahl < 10000000)
counter = counter + 8;
if (zahl >= 10000000 && zahl < 100000000)
counter = counter + 9;
if (zahl >= 100000000)
counter = counter + 10;
return zahl;
} //eingabe
float hoch(float Zahl1) {
int Zahl2, i;
float teilergebnis, erg2;
Zahl2 = (int)eingabe();
erg2 = Zahl1;
teilergebnis = Zahl1;
cin >> operant;
if (Zahl2 == 0)
return teilergebnis = 1;
else {
if (operant == '/' || operant == '*' || operant == '^') {
if (operant == '^') {
for (i = 1; i < Zahl2; i++)
erg2 = erg2 * Zahl1;
teilergebnis = hoch(erg2);
} //if
if (operant == '*') {
for (i = 1; i < Zahl2; i++)
erg2 = erg2 * Zahl1;
teilergebnis = mal(erg2);
} //if
if (operant == '/') {
for (i = 1; i < Zahl2; i++)
erg2 = erg2 * Zahl1;
teilergebnis = durch(erg2);
} //if
} //if
else
for (i = 1; i < Zahl2; i++)
teilergebnis = teilergebnis * Zahl1;
return teilergebnis;
} //else
} //hoch
float durch(float Zahl1) {
float Zahl2, teilergebnis, erg2;
Zahl2 = eingabe();
cin >> operant;
if (operant == '*' || operant == '/' || operant == '^' && operant != '=') {
if (operant == '*') {
erg2 = Zahl1 / Zahl2;
teilergebnis = mal(erg2);
} //if
if (operant == '/') {
erg2 = Zahl1 / Zahl2;
teilergebnis = durch(erg2);
} //if
if (operant == '^')
teilergebnis = Zahl1 / hoch(Zahl2);
} //if
else
teilergebnis = Zahl1 / Zahl2;
return teilergebnis;
} //durch
float mal(float Zahl1) {
float Zahl2, teilergebnis, erg2;
Zahl2 = eingabe();
cin >> operant;
if (operant == '*' || operant == '/' || operant == '^' && operant != '=') {
if (operant == '*') {
erg2 = Zahl1 * Zahl2;
teilergebnis = mal(erg2);
} //if
if (operant == '/') {
erg2 = Zahl1 * Zahl2;
teilergebnis = durch(erg2);
} //if
if (operant == '^')
teilergebnis = Zahl1 * hoch(Zahl2);
} //if
else
teilergebnis = Zahl1 * Zahl2;
return teilergebnis;
} //mal
float minus(float Zahl1) {
float Zahl2, teilergebnis;
Zahl2 = eingabe();
cin >> operant;
if (operant == '*' || operant == '/' || operant == '^') {
if (operant == '*')
teilergebnis = Zahl1 - mal(Zahl2);
if (operant == '/')
teilergebnis = Zahl1 - durch(Zahl2);
if (operant == '^')
teilergebnis = Zahl1 - hoch(Zahl2);
} //if
else
teilergebnis = Zahl1 - Zahl2;
return teilergebnis;
} //minus
float plus(float Zahl1) {
float Zahl2, teilergebnis;
Zahl2 = eingabe();
cin >> operant;
if (operant == '*' || operant == '/' || operant == '^') {
if (operant == '*')
teilergebnis = Zahl1 + mal(Zahl2);
if (operant == '/')
teilergebnis = Zahl1 + durch(Zahl2);
if (operant == '^')
teilergebnis = Zahl1 + hoch(Zahl2);
} //if
else
teilergebnis = Zahl1 + Zahl2;
return teilergebnis;
} //plus
void verteiler() {
float endergebnis = 0;
int i = 0, xpos, ypos;
if (i == 0) {
i++;
operant = '+';
} //if
cout << " " << char(201);
for (i = 0; i <= 35; i++)
cout << char(205);
cout << char(187) << "\n";
cout << " " << char(186) << " Rechner";
cout << " " << char(186) << "\n";
cout << " " << char(200);
for (i = 0; i <= 35; i++)
cout << char(205);
cout << char(188) << "\n\n\n\n\n";
cout << " " << char(218);
for (i = 0; i <= 45; i++)
cout << char(196);
cout << char(191) << "\n";
cout << " Ihre Eingabe: " << char(179);
cout << " ";
cout << char(179) << "\n";
cout << " " << char(192);
for (i = 0; i <= 20; i++)
cout << char(196);
cout << char(194);
for (i = 0; i <= 16; i++)
cout << char(196);
cout << char(194);
cout << char(196) << char(196) << char(196) << char(196) << char(196) << char(196);
cout << char(217) << "\n";
cout << " Ergebnis: ";
cout << char(179);
cout << " ";
cout << char(179) << "\n ";
cout << char(192);
for(i = 0; i <= 16; i++)
cout << char(196);
cout << char(217);
cout << "\n\n [bitte alle Zeichen und Zahlen OHNE Return und Space eingeben]";
xpos = 3;
ypos = 21;
gotoxy(xpos, ypos);
cout << "Verfuegbare Operanten: PLUS(+), MINUS(-), MAL(*), GETEILT(/) und HOCH(^)\n\n";
cout << " Zum Zeigen des Ergebnises bitte 'ISTGLEICH(=)' eingeben.";
xpos = 18;
ypos = 9;
gotoxy(xpos, ypos);
do {
switch(operant) {
case '+' : endergebnis = plus(endergebnis);
break;
case '-' : endergebnis = minus(endergebnis);
break;
case '*' : endergebnis = mal(endergebnis);
break;
case '/' : endergebnis = durch(endergebnis);
break;
case '^' : endergebnis = hoch(endergebnis);
break;
} //switch
} while(operant != '=');
xpos = 41;
ypos = 11;
gotoxy(xpos, ypos);
cout << endergebnis;
xpos = 27;
ypos = 17;
gotoxy(xpos, ypos);
cout << "<<< Weiter mit TASTE >>>";
getch();
} //verteiler
void hilfefunktion() {
int i;
clrscr();
cout << " ";
cout << char(201);
for (i = 0; i <= 20; i++)
cout << char(205);
cout << char(187) << "\n";
cout << " " << char(186);
cout << " HILFE VER.0.2b " << char(186) << "\n";
cout << " ";
cout << char(200);
for (i = 0; i <= 20; i++)
cout << char(205);
cout << char(188) << "\n\n";
cout << "Hier wird einmal der Hilfetext stehen!\n";
cout << "um zurueckzukehren, <TASTE> drueken! ";
getch();
clrscr();
} //hilfefunktion
void anfang() {
char auswahl;
int i;
clrscr();
do {
cout << "\n " << char(201);
for (i = 0; i <= 50; i++)
cout << char(205);
cout << char(187);
cout << "\n " << char(186);
cout << " Autor: , Germany";
cout << " " << char(186) << "\n";
cout << " " << char(186);
cout << " Datum: 10.05.2001";
cout << " " << char(186) << "\n";
cout << " " << char(186);
cout << " Testsystem: PII/333MHz, 192MB RAM, MS-DOS6.2";
cout << " " << char(186) << "\n";
cout << " " << char(200);
for (i = 0; i <= 50; i++)
cout << char(205);
cout << char(188) << "\n\n";
cout << " Dieses Programm ist wie ein Taschenrechner. \n\n\n";
cout << " ";
cout << char(201);
for (i = 0; i <= 20; i++)
cout << char(205);
cout << char(187) << "\n";
cout << " " << char(186);
cout << " RECHNER VER.3.8 " << char(186) << "\n";
cout << " ";
cout << char(200);
for (i = 0; i <= 20; i++)
cout << char(205);
cout << char(188) << "\n\n\n\n\n";
cout << "\nWeiter mit <W> (Hilfe mit <H> ) ";
cin >> auswahl;
if (auswahl == 'h' || auswahl == 'H')
hilfefunktion();
} while(auswahl != 'W' && auswahl != 'w');
} //anfang
void main(void) {
char nochmal;
anfang();
clrscr();
do {
clrscr();
verteiler();
clrscr();
cout << "\n\n\n\n";
cout << " Noch eine Berechnung durchfueren?\n";
cout << " ([j]a / [n]ein) ";
cout << " ";
cin >> nochmal;
counter = 0;
} while(nochmal != 'n');
} //main
ein weiterer Vorschlag: ne Verkettete liste (mit strukturen etc.)