Home > Software engineering >  For a simple calculator MFC source code written in c
For a simple calculator MFC source code written in c

Time:09-26

Can be rolled back, can undertake arithmetic, there are (), trigonometric functions and so on, can be calculated,

CodePudding user response:

http://blog.csdn.net/dpsying/article/details/19047645

CodePudding user response:

The
reference 1/f, 7-eleven's reply:
http://blog.csdn.net/dpsying/article/details/19047645

Thank you, I also realized the function, but the record is not how to write, pray god grant instruction

CodePudding user response:


http://my.oschina.net/u/1030910/blog/700744
Interface saved, logic is simple

CodePudding user response:

Use the keyboard? How to implement?

CodePudding user response:

http://download.csdn.net/download/shen_wei/3733148

CodePudding user response:

Fyi:
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Functional calculator (vc + + 6.0, the Win32 Console)
Function:
Currently provides more than 10 common mathematical functions:
(1) sinusoidal sin
2 cosine cos
(3) tangent tan
(4) open square SQRT
5] arcsine arcsin
[6] the arccosine arccos
Once the arctangent arctan
Being common logarithm lg
'levies natural logarithm ln
Exp. ⑽ e index
⑾ been function ^
⑿ rounded up ceil
[13] the whole floor down
[14] round round round
Usage:
If asked 32 times the power of 2, can break into 2 ^ 32 & lt; Enter & gt;
If asked 30 degrees of tangent type tan (Pi/6) & lt; Enter & gt;
Note not scored: tan (30) & lt; Enter>
If required 1.23 radians sine, there are several approaches are effective:
Sin (1.23) & lt; Enter>
Sin 1.23 & lt; Enter>
Sin1.23 & lt; Enter>
If verification is cosine formula of sum of squares can be into sin (1.23) ^ 2 + cos (1.23) ^ 2 & lt; Enter> Or sin1.23 ^ 2 + cos1.23 ^ 2 & lt; Enter>
In addition two function together, automatic understanding for multiplication, such as: sin1.23 cos0.77 + cos1.23 sin0.77 is equivalent to the sin (1.23) * cos (0.77) + cos (1.23) * sin (0.77)
Of course, you can also be based on the triangle transform, reoccupy sin (1.23 + 0.77) or sin2 verify,
This calculator so give full consideration to the operator priority, such as: 2 + 3 * 4 ^ 2 effectively: 2 + (3) * (4 * 4)
In addition the function name if it is in front of the Numbers, then automatically think people.
Likewise, if a number is the right of the left parenthesis, automatically think that the number and implied a multiplication sign between a bracket,
Such as: 3 sin1. 2 ^ 2 + 5 cos2. 1 ^ 2 to 3 * sin2 + 5 * cos2 (1.2) (2.1)
Such as: 4 (3-2 (sqrt5-1) + ln2) + lg5 equivalent to 4 * (2 * 3-5 () - 1) + loge (2)) + log10 (5)
In addition, the calculator provides a Pi type letters case-insensitive, for ease of use,
Hexadecimal integer begin with 0 x or 0 x,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
# include & lt; Iostream>
# include & lt; Iomanip>
# include & lt; Cstdlib>
# include & lt; Cstring>
# include & lt; Cctype>
# include & lt; Cmath>
# include & lt; stdio.h>
# include & lt; String. H>
# include & lt; Windows. H>
using namespace std;
Const char Tab=0 x9;
Const int DIGIT=1;
Const int MAXLEN=16384;
Char s [MAXLEN], * endss;
Int PCS=15;
Double round (double dVal, short iPlaces) {//iPlaces>=0
Char s [30];
Double dRetval;

Sprintf (s, "%. * lf iPlaces, dVal);
Sscanf (s, "% lf", & amp; DRetval);
Return (dRetval);
}
Double fun (double x, char op [], int * iop) {
While (op iop [* 1] <32)//the bank make function calls without nested parentheses, such as arc sin (sin (1.234)) simply type arc sin sin 1.234 & lt; Enter>
The switch (op iop [* 1]) {
Case 7: x=sin (x); (* iop) -; break;
Case 8: x=cos (x); (* iop) -; break;
Case 9: x=tan (x); (* iop) -; break;
Case 10: x=SQRT (x); (* iop) -; break;
Case 11: x=asin (x); (* iop) -; break;
Case 12: x=a cosine (x); (* iop) -; break;
Case 13: x=atan (x); (* iop) -; break;
Case 14: x=log10 (x); (* iop) -; break;
Case: 15 x=log (x); (* iop) -; break;
Case: 16 x=exp (x); (* iop) -; break;
Case 17: x=ceil (x); (* iop) -; break;
Case: 18 x=floor (x); (* iop) -; break;
Case: 19 x=round (x, 0); (* iop) -; break;
}
return x;
}
Double calc (char * expr, char * * addr) {
Static int deep;//the recursion depth
Static char * fname []={" sin ", "cos", "tan", "SQRT", "arcsin", "arccos", "arctan", "lg", "ln", "exp", "ceil", "floor", "round", NULL};
Double ST [10]={0.0};//digital stack
Char op [10]={' + '};//operator stack
Rexp char c, * and * pp, * pf;
Int ist=1, iop=1, the last, I, n.
__int64 i64;

if (! Deep) {
Pp=pf=expr;
Do {
C=* pp++;
If (c!=' '& amp; & C!!!=Tab)
* pf++=c;
} while (c!='\ 0');
}
Pp=expr;
If (c=* (pp)=='-' | | c=='+') {
Op [0]=c;
Pp++;
}
The last=! DIGIT;
While (pp (c=*)!='\ 0') {
If (c=='(') {//left round brackets
Deep++;
ST [ist++]=calc (+ + pp, addr);
Deep -;
ST] [ist - 1=fun (ST] [ist - 1, op, & amp; Iop);
Pp=* addr.
The last DIGIT of=;
If (* pp=='(' | | isalpha pp (*) & amp; & Strnicmp (pp, "Pi", 2)) {//purpose is: when the right round bracket is extremely right to left round bracket or function name, the default for the multiplication
Op [iop++]='*';
The last=! DIGIT;
C=op [-- iop];
Goto operate;
}
}
Else if (c==') ') {//right round brackets
Pp++;
break;
{} else if (isalpha (c))
if (! Strnicmp (pp, "Pi", 2)) {
If (last==DIGIT) {
cout<"PI on the left side of the encounter)" & lt; }
ST [ist++]=3.14159265358979323846264338328;
ST] [ist - 1=fun (ST] [ist - 1, op, & amp; Iop);
Pp +=2;
The last DIGIT of=;
if (! Strnicmp (pp, "Pi", 2)) {
cout<"Connected to two PI" & lt; }
If (* pp=='(') {
cout<"PI right encounter (" & lt; }
} else {
For (I=0; (pf=fname [I])!=NULL; I++)
if (! Strnicmp (pp, pf, strlen (pf))) break;
If (pf!=NULL) {
Op [iop++]=7 + I;
Pp +=strlen (pf);
} else {
cout<"Strange function name" & lt; }
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related