Multifunktionaler Taschenrechner

Ihr kennt das alle und deshalb würde ich mal gerne sehen wer von euch den Taschenrechner mit den nützlichsten Funktionen programmieren kann. Es ist egal ob ihr es als Konsolen-Rechner oder mit GUI erstellt, wichtig ist der Umfang an mathematischen Funktionen und anderen nützlichen Extras (Zwischenwertespeicher, History...). Postet zu eurem Quellcode auch nen Screenshot des Programmes.

Und wehe euch es ist nur ein billiger Abklatsch des Windows-Rechners! ;)
 
Hier ist mein graphischer C++ Taschenrechner, Sourcecode und Screenshot.

Code:
/*Bleeding's Taschenrechner*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR nCmdLine, int nCmdShow)
{

	HWND hwnd;
	WNDCLASS wcl;
	MSG msg;
	char szName[]  = "Fensterklasse";
	HBRUSH MyBrush = CreateSolidBrush ( RGB (50, 0, 150) );


	wcl.cbClsExtra			= 0;
	wcl.cbWndExtra			= 0;
	wcl.hbrBackground		= MyBrush;
	wcl.hCursor				= 0;
	wcl.hIcon				= LoadIcon (NULL, IDI_APPLICATION);
	wcl.hInstance			= hInstance;
	wcl.lpfnWndProc			= WndProc;
	wcl.lpszClassName		= szName;
	wcl.lpszMenuName		= NULL;
	wcl.style				= 0; 


	RegisterClass (&wcl);

	hwnd = CreateWindow (szName, "Taschenrechner", WS_OVERLAPPEDWINDOW, 300, 100, 600, 600,
						  NULL, NULL, hInstance, NULL);
	
	ShowWindow   (hwnd, nCmdShow);
	UpdateWindow (hwnd);

	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage  (&msg);
	}
	
	return msg.wParam;
}




LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static HWND	hAdd;
	static HWND hSub;
	static HWND hMul;
	static HWND hDiv;
	static HWND hWur;
	static HWND hQua;
	static HWND hSin;
	static HWND hCos;
	static HWND hTan;
	static HWND hCot;
	static HWND	hlog;
	static HWND hlog2;
	static HWND	hlog10;
	static HWND hNum1;
	static HWND hNum2;
	static HWND hRes;
	char		szBuffer[20];
	double		fNum1;
	double		fNum2;

	
	switch (message)
	{

	case WM_CREATE:

		hAdd = CreateWindow ( "button", "Addieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 100, 200, 100, 40, hwnd, (HMENU)1, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hSub = CreateWindow ( "button", "Subtrahieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 400, 200, 100, 40, hwnd, (HMENU)2, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
								
		hMul = CreateWindow ( "button", "Multiplizieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 100, 250, 100, 40, hwnd, (HMENU)3, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
								
		hDiv = CreateWindow ( "button", "Dividieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 400, 250, 100, 40, hwnd, (HMENU)4, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);



		hWur = CreateWindow ( "button", "Wurzel", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 400, 300, 100, 40, hwnd, (HMENU)5, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hQua = CreateWindow ( "button", "Quadrieren", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 100, 300, 100, 40, hwnd, (HMENU)6, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);



		hSin  = CreateWindow ( "button", "Sinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 110, 400, 75, 20, hwnd, (HMENU)7, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
								
		hCos   = CreateWindow ( "button", "Cosinus", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 210, 400, 75, 20, hwnd, (HMENU)8, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
								
		hTan   = CreateWindow ( "button", "Tangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 310, 400, 75, 20, hwnd, (HMENU)9, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hCot   = CreateWindow ( "button", "Cotangenz", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 410, 400, 75, 20, hwnd, (HMENU)10, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hlog   = CreateWindow ( "button", "log", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 165, 450, 75, 20, hwnd, (HMENU)14, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hlog2  = CreateWindow ( "button", "log2", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 255, 450, 75, 20, hwnd, (HMENU)15, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hlog10 = CreateWindow ( "button", "log10", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
							 345, 450, 75, 20, hwnd, (HMENU)16, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);


		hNum1   = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
							 150, 100, 100, 30, hwnd, (HMENU)11, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);

		hNum2   = CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
							 350, 100, 100, 30, hwnd, (HMENU)12, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
		
		hRes	= CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_CHILD | WS_VISIBLE,
							 230, 500, 150, 40, hwnd, (HMENU)13, 
							 (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
	
		return 0;
		
			
	case WM_COMMAND:
		
		if ( LOWORD (wParam) ==1)
		{		
			GetDlgItemText( hwnd, 11, szBuffer, sizeof(szBuffer)/sizeof(char) ); // hNum1
			fNum1 = atof(szBuffer);

			GetDlgItemText ( hwnd,12, szBuffer, sizeof(szBuffer)/sizeof(char) ); // hNum2
			fNum2 = atof(szBuffer);

			_gcvt( (fNum1 + fNum2), 10, szBuffer );
			SetDlgItemText(hwnd, 13, szBuffer);
		}



		if ( LOWORD (wParam) ==2)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( (fNum1-fNum2), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}

		
		if ( LOWORD (wParam) ==3)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( (fNum1*fNum2), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}


		if ( LOWORD (wParam) ==4)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( (fNum1/fNum2), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}


		if ( LOWORD (wParam) ==5)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( sqrt(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}
		

		if ( LOWORD (wParam) ==6)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( (fNum1*fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}

		
		if ( LOWORD (wParam) ==7)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( sin(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}

		
		if ( LOWORD (wParam) ==8)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( cos(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}


		if ( LOWORD (wParam) ==9)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( tan(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}


		if ( LOWORD (wParam) ==10)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( tanh(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}

		if ( LOWORD (wParam) ==14)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( log(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}


		if ( LOWORD (wParam) ==15)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( (fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer);
		}
		

		if ( LOWORD (wParam) ==16)
		{
			GetDlgItemText (hwnd,11, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum1=atof(szBuffer);

			GetDlgItemText (hwnd, 12, szBuffer, sizeof (szBuffer)/sizeof(char) );
			fNum2 =atof(szBuffer);

			_gcvt ( log10(fNum1), 10, szBuffer );
			SetDlgItemText (hwnd, 13, szBuffer );
		}



		return 0;	

	
		


	case WM_DESTROY:
	     PostQuitMessage (0);
		 return 0;

	}

	return DefWindowProc (hwnd, message, wParam, lParam);

}

Kommazahlen müssen mit Punkt angegeben werden, z.B 125.35 statt 125,35.

Eine Verbesserung sollte man noch machen, und zwar dass beim Verändern der Fenstergröße auch der Fensterinhalt mit verändernt wird. Weiss aber nicht wie das geht...mit API Programmierung kenn ich mich nicht so besonders aus. Wenn ich mal Zeit hab werd ich vielleicht noch dran arbeiten.


mfG
Bleeding
 
Ist sicherlich ein ordentliches Beispiel, aber zwei wichtige Funktionen, die Tec genannt hat fehlen (wenn ich sie nicht nur übersehen habe), nämlich der Speicher und die History.
 
Also ich bin jetzt zwar noch nicht so weit, aber allerdings hab ich schonmal die gröbsten Funktionen, Programmiere mit PVX und NOMADS auch erst seit 4 Tagen.

Hier erst einmal die Rechen Funktionen des Benutzten Programms
Code:
! J.U.B. sein Taschenrechner
INI:
	ERG=0, VARI1=0, VARI2=0
ADDI:
	REFRESH_FLG=1
	ERG=VARI1+VARI2
	RETURN
SUBI:
	REFRESH_FLG=1
	ERG=VARI1-VARI2
	RETURN
MULT:
	REFRESH_FLG=1
	ERG=VARI1*VARI2
	RETURN
DIVI:
	REFRESH_FLG=1
	ERG=VARI1/VARI2
	RETURN
QUAD:
	MSGBOX "Hier wird nur die Zahl auf dem ersten Kästchen hoch 2 genommen","ACHTUNG!"
	REFRESH_FLG=1
	ERG=VARI1*VARI1
	RETURN
WURZ:
	MSGBOX "Hier wird nur die Wurzel der Zahl aus dem ersten Kästchen genommen","ACHTUNG!"
	REFRESH_FLG=1
	ERG=SQR(VARI1)
	RETURN
SINU:
	MSGBOX "Hier wird nur die Zahl aus dem ersten Kästchen verwendet","ACHTUNG!"
	REFRESH_FLG=1
	ERG=SIN(VARI1)
	RETURN
COSI:
	MSGBOX "Hier wird nur die Zahl aus dem ersten Kästchen verwendet","ACHTUNG!"
	REFRESH_FLG=1
	ERG=COS(VARI1)
	RETURN
TANG:
	MSGBOX "Hier wird nur die Zahl aus dem ersten Kästchen verwendet","ACHTUNG!"
	REFRESH_FLG=1
	ERG=TAN(VARI1)
	RETURN
LOGI:
	MSGBOX "Hier wird nur die Zahl aus dem ersten Kästchen verwendet","ACHTUNG!"
	REFRESH_FLG=1
	ERG=LOG(VARI1)
	RETURN

Und Hier der Taschenrechner
taschenrechner.jpg
 
Zurück
Oben