From 415e1ecd6fa75a1999fd60c1c579fe512d3ae500 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Thu, 17 Dec 2020 00:48:03 +0100 Subject: [PATCH 1/2] Creating new bugs --- main.cpp | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 164 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index a3f3074..2670c49 100644 --- a/main.cpp +++ b/main.cpp @@ -130,8 +130,8 @@ bool checkChar(char c, int type) void heapPointer(int y) { - gotoxy(0, 0); - std::cout << y; + /*gotoxy(0, 0); + std::cout << y;*/ char t = '\0'; if(y > 0) @@ -185,11 +185,35 @@ void heapPointer(int y) for(int i = 0; i <= 10; i++) std::cout << " "; } +void displayNumBuilder(int n) +{ + int len; + int i = n; + + for(len = 0; i > 0; len++) + { + i /= 10; + } + + //std::cout << 10 - len; + + gotoxy(2, 2); + color(RED, BLACK); + std::cout << n; + for(int j = 0; j < (10 - len); j++) + { + std::cout << " "; + } + color(WHITE, BLACK); +} + std::string stringToONP(std::string s, int speed = 500) { heapPointer(0); std::string out = ""; int len = s.length(); + int numBuild = 0; + int numBuildCount = 1; char tmp; char heap[100] {}; @@ -205,6 +229,11 @@ std::string stringToONP(std::string s, int speed = 500) switch (tmp) { case '=': + numBuildCount = 1; + out += std::to_string(numBuild); + numBuild = 0; + out += ";"; + displayNumBuilder(0); for (; counter > 0; counter--) { out += heap[counter - 1]; @@ -236,12 +265,21 @@ std::string stringToONP(std::string s, int speed = 500) case '7': case '8': case '9': - out += tmp; + numBuild += (numBuildCount * (tmp - '0')); + numBuildCount *= 10; + displayNumBuilder(numBuild); + //out += tmp; break; case '+': case '-': case '*': case '/': + numBuildCount = 1; + out += std::to_string(numBuild); + numBuild = 0; + out += ";"; + displayNumBuilder(0); + while (counter) { if (priority(tmp) > priority(heap[counter - 1])) break; @@ -325,10 +363,13 @@ int calculateONP(std::string s, int speed = 500) { heapPointer(0); int out = 0; + int numBuild = 0; + int numBuildCount = 1; int len = s.length(); char tmp; int counter = 0; int calculate = 0; + int digit = 0; int heap[100]{}; for (int i = 0; i < 100; i++) heap[i] = 0; @@ -336,11 +377,39 @@ int calculateONP(std::string s, int speed = 500) for (int i = 0; i < len; i++) { //gotoxy(1 + i, 8); + color(LIGHT_GREEN, BLACK); gotoxy(41 + i, 4); std::cout << " ^"; tmp = s.c_str()[i]; switch (tmp) { + case ';': + heap[counter] = numBuild; + //gotoxy(3 + (2 * counter), 2); + + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + //std::cout << numBuild; + gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK); + counter++; + heapPointer(counter); + + gotoxy(2, 3 + counter); + color(YELLOW, BLACK); + std::cout << numBuild; + + numBuildCount = 1; + numBuild = 0; + displayNumBuilder(0); + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + std::cout << tmp; + gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK); + break; case '0': case '1': case '2': @@ -351,7 +420,16 @@ int calculateONP(std::string s, int speed = 500) case '7': case '8': case '9': - heap[counter] = tmp - '0'; + numBuild += (numBuildCount * (tmp - '0')); + numBuildCount *= 10; + displayNumBuilder(numBuild); + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + std::cout << tmp; + gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK); + /*heap[counter] = tmp - '0'; //gotoxy(3 + (2 * counter), 2); gotoxy(2, 4 + counter); color(YELLOW, LIGHT_PURPLE); @@ -363,7 +441,7 @@ int calculateONP(std::string s, int speed = 500) std::cout << " ^"; color(WHITE, BLACK); counter++; - heapPointer(counter); + heapPointer(counter);*/ break; case '+': calculate = heap[counter - 2] + heap[counter - 1]; @@ -372,7 +450,7 @@ int calculateONP(std::string s, int speed = 500) //(((2+2)+2)+2)+2= //gotoxy(3 + (2 * (counter - 2)), 2); gotoxy(2, 4 + counter - 2); - color(YELLOW, LIGHT_PURPLE); + color(YELLOW, BLACK); std::cout << " "; //gotoxy(3 + (2 * (counter - 1)), 2); gotoxy(2, 4 + counter - 1); @@ -381,7 +459,7 @@ int calculateONP(std::string s, int speed = 500) heapPointer(counter); heap[counter++] = calculate; heapPointer(counter); - color(YELLOW, LIGHT_PURPLE); + color(YELLOW, BLACK); //gotoxy(3 + (2 * (counter - 1)), 2); gotoxy(2, 4 + counter - 1); std::cout << calculate; @@ -393,7 +471,7 @@ int calculateONP(std::string s, int speed = 500) color(WHITE, BLACK); break; case '-': - calculate = heap[counter - 2] - heap[counter - 1]; + /*calculate = heap[counter - 2] - heap[counter - 1]; heap[counter - 2] = 0; heap[counter - 1] = 0; //gotoxy(3 + (2 * (counter - 2)), 2); @@ -415,11 +493,36 @@ int calculateONP(std::string s, int speed = 500) color(LIGHT_GREEN, BLACK); std::cout << tmp; gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK);*/ + calculate = heap[counter - 2] - heap[counter - 1]; + heap[counter - 2] = 0; + heap[counter - 1] = 0; + //(((2+2)+2)+2)+2= + //gotoxy(3 + (2 * (counter - 2)), 2); + gotoxy(2, 4 + counter - 2); + color(YELLOW, BLACK); + std::cout << " "; + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << " "; + counter -= 2; + heapPointer(counter); + heap[counter++] = calculate; + heapPointer(counter); + color(YELLOW, BLACK); + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << calculate; + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + std::cout << tmp; + gotoxy(41 + i, 4); std::cout << " ^"; color(WHITE, BLACK); break; case '*': - calculate = heap[counter - 2] * heap[counter - 1]; + /*calculate = heap[counter - 2] * heap[counter - 1]; heap[counter - 2] = 0; heap[counter - 1] = 0; //gotoxy(3 + (2 * (counter - 2)), 2); @@ -441,6 +544,31 @@ int calculateONP(std::string s, int speed = 500) color(LIGHT_GREEN, BLACK); std::cout << tmp; gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK);*/ + calculate = heap[counter - 2] * heap[counter - 1]; + heap[counter - 2] = 0; + heap[counter - 1] = 0; + //(((2+2)+2)+2)+2= + //gotoxy(3 + (2 * (counter - 2)), 2); + gotoxy(2, 4 + counter - 2); + color(YELLOW, BLACK); + std::cout << " "; + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << " "; + counter -= 2; + heapPointer(counter); + heap[counter++] = calculate; + heapPointer(counter); + color(YELLOW, BLACK); + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << calculate; + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + std::cout << tmp; + gotoxy(41 + i, 4); std::cout << " ^"; color(WHITE, BLACK); break; @@ -467,7 +595,7 @@ int calculateONP(std::string s, int speed = 500) color(WHITE, BLACK); return 0; } - calculate = heap[counter - 2] / heap[counter - 1]; + /*calculate = heap[counter - 2] / heap[counter - 1]; heap[counter - 2] = 0; heap[counter - 1] = 0; //gotoxy(3 + (2 * (counter - 2)), 2); @@ -489,6 +617,31 @@ int calculateONP(std::string s, int speed = 500) color(LIGHT_GREEN, BLACK); std::cout << tmp; gotoxy(41 + i, 4); + std::cout << " ^"; + color(WHITE, BLACK);*/ + calculate = heap[counter - 2] / heap[counter - 1]; + heap[counter - 2] = 0; + heap[counter - 1] = 0; + //(((2+2)+2)+2)+2= + //gotoxy(3 + (2 * (counter - 2)), 2); + gotoxy(2, 4 + counter - 2); + color(YELLOW, BLACK); + std::cout << " "; + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << " "; + counter -= 2; + heapPointer(counter); + heap[counter++] = calculate; + heapPointer(counter); + color(YELLOW, BLACK); + //gotoxy(3 + (2 * (counter - 1)), 2); + gotoxy(2, 4 + counter - 1); + std::cout << calculate; + gotoxy(42 + i, 3); + color(LIGHT_GREEN, BLACK); + std::cout << tmp; + gotoxy(41 + i, 4); std::cout << " ^"; color(WHITE, BLACK); break; @@ -700,7 +853,7 @@ int main(int argc, char *argv[]) tmp3 >> sp3; system("cls"); - system("pause > NUL"); + //system("pause > NUL"); color(GREEN, GREEN); for(int i = 1; i <= 28; i++) From e6d279988b35c5209e3a94d4cce6d37f7d1ae308 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Tue, 19 Jan 2021 21:14:40 +0100 Subject: [PATCH 2/2] Major bugfixes --- main.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 2670c49..a0813f9 100644 --- a/main.cpp +++ b/main.cpp @@ -219,6 +219,7 @@ std::string stringToONP(std::string s, int speed = 500) char heap[100] {}; for (int i = 0; i < 100; i++) heap[i] = '\0'; int counter = 0; + char prev = '\0'; for (int i = 0; i < len; i++) { @@ -275,10 +276,14 @@ std::string stringToONP(std::string s, int speed = 500) case '*': case '/': numBuildCount = 1; - out += std::to_string(numBuild); - numBuild = 0; - out += ";"; - displayNumBuilder(0); + if(prev == ')') prev = '\0'; + else { + out += std::to_string(numBuild); + + numBuild = 0; + out += ";"; + displayNumBuilder(0); + } while (counter) { @@ -321,7 +326,40 @@ std::string stringToONP(std::string s, int speed = 500) color(WHITE, BLACK); break; case ')': - + prev = ')'; + numBuildCount = 1; + out += std::to_string(numBuild); + numBuild = 0; + out += ";"; + displayNumBuilder(0); + + while (counter) + { + if(heap[counter - 1] == '(') break; + if (priority(tmp) > priority(heap[counter - 1])) break; + out += heap[--counter]; + heapPointer(counter); + heap[counter] = '\0'; + /*gotoxy(3 + (2 * counter), 2); + color(RED, BLACK); + std::cout << " "; + color(WHITE, BLACK);*/ + gotoxy(2, 3 + counter); + color(YELLOW, LIGHT_PURPLE); + if(counter != 0) std::cout << " "; + color(WHITE, BLACK); + } + heap[counter] = tmp; + /*gotoxy(3 + (2 * counter), 2); + color(RED, BLACK); + std::cout << tmp; + color(WHITE, BLACK);*/ + heapPointer(counter + 1); + gotoxy(2, 4 + counter); + color(YELLOW, LIGHT_PURPLE); + std::cout << tmp; + counter++; + color(WHITE, BLACK); for (; heap[counter] != '('; counter--) { heapPointer(counter); @@ -370,6 +408,7 @@ int calculateONP(std::string s, int speed = 500) int counter = 0; int calculate = 0; int digit = 0; + char prev = '\0'; int heap[100]{}; for (int i = 0; i < 100; i++) heap[i] = 0;