#include<constream.h> #include<graphics.h> #include<process.h> class DSAA{ public:char Ch; //////////////////////////W I N D O W M E T H O D ////////////////////////// void WINDOW(int x1,int y1, int x2, int y2,char TITLE[]) { setcolor(LIGHTBLUE); setfillstyle(SOLID_FILL,LIGHTBLUE); rectangle(x1,y1,x2,y2); floodfill(x1+1,y1+1,LIGHTBLUE); setcolor(LIGHTGRAY); setfillstyle(SOLID_FILL,LIGHTGRAY); rectangle(x1,y1,x2,y2); floodfill(x1+1,y1+1,LIGHTGRAY); setcolor(BLUE); setfillstyle(SOLID_FILL,BLUE); rectangle(x1+2,y1+2,x2-2,y1+20); floodfill(x1+3,y1+3,BLUE); setcolor(WHITE); line(x1,y1,x2,y1);line(x1,y1+1,x2-2,y1+1); line(x1,y1,x1,y2-1);line(x1+1,y1,x1+1,y2-2); setcolor(DARKGRAY); line(x2-1,y1+1,x2-1,y2-1);line(x2-1,y2-1,x1+2,y2-1); setcolor(BLACK); line(x2,y1,x2,y2);line(x2,y2,x1,y2); setcolor(WHITE); settextstyle(2,0,5); outtextxy(x1+7,y1+2,TITLE); setcolor(BLACK); settextstyle(2,0,4); outtextxy(x1+15,y1+30,"Arrays"); line(x1+15,y1+43,x1+20,y1+43); outtextxy(x1+70,y1+30,"Sorting"); line(x1+75,y1+43,x1+79,y1+43); outtextxy(x1+125,y1+30,"Search"); line(x1+130,y1+43,x1+134,y1+43); outtextxy(x1+175,y1+30,"Stacks"); line(x1+175,y1+43,x1+179,y1+43); outtextxy(x1+225,y1+30,"Queues"); line(x1+225,y1+43,x1+229,y1+43); outtextxy(x1+275,y1+30,"Recursion"); line(x1+275,y1+43,x1+279,y1+43); outtextxy(x1+560,y1+30,"Exit"); line(x1+566,y1+43,x1+570,y1+43); } ////////////////////////// M E N U /////////////////////////////////// void Menu(int x1,int y1,int x2,int y2) { setcolor(LIGHTGRAY);setfillstyle(SOLID_FILL,LIGHTGRAY); rectangle(x1,y1,x2,y2);floodfill(x1+1,y1+1,LIGHTGRAY); setcolor(WHITE); line(x1+1,y1+1,x2-1,y1+1);line(x1+1,y1+1,x1+1,y2-1); setcolor(BLACK);line(x2,y1,x2,y2);line(x2,y2,x1,y2); setcolor(DARKGRAY);line(x2-1,y1+1,x2-1,y2-1);line(x2-1,y2-1,x1+1,y2-1); setcolor(WHITE);line(x1,y1,x2-1,y1);line(x1,y1,x1,y2-1); } void Hide_Menu(int x1,int y1,int x2,int y2) { setcolor(LIGHTBLUE);setfillstyle(SOLID_FILL,LIGHTBLUE); rectangle(x1,y1,x2,y2);floodfill(x1+1,y1+1,LIGHTBLUE); setcolor(LIGHTGRAY);setfillstyle(SOLID_FILL,LIGHTGRAY); rectangle(x1-1,y1-1,x2+1,y2+1);floodfill(x1,y1,LIGHTGRAY); } //////////////////////S E L E C T M E N U I T E M ////////////////////// void SelectMenuItem(int x1,int y1,int x2,int y2) { setcolor(WHITE); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(BLACK); line(x2,y1,x2,y2); line(x2,y2,x1,y2); } ///////////////////////P U S H M E N U I T E M /////////////////////// void PushMenuItem(int x1,int y1,int x2,int y2) { setcolor(BLACK); line(x1,y1,x2,y1); line(x1,y1,x1,y2); setcolor(WHITE); line(x2,y1,x2,y2); line(x2,y2,x1,y2); } ///////////////////H I D E M E N U I T E M void HideMenuItem(int x1,int y1,int x2,int y2) { setcolor(LIGHTGRAY); line(x1,y1,x2,y1); line(x1,y1,x1,y2); line(x2,y1,x2,y2); line(x2,y2,x1,y2); } ///////////////////S E L E C T I O N O F M E N U I T E M S\\\\\\\\\\\ void Select_Array() { SelectMenuItem(26,48,75,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Array();Choice_Array();getch();} else if (Ch=='x' || Ch=='X'|| Ch==75) Select_Exit(); else if (Ch=='o' || Ch=='O'|| Ch==77) Select_Sorting(); else if (Ch=='e' || Ch=='E') Select_Search(); else if (Ch=='s' || Ch=='S') Select_Stacks(); else if (Ch=='q' || Ch=='Q') Select_Queues(); else if (Ch=='r' || Ch=='R') Select_Recursion(); else Select_Array(); } void Select_Sorting() { SelectMenuItem(82,48,136,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Sorting();Choice_Sorting();getch();} else if (Ch=='a' || Ch=='A'|| Ch==75) Select_Array(); else if (Ch=='e' || Ch=='E'|| Ch==77) Select_Search(); else if (Ch=='x' || Ch=='X') Select_Exit(); else if (Ch=='s' || Ch=='S') Select_Stacks(); else if (Ch=='q' || Ch=='Q') Select_Queues(); else if (Ch=='r' || Ch=='R') Select_Recursion(); else Select_Sorting(); } void Select_Search() { SelectMenuItem(138,48,188,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Search();Choice_Search();getch();} else if (Ch=='o' || Ch=='O'|| Ch==75) Select_Sorting(); else if (Ch=='s' || Ch=='S'|| Ch==77) Select_Stacks(); else if (Ch=='a' || Ch=='A') Select_Array(); else if (Ch=='q' || Ch=='Q') Select_Queues(); else if (Ch=='r' || Ch=='R') Select_Recursion(); else if (Ch=='x' || Ch=='X') Select_Exit(); else Select_Search(); } void Select_Stacks() { SelectMenuItem(190,48,236,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Stacks();Choice_Stacks();getch();} else if (Ch=='e' || Ch=='E'|| Ch==75) Select_Search(); else if (Ch=='q' || Ch=='Q'|| Ch==77) Select_Queues(); else if (Ch=='o' || Ch=='O') Select_Sorting(); else if (Ch=='a' || Ch=='A') Select_Array(); else if (Ch=='r' || Ch=='R') Select_Recursion(); else if (Ch=='x' || Ch=='X') Select_Exit(); else Select_Stacks(); } void Select_Queues() { SelectMenuItem(238,48,288,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Queues();Choice_Queues();getch();} else if (Ch=='s' || Ch=='S'|| Ch==75) Select_Stacks(); else if (Ch=='r' || Ch=='R'|| Ch==77) Select_Recursion(); else if (Ch=='e' || Ch=='E') Select_Search(); else if (Ch=='o' || Ch=='O') Select_Sorting(); else if (Ch=='a' || Ch=='A') Select_Array(); else if (Ch=='x' || Ch=='X') Select_Exit(); else Select_Queues(); } void Select_Recursion() { SelectMenuItem(290,48,355,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Recursion();Choice_Recursion();getch();} else if (Ch=='q' || Ch=='Q'|| Ch==75) Select_Queues(); else if (Ch=='x' || Ch=='X'|| Ch==77) Select_Exit(); else if (Ch=='s' || Ch=='S') Select_Stacks(); else if (Ch=='e' || Ch=='E') Select_Search(); else if (Ch=='o' || Ch=='O') Select_Sorting(); else if (Ch=='a' || Ch=='A') Select_Array(); else Select_Recursion(); } void Select_Exit() { SelectMenuItem(570,48,610,66); Ch=getch(); Hide_All(); if (Ch=='\r' || Ch==32) {Push_Exit();Choice_Exit();getch();} else if (Ch=='r' || Ch=='R'|| Ch==75) Select_Recursion(); else if (Ch=='a' || Ch=='A'|| Ch==77) Select_Array(); else if (Ch=='q' || Ch=='Q') Select_Queues(); else if (Ch=='s' || Ch=='S') Select_Stacks(); else if (Ch=='e' || Ch=='E') Select_Search(); else if (Ch=='o' || Ch=='O') Select_Sorting(); else Select_Exit(); } /////////////////P U S H I N G M E N U I T E M S \\\\\\\\\\\\\\\\\\\\\\ void Push_Array() { PushMenuItem(26,48,75,66);///Array } void Push_Sorting() { PushMenuItem(82,48,136,66);///Sorting } void Push_Search() { PushMenuItem(138,48,188,66);///Searching } void Push_Stacks() { PushMenuItem(190,48,236,66);///Stacks } void Push_Queues() { PushMenuItem(238,48,288,66);///Queues } void Push_Recursion() { PushMenuItem(290,48,355,66);///Recursion } void Push_Exit() { PushMenuItem(570,48,610,66);///Exit } //////////U N S E L E C T I N G A L L M E N U I T E M S \\\\\\\\\ void Hide_All() { HideMenuItem(26,48,75,66);///Array HideMenuItem(82,48,136,66);///Sorting HideMenuItem(138,48,188,66);///Searching HideMenuItem(190,48,236,66);///Stacks HideMenuItem(238,48,288,66);///Queues HideMenuItem(290,48,355,66);///Recursion HideMenuItem(570,48,610,66);///Exit } //////////////M E N U S OF A L L I T E M S ///////////////////////// void Menu_Array() { Menu(25,68,150,225); setcolor(BLACK);settextstyle(2,0,4); outtextxy(40,75,"Insertion"); outtextxy(40,115,"Deletion"); outtextxy(40,155,"Indexing"); outtextxy(40,195,"Replacement"); } void Menu_Sorting() { Menu(80,68,205,175); setcolor(BLACK);settextstyle(2,0,4); outtextxy(95,75, "Bubble Sort"); outtextxy(95,115,"Insertion Sort"); outtextxy(95,155,"Selection Sort"); } void Menu_Search() { Menu(140,68,265,135); setcolor(BLACK);settextstyle(2,0,4); outtextxy(155,75, "Linear Search"); outtextxy(155,115, "Binary Search"); } void Menu_Stacks() { Menu(190,68,315,175); setcolor(BLACK);settextstyle(2,0,4); outtextxy(205,75,"Push"); outtextxy(205,115,"Pop"); outtextxy(205,155,"Show"); } void Menu_Queues() { Menu(240,68,365,175); setcolor(BLACK);settextstyle(2,0,4); outtextxy(255,75,"Insert"); outtextxy(255,115,"Remove"); outtextxy(255,155,"Show"); } void Menu_Recursion() { Menu(290,68,415,175); setcolor(BLACK);settextstyle(2,0,4); outtextxy(305,75,"Fabonnaci Series"); outtextxy(305,115,"Triangular Series"); outtextxy(305,155,"Factorial"); } void Menu_Exit() { Menu(485,68,610,150); setcolor(BLACK); settextstyle(2,0,4);outtextxy(520,80,"Yes"); settextstyle(2,0,4);outtextxy(520,125,"NO"); } void Choice_Array() { Menu_Array();Ch=getch(); if(Ch==80) goto INS; else if (Ch==27){Hide_All();Hide_Menu_Array();Choice();} else if (Ch==72)goto REPLACE; else Choice_Array(); INS: setcolor(WHITE);settextstyle(2,0,4);outtextxy(40,75,"Insertion"); Ch=getch();Menu_Array(); if (Ch==80)goto DEL; else if (Ch==72)goto REPLACE; if (Ch==27){Hide_All();Hide_Menu_Array();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\insarr.exe",NULL);} else goto INS; DEL: setcolor(WHITE);settextstyle(2,0,4);outtextxy(40,115,"Deletion"); Ch=getch();Menu_Array(); if (Ch==27){Hide_All();Hide_Menu_Array();Choice();} if (Ch==80)goto INDEX; if (Ch==72)goto INS; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\delarr.exe",NULL);} else goto DEL; INDEX: setcolor(WHITE);settextstyle(2,0,4);outtextxy(40,155,"Indexing"); Ch=getch();Menu_Array(); if (Ch==27){Hide_All();Hide_Menu_Array();Choice();} if (Ch==80)goto REPLACE; if (Ch==72)goto DEL; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\indexing.exe",NULL);} else goto INDEX; REPLACE: setcolor(WHITE);settextstyle(2,0,4);outtextxy(40,195,"Replacement"); Ch=getch();Menu_Array(); if (Ch==27){Hide_All();Hide_Menu_Array();Choice();} if (Ch==80)goto INS; if (Ch==72)goto INDEX; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\replace.exe",NULL);} else goto REPLACE; } void Choice_Sorting() { Menu_Sorting();Ch=getch(); if(Ch==80) goto BUBBLE; else if (Ch==27){Hide_All();Hide_Menu_Sorting();Choice();} else if (Ch==72)goto SELECT; else Choice_Sorting(); BUBBLE: setcolor(WHITE);settextstyle(2,0,4);outtextxy(95,75,"Bubble Sort"); Ch=getch();Menu_Sorting(); if (Ch==80)goto INSERT; else if (Ch==72)goto SELECT; if (Ch==27){Hide_All();Hide_Menu_Sorting();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\bublsort.exe",NULL);} else goto BUBBLE; INSERT: setcolor(WHITE);settextstyle(2,0,4);outtextxy(95,115,"Insertion Sort"); Ch=getch();Menu_Sorting(); if (Ch==27){Hide_All();Hide_Menu_Sorting();Choice();} if (Ch==80)goto SELECT; if (Ch==72)goto BUBBLE; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\insort.exe",NULL);} else goto INSERT; SELECT: setcolor(WHITE);settextstyle(2,0,4);outtextxy(95,155,"Selection Sort"); Ch=getch();Menu_Sorting(); if (Ch==27){Hide_All();Hide_Menu_Sorting();Choice();} if (Ch==80)goto BUBBLE; if (Ch==72)goto INSERT; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\slctsort.exe",NULL);} else goto SELECT; } void Choice_Search() { Menu_Search();Ch=getch(); if(Ch==80) goto LINEAR; else if (Ch==27){Hide_All();Hide_Menu_Search();Choice();} else if (Ch==72)goto BINARY; else Choice_Search(); LINEAR: setcolor(WHITE);settextstyle(2,0,4);outtextxy(155,75,"Linear Search"); Ch=getch();Menu_Search(); if (Ch==80)goto BINARY; else if (Ch==72)goto BINARY; if (Ch==27){Hide_All();Hide_Menu_Search();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\lsearch.exe",NULL);} else goto LINEAR; BINARY: setcolor(WHITE);settextstyle(2,0,4);outtextxy(155,115,"Binary Search"); Ch=getch();Menu_Search(); if (Ch==27){Hide_All();Hide_Menu_Search();Choice();} if (Ch==80)goto LINEAR; if (Ch==72)goto LINEAR; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\bsearch.exe",NULL);} else goto BINARY; } void Choice_Stacks() { Menu_Stacks();Ch=getch(); if(Ch==80) goto PUSH; else if (Ch==27){Hide_All();Hide_Menu_Stacks();Choice();} else if (Ch==72)goto SHOW; else Choice_Stacks(); PUSH: setcolor(WHITE);settextstyle(2,0,4);outtextxy(205,75,"Push"); Ch=getch();Menu_Stacks(); if (Ch==80)goto POP; else if (Ch==72)goto SHOW; if (Ch==27){Hide_All();Hide_Menu_Stacks();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\stack.exe",NULL);} else goto PUSH; POP: setcolor(WHITE);settextstyle(2,0,4);outtextxy(205,115,"Pop"); Ch=getch();Menu_Stacks(); if (Ch==27){Hide_All();Hide_Menu_Stacks();Choice();} if (Ch==80)goto SHOW; if (Ch==72)goto PUSH; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\stack.exe",NULL);} else goto POP; SHOW: setcolor(WHITE);settextstyle(2,0,4);outtextxy(205,155,"Show"); Ch=getch();Menu_Stacks(); if (Ch==27){Hide_All();Hide_Menu_Stacks();Choice();} if (Ch==80)goto PUSH; if (Ch==72)goto POP; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\stack.exe",NULL);} else goto SHOW; } void Choice_Queues() { Menu_Queues();Ch=getch(); if(Ch==80) goto IN; else if (Ch==27){Hide_All();Hide_Menu_Queues();Choice();} else if (Ch==72)goto SH; else Choice_Queues(); IN: setcolor(WHITE);settextstyle(2,0,4);outtextxy(255,75,"Insert"); Ch=getch();Menu_Queues(); if (Ch==80)goto RE; else if (Ch==72)goto SH; if (Ch==27){Hide_All();Hide_Menu_Queues();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\queue.exe",NULL);} else goto IN; RE: setcolor(WHITE);settextstyle(2,0,4);outtextxy(255,115,"Remove"); Ch=getch();Menu_Queues(); if (Ch==27){Hide_All();Hide_Menu_Queues();Choice();} if (Ch==80)goto SH; if (Ch==72)goto IN; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\queue.exe",NULL);} else goto RE; SH: setcolor(WHITE);settextstyle(2,0,4);outtextxy(255,155,"Show"); Ch=getch();Menu_Queues(); if (Ch==27){Hide_All();Hide_Menu_Queues();Choice();} if (Ch==80)goto IN; if (Ch==72)goto RE; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\queue.exe",NULL);} else goto SH; } void Choice_Recursion() { Menu_Recursion();Ch=getch(); if(Ch==80) goto FABO; else if (Ch==27){Hide_All();Hide_Menu_Recursion();Choice();} else if (Ch==72)goto FACT; else Choice_Recursion(); FABO: setcolor(WHITE);settextstyle(2,0,4);outtextxy(305,75,"Fabonnaci Series"); Ch=getch();Menu_Recursion(); if (Ch==80)goto TRI; else if (Ch==72)goto FACT; if (Ch==27){Hide_All();Hide_Menu_Recursion();Choice();} else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\fabo.exe",NULL);} else goto FABO; TRI: setcolor(WHITE);settextstyle(2,0,4);outtextxy(305,115,"Triangular Series"); Ch=getch();Menu_Recursion(); if (Ch==27){Hide_All();Hide_Menu_Recursion();Choice();} if (Ch==80)goto FACT; if (Ch==72)goto FABO; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("d:\\language\\tc\\bin\\rasheed\\dsaa_prj\\triangl.exe",NULL);} else goto TRI; FACT: setcolor(WHITE);settextstyle(2,0,4);outtextxy(305,155,"Factorial"); Ch=getch();Menu_Recursion(); if (Ch==27){Hide_All();Hide_Menu_Recursion();Choice();} if (Ch==80)goto FABO; if (Ch==72)goto TRI; else if (Ch=='\r' || Ch==32) { closegraph(); execlp("c:\\tc\\bin\\factor.exe",NULL);} else goto FACT; } void Choice_Exit() { Menu_Exit(); Ch=getch(); if (Ch==27){Hide_All();Hide_Menu_Exit();Choice();} else if (Ch==80) goto YES; else if (Ch==72) goto NO; else Choice_Exit(); YES: setcolor(WHITE); settextstyle(2,0,4);outtextxy(520,80,"Yes"); Ch=getch(); Menu_Exit(); if(Ch=='\r' || Ch==32)exit(0); else if (Ch==27){Hide_All();Hide_Menu_Exit();Choice();} else if (Ch==72 || Ch==80)goto NO; else goto YES; NO: setcolor(WHITE);settextstyle(2,0,4);outtextxy(520,125,"NO"); Ch=getch(); Menu_Exit(); if (Ch=='\r'|| Ch==32) {Hide_All();Hide_Menu_Exit();Choice();} else if (Ch==72 || Ch==80)goto YES; else if (Ch==27){Hide_All();Hide_Menu_Exit();Choice();} else goto NO; } ///////////////////H I D E M E N U S ////////////////////////// void Hide_Menu_Array() { Hide_Menu(25,68,150,225);} void Hide_Menu_Sorting() { Hide_Menu(80,68,205,175);} void Hide_Menu_Search() { Hide_Menu(140,68,265,135);} void Hide_Menu_Stacks() { Hide_Menu(190,68,315,175);} void Hide_Menu_Queues() { Hide_Menu(240,68,365,175);} void Hide_Menu_Recursion() { Hide_Menu(290,68,415,175);} void Hide_Menu_Exit() { Hide_Menu(485,68,610,150);} /////////////////////C H O I C E O F M E N U I T E M S //////////////// void Choice() { Ch=getch(); if (Ch=='a' || Ch=='A'|| Ch==77) Select_Array(); else if (Ch=='x' || Ch=='X'|| Ch==75) Select_Exit(); else if (Ch=='o' || Ch=='O') Select_Sorting(); else if (Ch=='e' || Ch=='E') Select_Search(); else if (Ch=='s' || Ch=='S') Select_Stacks(); else if (Ch=='q' || Ch=='Q') Select_Queues(); else if (Ch=='r' || Ch=='R') Select_Recursion(); else {Choice();} } }; /////////////////// M A I N M E T H O D /////////////////////// void main(void) { int gd=0,gm; initgraph(&gd,&gm,"\\tc\\bgi"); setbkcolor(BLACK); setcolor(LIGHTBLUE);setfillstyle(SOLID_FILL,LIGHTBLUE); floodfill(0,0,LIGHTBLUE); DSAA x; x.WINDOW(20,20,620,465,"Data Structure & Algorithm Analysis"); x.Choice(); }
C Program For Creating Complicated Menu's
January 04, 2015
By:
Bhanu Namikaze
Bhanu Namikaze
Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.
No comments:
Post a Comment