📄 simplecalu.cpp
字号:
//============================================================================// Name : SimpleCalu.cpp// Author : // Version :// Copyright : Your copyright notice// Description : Hello World in C, Ansi-style//============================================================================/*#include <stdio.h>#include "Calu.h"//#include "CaluHelp.h"void FriendFunc( void );class CTest{ friend void FriendFunc( void ); CTest( ) : m_iValue( 1 ) { } void ShowMsg( void ); int m_iValue;};void CTest::ShowMsg( void ){ printf( "Hello, my friend, you can invoked me of course!\n" );}void FriendFunc( void ){ CTest tester; printf("m_iValue is: %d", tester.m_iValue); printf("\n"); tester.ShowMsg( ); }class COwnInner // Size is 1 byte{public: class CInner // Size if 8 byte { public: int m_i1; int m_i2; };};*///int main(void) { /*//FriendFunc( ); //printf( "The size of the COwnInner is: %d \n", sizeof(COwnInner) ); //printf ( "The size of the CInner is: %d \n", sizeof(COwnInner::CInner) ); CCaluHelp::HelpQueue *pQueue = new CCaluHelp::HelpQueue; printf( "UseLength: %d \n", pQueue->UsedLength( ) ); printf( "FreeLength: %d \n", pQueue->FreeLength( ) ); for (int i = 0; i < 16; i++) { Element eTmp; eTmp.value = i; eTmp.type = 0; pQueue->AddToTail(eTmp); } printf( "UseLength: %d \n", pQueue->UsedLength( ) ); printf( "FreeLength: %d \n", pQueue->FreeLength( ) ); Element eTmp2; eTmp2.value = 17; eTmp2.type = 0; pQueue->AddToTail(eTmp2); printf( "UseLength: %d \n", pQueue->UsedLength( ) ); printf( "FreeLength: %d \n", pQueue->FreeLength( ) ); for (int i = 0; i < 5; i++) { printf( "Front: %f \n", (pQueue->Front( )).value ); } printf( "UseLength: %d \n", pQueue->UsedLength( ) ); printf( "FreeLength: %d \n", pQueue->FreeLength( ) ); //pQueue->AddToTail(18); //pQueue->AddToTail(19); //pQueue->AddToTail(20); //printf( "UseLength: %d \n", pQueue->UsedLength( ) ); //printf( "FreeLength: %d \n", pQueue->FreeLength( ) ); for (int i = 0; i < 17; ++i) pQueue->Front( ); printf( "Empty? %d", pQueue->Empty( ) ); delete pQueue;*/ /*printf("%d\n", '+'); printf("%d\n", '-'); printf("%d\n", '*'); printf("%d\n", '/'); // 1+2*3+4-2 Element e0; e0.value = 1; e0.type = NUMBER_TYPE; Element e1; e1.value = '+'; e1.type = OPERATOR_TYPE; Element e2; e2.value = 2; e2.type = NUMBER_TYPE; Element e3; e3.value = '*'; e3.type = OPERATOR_TYPE; Element e4; e4.value = 3; e4.type = NUMBER_TYPE; Element e5; e5.value = '+'; e5.type = OPERATOR_TYPE; Element e6; e6.value = 4; e6.type = NUMBER_TYPE; Element e7; e7.value = '-'; e7.type = OPERATOR_TYPE; Element e8; e8.value = 2; e8.type = NUMBER_TYPE; CCaluHelp::HelpStack *pStack = new CCaluHelp::HelpStack; //pStack->Push( e0 ); pStack->Push( e1 ); //pStack->Push( e2 ); pStack->Push( e3 ); //pStack->Push( e4 ); //pStack->Push( e5 ); //pStack->Push( e6 ); //pStack->Push( e7 ); //pStack->Push( e8 ); //while ( !pStack->Empty( ) ) //{ //printf( "Value: %f \n", pStack->Pop( ).value ); //} CCaluHelp::HelpStack stack; pStack->PopMatch( e3, stack ); while ( !stack.Empty( ) ) { printf( "Value: %f \n", stack.Pop( ).value ); } printf("Empty? %d\n", pStack->Empty( )); delete pStack;*/ //CCaluHelp::HelpQueue queue; //CCaluHelp calu; //const char *pcszExpr = "1+2+3*4"; //calu.ParseExpr( pcszExpr, queue ); /*while ( !queue.Empty( ) ) { Element e = queue.Front( ); if (e.type == NUMBER_TYPE) printf("%f \n", e.value); else if (e.type == OPERATOR_TYPE) printf("%c \n", (char)e.value); }*/ //float rel = calu.CaluPostfix( queue ); //printf("%d \n", (int)rel); //CCaluHelp *pCalu = new CCaluHelp; //const char * pcszExpr = "1+2*4"; //float fResult = pCalu->CaluExpr( pcszExpr ); //printf("The result of %s is %d \n", pcszExpr, (int)fResult); //delete pCalu; // Now, you see, the interface is easier to use then use the class. //const char * pcszExpr = "1+2*4"; //printf("The result of %s is %.2f \n", pcszExpr, CalculateExpr( pcszExpr ) ); //return 0;//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -