បង្កើត Menu ក្នុង C++



#include<iostream.h>
#include<conio.h>
void main(){
 clrscr();
 int opt=0,y,max=10; // menu have 10 => max = 10;
 char *menu[10],ch;       // *menu use string
 menu[0]="  Add     ";
 menu[1]="  Insert  ";
 menu[2]="  Delete  ";
 menu[3]="  Update  ";
 menu[4]="  Sort    ";
 menu[5]="  Search  ";
 menu[6]="  Display ";
 menu[7]="  Sitting ";
 menu[8]="  About   ";
 menu[9]="  Exit    ";
 _setcursortype(_NOCURSOR);
 do{
 y=5;
 for(int i=0;i<max;i++){
if(opt==i){
textcolor(7); // 7 color white
textbackground(1);      // 1 color blue
}else{
textcolor(0);           // 0 color black
textbackground(6);      // 6 color orange
}
gotoxy(35,y++);
cprintf("%s",menu[i]);          // %s output string menu[i]
 }
 ch=getch();                            // 72 key up , 80 key down
 if(ch==72||ch==80){
if(ch==72)
if(opt==0)
opt=max-1;
else
opt--;
else
if(opt==max-1)
opt=0;
else
opt++;
 }
 }while(ch!=13);                        // 13 key enter
 textbackground(0);
 textcolor(7);
 clrscr();
 gotoxy(28,10);
 cout<<"You Selected : "<<menu[opt]; // use switch(opt){ case 0: ,to, case 9: }
 getch();
}





និស្សិត ផ្ដាច់សង្ខា

My Blogger TricksAll Blogger TricksTechtunes