- Timestamp:
- Feb 23, 2012, 12:33:51 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Utilities/GenerateMathProblem01/GenerateMathProblem01.cpp
r53 r54 6 6 7 7 #include "stdafx.h" 8 #include <assert.h> 8 9 9 10 class Item … … 62 63 OperationItem() : 63 64 m_pItem1(NULL), 65 m_nSymbol(0), 64 66 m_pItem2(NULL) 65 67 { 68 } 69 OperationItem(Item* pItem1, CHAR nSymbol, Item* pItem2) : 70 m_pItem1(pItem1), 71 m_nSymbol(nSymbol), 72 m_pItem2(pItem2) 73 { 74 assert(pItem1 && IsValidSymbol(nSymbol) && pItem2); 75 } 76 static BOOL IsValidSymbol(CHAR nSymbol) 77 { 78 return nSymbol && strchr("+-*:", nSymbol) != NULL; 66 79 } 67 80 INT GetPriority() … … 73 86 return 2; 74 87 case '*': 75 case ' /':88 case ':': 76 89 return 1; 77 90 } … … 83 96 { 84 97 case '-': 85 case ' /':98 case ':': 86 99 return FALSE; 87 100 } … … 95 108 else 96 109 sString.Append(m_pItem1->AsString()); 110 assert(IsValidSymbol(m_nSymbol)); 97 111 sString.AppendFormat(_T(" %c "), m_nSymbol); 98 112 if(m_pItem2->GetPriority() > GetPriority() || m_pItem2->IsOperation() && m_pItem2->GetPriority() == GetPriority() && !IsCommutative()) … … 212 226 int _tmain(int argc, _TCHAR* argv[]) 213 227 { 228 #pragma region Special Case 229 #if defined(_DEBUG) 230 { 231 // NOTE: 232 // Actual: (77 + 53503) : 8360 : 88 : 12 233 // Correct: (77 + 53503) : (8360 : 88) : 12 234 OperationItem* pA = new OperationItem(new ValueItem(77), '+', new ValueItem(53503)); 235 OperationItem* pB = new OperationItem(new ValueItem(8630), ':', new ValueItem(88)); 236 OperationItem* pC = new OperationItem(pA, ':', pB); 237 OperationItem* pD = new OperationItem(pC, ':', new ValueItem(12)); 238 _tprintf(_T("pD->AsString() %s\n"), pD->AsString()); 239 pD->AsString(); 240 } 241 #endif // defined(_DEBUG) 242 #pragma endregion 214 243 srand(1); 215 244 for(INT nCount = 0; nCount < 1000; nCount++)
Note: See TracChangeset
for help on using the changeset viewer.