Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <winbgim.h>
- #include <cmath>
- #include <windows.h>
- #include <conio.h>
- #include "graphics.h"
- #include <stdio.h>
- #include <mmsystem.h>
- #include <string.h>
- #include <locale>
- #include <string>
- #include <cstdio>
- #include <stdlib.h>
- using namespace std;
- ///ecuatia postfixata
- #define BLANK ' '
- #define TAB '\t'
- using namespace std;
- void scrie();
- void push(long int symbol);
- long int pop();
- void infix_to_postfix();
- long int eval_post();
- int priority(char symbol);
- int isEmpty();
- int white_space(char);
- char infix[100]; char postfix[100];
- long int stack[100];
- int top;
- int nr_elem;
- enum limbi { RO, EN, FR };
- limbi limba = RO;
- const int h = getmaxheight();
- const int w = getmaxwidth();
- char ec_postfixata[100][100];
- ///nr de nivele
- bool operand(char op[])
- {
- return !(strcmp(op, "+") == 0 || strcmp(op, "-") == 0 || strcmp(op, "*") == 0 || strcmp(op, "/") == 0);
- }
- int nivelMaxim(char ec_postfixata[100][100], int nr_elem)
- {
- int nivel[256] = { 0 };
- int k = 0;
- for (int i = 1; i <= nr_elem; i++)
- if (operand(ec_postfixata[i]))
- nivel[++k] = 1;
- else
- {
- k--;
- nivel[k] = 1 + max(nivel[k], nivel[k + 1]);
- }
- return nivel[1];
- }
- int nr_nivele = nivelMaxim(ec_postfixata, nr_elem);
- ///nr de caractere a unui element
- int nr_digituri[100];
- void digitNumar(char postfix[100], int nr_digituri[100], int& nr)
- {
- int k = 0;
- int i;
- for (i = 0; i < strlen(infix); i++)
- {
- if (infix[i] >= '0' && infix[i] <= '9')
- nr_digituri[k]++;
- else
- k++;
- }
- nr = k;
- }
- void transformaEcuatiaPostfixataInMatrice(char postfix[100])
- {
- for (int i = 0; i < nr_elem; i++)
- {
- int aux = nr_digituri[i];
- for (int j = 0; j < aux; j++)
- {
- ec_postfixata[i][j] = postfix[j];
- }
- int ok = 0;
- while (ok != aux)
- {
- for (int j = 0; j < nr_elem - 1; j++)
- postfix[j] = postfix[j + 1];
- ok++;
- }
- }
- }
- int i;
- void paginaPrincipala(int w, int h);
- void optiuni();
- int culoare1 = RED;
- int culoare2 = YELLOW;
- void schimbaPagOptiuni()
- {
- setbkcolor(BLACK);
- cleardevice();
- setcolor(LIGHTMAGENTA);
- }
- void deseneazaNod(int x, int y, int r, string s, int dim)
- {
- setcolor(culoare2);
- setfillstyle(SOLID_FILL, culoare1);
- fillellipse(x, y, r, r);
- settextstyle(EUROPEAN_FONT, HORIZ_DIR, dim);
- setbkcolor(culoare1);
- // Crede-ma pe cuvant, murim incet altfel. Nu tb sa faci nimic la el, doar o sa mearga.
- char ptCaChar[s.length()];
- strcpy(ptCaChar, s.c_str());
- outtextxy(x - r / 2, y - r / 2, ptCaChar);
- }
- void deschideNouaPagina(int w, int h)
- {
- setbkcolor(BLACK);
- cleardevice();
- readimagefile("Capture.JPG", 0, 0, w, h);
- }
- void butonIntermediarInapoi(int h)
- {
- setcolor(LIGHTGREEN);
- setbkcolor(GREEN);
- settextstyle(3, HORIZ_DIR, 27);
- if (limba == 0)
- outtextxy(100, h - 100, "INAPOI");
- else if (limba == 1)
- outtextxy(100, h - 100, "BACK");
- else if (limba == 2)
- outtextxy(100, h - 100, "RETOUR");
- }
- void butonIntermediarAfisare(int w, int h)
- {
- setcolor(RED);
- setbkcolor(YELLOW);
- settextstyle(3, HORIZ_DIR, 27);
- if (limba == 0)
- outtextxy(w - 320, h - 100, "REZULTAT");
- else if (limba == 1)
- outtextxy(w - 320, h - 100, "RESULT");
- else if (limba == 2)
- outtextxy(w - 320, h - 100, "RESULTAT");
- }
- void schimbaCulori(int w, int h)
- {
- schimbaPagOptiuni();
- settextstyle(4, HORIZ_DIR, 7);
- if (limba == 0)
- outtextxy(w / 2 - 200, 100, "CULORI");
- else if (limba == 1)
- outtextxy(w / 2 - 200, 100, "COLORS");
- else if (limba == 2)
- outtextxy(w / 2 - 200, 100, "COULEURS");
- settextstyle(6, 0, 4);
- setcolor(WHITE);
- if (limba == 0)
- outtextxy(200, 400, "CULOARE NOD");
- else if (limba == 1)
- outtextxy(200, 400, "NODE COLOR");
- else if (limba == 2)
- outtextxy(200, 400, "COULEUR DU NOEUD");
- setfillstyle(SOLID_FILL, COLOR(179, 255, 242));
- fillellipse(650, 400, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(255, 255, 77));
- fillellipse(750, 400, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(255, 153, 153));
- fillellipse(850, 400, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(255, 166, 77));
- fillellipse(950, 400, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(255, 153, 238));
- fillellipse(1050, 400, 30, 30);
- if (limba == 0)
- outtextxy(200, 600, "CULOARE SCRIS");
- else if (limba == 1)
- outtextxy(200, 600, "WRITING COLOR");
- else if (limba == 2)
- outtextxy(200, 600, "COULEUR D'ECRITURE");
- setfillstyle(SOLID_FILL, COLOR(102, 0, 153));
- fillellipse(650, 600, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(26, 0, 153));
- fillellipse(750, 600, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(128, 0, 85));
- fillellipse(850, 600, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(9, 51, 0));
- fillellipse(950, 600, 30, 30);
- setfillstyle(SOLID_FILL, COLOR(102, 0, 0));
- fillellipse(1050, 600, 30, 30);
- butonIntermediarInapoi(h);
- int ok = 0, x, y;
- while (ok == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, x, y);
- if (getpixel(x, y) == GREEN || getpixel(x, y) == LIGHTGREEN)
- {
- ok = 1;
- optiuni();
- }
- else if (getpixel(x, y) == COLOR(179, 255, 242) || getpixel(x, y) == COLOR(255, 255, 77) || getpixel(x, y) == COLOR(255, 153, 153) || getpixel(x, y) == COLOR(255, 166, 77) || getpixel(x, y) == COLOR(255, 153, 238))
- {
- ok = 1;
- culoare1 = getpixel(x, y);
- schimbaCulori(w, h);
- }
- else if (getpixel(x, y) == COLOR(102, 0, 153) || getpixel(x, y) == COLOR(26, 0, 153) || getpixel(x, y) == COLOR(128, 0, 85) || getpixel(x, y) == COLOR(9, 51, 0) || getpixel(x, y) == COLOR(102, 0, 0))
- {
- ok = 1;
- culoare2 = getpixel(x, y);
- schimbaCulori(w, h);
- }
- }
- }
- void schimbalimba(int w, int h)
- {
- schimbaPagOptiuni();
- settextstyle(4, HORIZ_DIR, 7);
- if (limba == 0)
- outtextxy(w / 2 - 150, 100, "LIMBA");
- else if (limba == 1)
- outtextxy(w / 2 - 150, 100, "LANGUAGE");
- else if (limba == 2)
- outtextxy(w / 2 - 150, 100, "LANGUE");
- readimagefile("romania_0012.JPG", w / 2 - 350, h / 2 - 50, w / 2 - 200, h / 2 + 50);
- readimagefile("Flag_of_the_United_Kingdom.JPG", w / 2 - 100, h / 2 - 50, w / 2 + 50, h / 2 + 50);
- readimagefile("64619037drapeau-reunion-png.JPG", w / 2 + 150, h / 2 - 50, w / 2 + 300, h / 2 + 50);
- butonIntermediarInapoi(h);
- int ok = 0, x, y;
- while (ok == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, x, y);
- if (getpixel(x, y) == LIGHTGREEN || getpixel(x, y) == GREEN)
- {
- ok = 1;
- optiuni();
- }
- else if (x > w / 2 - 350 && x< w / 2 - 200 && y>h / 2 - 50 && y < h / 2 + 50)
- {
- ok = 1;
- limba = RO;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- else if (x > w / 2 - 100 && x<w / 2 + 50 && y>h / 2 - 50 && y < h / 2 + 50)
- {
- ok = 1;
- limba = EN;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- else if (x > w / 2 + 150 && x<w / 2 + 300 && y>h / 2 - 50 && y < h / 2 + 50)
- {
- ok = 1;
- limba = FR;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- }
- }
- void scrie()
- {
- infix[256] = { 0 };
- char tasta;
- int k = 0;
- do
- {
- tasta = getch();
- if (tasta == 8) /// tasta == backspace
- {
- infix[strlen(infix) - 1] = NULL;
- bar(w / 2 - 500, h / 2 - 50, w / 2 + 500, h / 2 + 50);
- k--;
- }
- else infix[k++] = tasta;
- setcolor(BLACK);
- setbkcolor(WHITE);
- settextstyle(SIMPLEX_FONT, HORIZ_DIR, 3);
- settextjustify(CENTER_TEXT, CENTER_TEXT);
- outtextxy(w / 2, h / 2, infix);
- } while (tasta != 27);
- /// tasta != ESC
- }
- void optiuni()
- {
- schimbaPagOptiuni();
- settextstyle(4, HORIZ_DIR, 7);
- if (limba == 0)
- outtextxy(w / 2 - 200, 100, "OPTIUNI");
- else if (limba == 1)
- outtextxy(w / 2 - 200, 100, "OPTIONS");
- else if (limba == 2)
- outtextxy(w / 2 - 200, 100, "OPTIONS");
- settextstyle(6, 0, 4);
- setbkcolor(COLOR(0, 0, 1));
- setcolor(COLOR(255, 255, 255));
- if (limba == 0)
- {
- outtextxy(250, 250, "CULORI");
- setbkcolor(COLOR(0, 0, 0));
- setcolor(WHITE);
- outtextxy(300, 350, "CULOARE NOD:");
- setfillstyle(SOLID_FILL, culoare1);
- fillellipse(800, 360, 30, 30);
- outtextxy(300, 450, "CULOARE SCRIS:");
- setfillstyle(SOLID_FILL, culoare2);
- fillellipse(800, 460, 30, 30);
- setbkcolor(COLOR(0, 1, 0));
- setcolor(COLOR(255, 254, 255));
- outtextxy(250, 550, "LIMBA");
- }
- else if (limba == 1)
- {
- outtextxy(250, 250, "COLORS");
- setbkcolor(COLOR(0, 0, 0));
- setcolor(WHITE);
- outtextxy(300, 350, "NODE COLOR:");
- setfillstyle(SOLID_FILL, culoare1);
- fillellipse(800, 360, 30, 30);
- outtextxy(300, 400, "WRITING COLOR:");
- setfillstyle(SOLID_FILL, culoare2);
- fillellipse(800, 460, 30, 30);
- setbkcolor(COLOR(0, 1, 0));
- setcolor(COLOR(255, 254, 255));
- outtextxy(250, 550, "LANGUAGE");
- }
- else if (limba == 2)
- {
- outtextxy(250, 250, "COULEURS");
- setbkcolor(COLOR(0, 0, 0));
- setcolor(WHITE);
- outtextxy(300, 350, "COULEUR DU NOEUD:");
- setfillstyle(SOLID_FILL, culoare1);
- fillellipse(800, 360, 30, 30);
- outtextxy(300, 400, "COULEUR D'ECRITURE:");
- setfillstyle(SOLID_FILL, culoare2);
- fillellipse(800, 460, 30, 30);
- setbkcolor(COLOR(0, 1, 0));
- setcolor(COLOR(255, 254, 255));
- outtextxy(250, 550, "LANGUE");
- }
- butonIntermediarInapoi(h);
- int ok = 0, x, y;
- while (ok == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, x, y);
- if (getpixel(x, y) == LIGHTGREEN || getpixel(x, y) == GREEN)
- {
- ok = 1;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- else if (getpixel(x, y) == COLOR(0, 0, 1) || getpixel(x, y) == COLOR(255, 255, 255))
- {
- ok = 1;
- schimbaCulori(w, h);
- }
- else if (getpixel(x, y) == COLOR(0, 1, 0) || getpixel(x, y) == COLOR(255, 254, 255))
- {
- ok = 1;
- schimbalimba(w, h);
- }
- }
- }
- void arbore()
- {
- schimbaPagOptiuni();
- butonIntermediarAfisare(w, h);
- butonIntermediarInapoi(h);
- setcolor(LIGHTRED);
- setbkcolor(BLUE);
- if (limba == 0)
- outtextxy(100, 100, "LA FINAL APASATI ESC");
- else if (limba == 1)
- outtextxy(100, 100, "AT THE END PRESS ESC");
- else if (limba == 2)
- outtextxy(100, 100, "AU FINAL CLICK ESC");
- setcolor(WHITE);
- setbkcolor(WHITE);
- bar(w / 2 - 500, h / 2 - 50, w / 2 + 500, h / 2 + 50);
- scrie();
- int ok = 0;
- int x2, y2;
- while (ok == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, x2, y2);
- if (getpixel(x2, y2) == GREEN || getpixel(x2, y2) == LIGHTGREEN)
- {
- ok = 1;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- else if (getpixel(x2, y2) == RED || getpixel(x2, y2) == YELLOW)
- {
- ok = 1;
- schimbaPagOptiuni();
- setbkcolor(WHITE);
- int dimensiune = 5;
- int r = 30;
- int x = w / 2;
- int ynou;
- int u[100];
- int y = h / nr_nivele;
- string valNod = "+";
- deseneazaNod(x, y, r, valNod, dimensiune);
- ynou = y + h / nr_nivele;
- ///la fiecare niv se incrementeaza y cu h impartit la nr de nivele pt ca s -a impartit ecranul intr0un nr de nivele
- int xs = x - x / 2;
- int xd = x + x / 2;
- line(x - r, y, xs, ynou - r);
- line(x + r, y, xd, ynou - r);
- for (i = 2; i <= nr_nivele; i++)
- {
- y = ynou;
- ynou = ynou + h / nr_nivele;
- int j = 1;
- int coordonataX = x / (pow(2, i - 1));
- while (j < i * i)
- {
- deseneazaNod(coordonataX, y, r, valNod, dimensiune);
- if (i != nr_nivele)
- {
- if (coordonataX < x / 2)
- {
- line(coordonataX - r, y, coordonataX - coordonataX / 2, ynou - r);
- line(coordonataX + r, y, coordonataX + coordonataX / 2, ynou - r);
- }
- else
- {
- line(coordonataX - r, y, coordonataX - x / (2 * pow(2, i - 1)), ynou - r);
- line(coordonataX + r, y, coordonataX + x / (2 * pow(2, i - 1)), ynou - r);
- }
- }
- coordonataX = coordonataX + 2 * x / pow(2, i - 1);
- j = j + 2;
- }
- }
- }
- }
- }
- void nivelNod()
- {
- schimbaPagOptiuni();
- butonIntermediarAfisare(w, h);
- butonIntermediarInapoi(h);
- setcolor(LIGHTRED);
- setbkcolor(BLUE);
- if (limba == 0)
- outtextxy(100, 100, "LA FINAL APASATI ESC");
- else if (limba == 1)
- outtextxy(100, 100, "AT THE END PRESS ESC");
- else if (limba == 2)
- outtextxy(100, 100, "AU FINAL CLICK ESC");
- setcolor(BLACK);
- setbkcolor(WHITE);
- bar(w / 2 - 500, h / 2 - 50, w / 2 + 500, h / 2 + 50);
- scrie();
- int ok = 0, x, y;
- while (ok == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, x, y);
- if (getpixel(x, y) == LIGHTGREEN || getpixel(x, y) == GREEN)
- {
- ok = 1;
- deschideNouaPagina(w, h);
- paginaPrincipala(w, h);
- }
- else if (getpixel(x, y) == RED || getpixel(x, y) == YELLOW)
- {
- ok = 1;
- schimbaPagOptiuni();
- setbkcolor(WHITE);
- infix_to_postfix();
- ///int rezultat=getLevel(root,infix);
- ///char s[100];
- /// itoa(rezultat,s,10);
- /// outtextxy(w/2,h/2,s);
- }
- }
- }
- void paginaPrincipala(int w, int h)
- {
- setcolor(COLOR(255, 3, 3));
- setbkcolor(COLOR(255, 238, 3));
- settextstyle(1, HORIZ_DIR, 28);
- if (limba == 0)
- outtextxy(w / 2 - 400, h / 2 - 300, "ARBORELE ECUATIEI");
- else if (limba == 1)
- outtextxy(w / 2 - 240, h / 2 - 300, "BINARY TREE");
- else if (limba == 2)
- outtextxy(w / 2 - 300, h / 2 - 300, "ARBRE BINAIRE");
- setcolor(COLOR(254, 3, 3));
- setbkcolor(COLOR(254, 238, 3));
- settextstyle(1, HORIZ_DIR, 28);
- if (limba == 0)
- outtextxy(w / 2 - 350, h / 2, "NIVELUL NODULUI");
- else if (limba == 1)
- outtextxy(w / 2 - 250, h / 2, "NODE LEVEL");
- else if (limba == 2)
- outtextxy(w / 2 - 350, h / 2, "NIVEAU DU NOEUD");
- setcolor(COLOR(255, 4, 3));
- setbkcolor(COLOR(255, 237, 3));
- settextstyle(1, HORIZ_DIR, 28);
- if (limba == 0)
- outtextxy(w / 2 - 150, h / 2 + 300, "OPTIUNI");
- else if (limba == 1)
- outtextxy(w / 2 - 150, h / 2 + 300, "OPTIONS");
- else if (limba == 2)
- outtextxy(w / 2 - 150, h / 2 + 300, "OPTIONS");
- int xx, yy;
- int okk = 0;
- while (okk == 0)
- {
- getmouseclick(WM_LBUTTONDOWN, xx, yy);
- if (getpixel(xx, yy) == COLOR(255, 3, 3) || getpixel(xx, yy) == COLOR(255, 238, 3))
- {
- okk = 1;
- arbore();
- }
- else if (getpixel(xx, yy) == COLOR(255, 237, 3) || getpixel(xx, yy) == COLOR(255, 4, 3))
- {
- okk = 1;
- optiuni();
- }
- else if (getpixel(xx, yy) == COLOR(254, 3, 3) || getpixel(xx, yy) == COLOR(254, 238, 3))
- {
- okk = 1;
- nivelNod();
- }
- }
- }
- int main()
- {
- initwindow(w, h);
- readimagefile("Capture.JPG", 0, 0, w, h);
- paginaPrincipala(w, h);
- long int value;
- top = -1;
- gets(infix);
- infix_to_postfix();
- value = eval_post();
- getch();
- closegraph();
- return 0;
- }
- void infix_to_postfix()
- {
- unsigned int i, p = 0;
- char next;
- char symbol;
- for (i = 0; i < strlen(infix); i++)
- {
- symbol = infix[i];
- if (!white_space(symbol))
- {
- switch (symbol)
- {
- case '(':
- push(symbol);
- break;
- case ')':
- while ((next = pop()) != '(')
- postfix[p++] = next;
- break;
- case '+':
- case '-':
- case '*':
- case '/':
- case '%':
- case '^':
- while (!isEmpty() && priority(stack[top]) >= priority(symbol))
- postfix[p++] = pop();
- push(symbol);
- break;
- default: /*if an operand comes*/
- postfix[p++] = symbol;
- }
- }
- }
- while (!isEmpty())
- postfix[p++] = pop();
- postfix[p] = '\0'; /*End postfix with'\0' to make it a string*/
- }/*End of infix_to_postfix()*/
- ///prioritatea operatorilor
- int priority(char symbol)
- {
- switch (symbol)
- {
- case '(':
- return 0;
- case '+':
- case '-':
- return 1;
- case '*':
- case '/':
- case '%':
- return 2;
- case '^':
- return 3;
- default:
- return 0;
- }
- }
- void push(long int symbol)
- {
- if (top > 100)
- {
- printf("Stack overflow\n");
- exit(1);
- }
- stack[++top] = symbol;
- }/*End of push()*/
- long int pop()
- {
- if (isEmpty())
- {
- printf("Stack underflow\n");
- exit(1);
- }
- return (stack[top--]);
- }
- ///stivaVida
- int isEmpty()
- {
- if (top == -1)
- return 1;
- else
- return 0;
- }
- int white_space(char symbol)
- {
- if (symbol == BLANK || symbol == TAB)
- return 1;
- else
- return 0;
- }///daca e spatiu
- long int eval_post()
- {
- long int a, b, temp, result;
- unsigned int i;
- for (i = 0; i < strlen(postfix); i++)
- {
- if (postfix[i] <= '9' && postfix[i] >= '0')
- push(postfix[i] - '0');
- else
- {
- a = pop();
- b = pop();
- switch (postfix[i])
- {
- case '+':
- temp = b + a; break;
- case '-':
- temp = b - a; break;
- case '*':
- temp = b * a; break;
- case '/':
- temp = b / a; break;
- case '%':
- temp = b % a; break;
- case '^':
- temp = pow(b, a);
- }
- push(temp);
- }
- }
- result = pop();
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement