the Hellboard (http://old.the-hellboard.de/index.php)
- Computer und Co (http://old.the-hellboard.de/board.php?boardid=10)
--- Software (http://old.the-hellboard.de/board.php?boardid=12)
---- Coder Forum (http://old.the-hellboard.de/board.php?boardid=90)
----- mdcalc (http://old.the-hellboard.de/thread.php?threadid=4489)


Geschrieben von Three of Five am 25.09.2005 um 13:20:

  mdcalc

ja, seit gestern schreib ich an mdcalc, einem taschenrechner, der seine eingaben per kommandozeilen parameter erwartet (damit ich ihn einfach per exec -o per xchat aufrufen kann)

hier sind die sourcen:

code:
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:
/* mdclac by Martin Dannehl, (c)2005 - 3of5@unimatrix-01.org
Weiterverbreitung und Weiterbearbeitung unter Beibehaltung des Copyrights erlaubt*/
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main (int argc,char* argv[])
{
	bool pararight = false;
	if (argc == 1)		//Überprüfen ob Parameteranzahl korrekt, wenn nicht Meldung und Ende
	{
		cout << "mdcalc (c) 2005 Martin Dannehl" << endl 
			<< "Usage: Wert1 Operand Wert2" << endl
			<< "Zulässige Operanden: " << endl
			<< "+ (Summe)" << endl
			<< "- (Differenz)" << endl
			<< "x (Produkt)" << endl
			<< "/ (Quotient)" << endl
			<< "^ (Potenz)" << endl
				<< "_ (Wurzel)" << endl;
		pararight = true;
	}
	if (argc == 4)
	{
		pararight = true;
		double Wert1,Wert2;		//Einlesen der Parameter in Variablen
		char operand;
		Wert1 = atof(argv[1]);
		Wert2 = atof(argv[3]);
		operand = argv[2][0];
		switch (operand)		//Auswählen und berechnen anhand des Operanden
		{
			case '+': cout << Wert1 << " + " << Wert2 << " = " << Wert1+Wert2 << endl;break;
			case '-': cout << Wert1 << " - " << Wert2 << " = " << Wert1-Wert2 << endl;break;
			case 'x': cout << Wert1 << " x " << Wert2 << " = " << Wert1*Wert2 << endl;break;
			case '/': cout << Wert1 << " / " << Wert2 << " = " << Wert1/Wert2 << endl;break;
			case '^': cout << Wert1 << " ^ " << Wert2 << " = " << pow(Wert1,Wert2) << endl;break;
			case '_': cout << Wert1 << " _ " << Wert2 << " = " << pow(Wert1,(1/Wert2)) << endl;break;
			default: cout << "Fehlerhafter Operand!" << endl 
					<< "Zulässig: + - x / ^" << endl;
		}
	}
	if (!pararight)
		cout << "Fehlerhafte Parameteranzahl!" << endl << "Bitte in angeben: Wert1 Operand Wert2" << endl;
}

als nächstes bastel ich wohl eine fakultätsberechnung dazu und vllt das parsen von termen, was stanny schon im irc vorgeschlagen hatte
da hab ich nur noch net so ne rechte idee wie ich das implementieren soll



Geschrieben von MoD3000 am 25.09.2005 um 15:21:

 

wenn du in den beiden ifs "return"st, kannst du dir die pararight Variable sparen smile


Forensoftware: Burning Board 2.3.6, entwickelt von WoltLab GmbH