ช่วยดูโค้ดแล้วอธิบายว่าแต่ส่วนทำงานยังไง พอดีผมต้องพรีเซนต์อาจารย์ครับ(กรุณา)
//เป็นโค้ดโรงหนัง ในการจองหนังที่จะดู #include<iostream> #include<string> #include<fstream> using namespace std; void menu() { //Menu Movie Big C cout<<"***BIG C MOVIE MENU***\n"; cout<<" 1.Run Program\n"; cout<<" 2.Change Data Movies\n"; //Show enter 3 input store cout<<" 3.Exit\n"; cout<<" Please select: "; } void datas(const char *cinima); void datam(const char *cinima); void datal(const char *cinima); int main() { const char *chairs = "c:/chairs.txt"; //Declare constant chairs store c:\xxx const char *chairm = "c:/chairm.txt"; //Declare constant chairm store c:\xxx const char *chairl = "c:/chairl.txt"; //Declare constant chairm store c:\xxx const char *fp="c:/movie.txt"; const char *p; char ch,Clear; string word,buffer[30],moviename,therter[3000],therter1[20][20],name; int choice,select,row,com,r,c; do { system("cls"); menu(); cin>>choice; if(choice==1) { system("cls"); ifstream fin(fp,ios::in); if(!fin.is_open()) { cout<<"\nFile not found add movie in menu choice 2\n"; cout<<"Please enter .......\n"; cin>>ch; } if(fin.is_open()) { int i=0; while(!fin.eof()) { fin>>word; buffer[i]=word+"\n"; i++; } cout<<"1.Zone1 cinima: "<<buffer[0]; cout<<"2.Zone2 cinima: "<<buffer[1]; cout<<"3.Zone3 cinima: "<<buffer[2]<<endl; fin.close(); cout<<"Enter choice Cinema : "; cin>>select; if(select==1) { p=chairs; name="Zone1 cinima: "+buffer[0]; r=5; c=9; } if(select==2) { p=chairm; name="Zone2 cinima: "+buffer[1]; r=8; c=11; } if(select==3) { p=chairl; name="Zone3 cinima: "+buffer[2]; r=12; c=13; } ifstream fin(p,ios_base::in); int k=0; while(!fin.eof()) { fin>>word; therter[k]=word; k++; } int n=0; cout<<r<<" "<<c<<endl; for(int i=0;i<r;i++) { for(int j=0;j<c;j++) { therter1[i][j]=therter[n]; n++; } } do { system("cls"); cout<<"\t\t\t"<<name<<endl; cout<<" "; for(int i=1;i<c;i++) cout<<" "<<i; cout<<"\n\n"; for(int i=0;i<r;i+)+ { for(int j=0;j<c;j++) cout<<therter1[i][j]<<" "; cout<<"\n\n"; } cout<<" 1.Choose\n"; cout<<" 2.Remove\n"; cout<<" 3.Clear\n"; cout<<" 4.Exit menu\n"; cout<<"Select choice: "; cin>>ch; if(ch=='1') { cout<<"\tEnter Row: "; cin>>ch; cout<<"\tEnter Com: "; cin>>com; if(ch=='a')row=0; if(ch=='b')row=1; if(ch=='c')row=2; if(ch=='d')row=3; if(ch=='e')row=4; if(ch=='f')row=5; if(ch=='g')row=6; if(ch=='h')row=7; if(ch=='i')row=8; if(ch=='j')row=9; if(ch=='k')row=10; if(ch=='l')row=11; therter1[row][com]="X"; ofstream fout(p,ios::out); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) fout<<therter1[i][j]<<" "; fout<<"\n"; } fout.close(); } if(ch=='2') { cout<<"\tRemove\n"; cout<<"\tEnter Row: "; cin>>ch; cout<<"\tEnter Com: "; cin>>com; if(ch=='a')row=0; if(ch=='b')row=1; if(ch=='c')row=2; if(ch=='d')row=3; if(ch=='e')row=4; if(ch=='f')row=5; if(ch=='g')row=6; if(ch=='h')row=7; if(ch=='i')row=8; if(ch=='j')row=9; if(ch=='k')row=10; if(ch=='l')row=11; therter1[row][com]="-"; ofstream fout(p,ios::out); for(int i=0;i<r;i++) { for(int j=0;j<c;j++) fout<<therter1[i][j]<<" "; fout<<"\n"; } fout.close(); } if(ch=='3') { cout<<"Clear y/n: "; cin>>Clear; if(select==1) { switch(Clear) { case 'y':datas(chairs);return main(); }; } if(select==2) { switch(Clear) { case 'y':datam(chairm);return main(); }; } if(select==3) { switch(Clear) { case 'y':datal(chairl);return main(); }; } } } while(ch!='4'); } } if(choice==2) { system("cls"); ifstream open(fp,ios::in); if(!open.is_open()) { if(!open.is_open()) datas(chairs); if(!open.is_open()) datam(chairm); if(!open.is_open()) datal(chairl); ofstream write(fp,ios::out); for(int i=1;i<=3;i++) { cout<<"Enter movie"<<i<<" name: "; cin>>moviename; write<<moviename+"\n"; } } if(open.is_open()) { ifstream fin(fp,ios::in); int i=0; while(!fin.eof()) { fin>>word; buffer[i]=word+"\n"; i++; } for(int i=0;i<3;i++) cout<<i+1<<"."<<buffer[i]; fin.close(); cout<<"Chang movie select: "; cin>>select; cout<<"New movie"<<select<<" name: "; cin>>moviename; if(select==1)buffer[0]=moviename+"\n"; if(select==2)buffer[1]=moviename+"\n"; if(select==3)buffer[2]=moviename+"\n"; ofstream fout(fp,ios::out); for(int i=0;i<3;i++) { fout<<buffer[i]; } fout.close(); } } } while(choice!=3); return 0; } void datas(const char *cinima) { ofstream fout(cinima,ios::out); fout<<"A - - - - - - - -\n"; fout<<"B - - - - - - - -\n"; fout<<"C - - - - - - - -\n"; fout<<"D - - - - - - - -\n"; fout<<"E - - - - - - - -\n"; fout.close(); } void datam(const char *cinima) { ofstream fout(cinima,ios::out); fout<<"A - - - - - - - - - -\n"; fout<<"B - - - - - - - - - -\n"; fout<<"C - - - - - - - - - -\n"; fout<<"D - - - - - - - - - -\n"; fout<<"E - - - - - - - - - -\n"; fout<<"F - - - - - - - - - -\n"; fout<<"G - - - - - - - - - -\n"; fout<<"H - - - - - - - - - -\n"; fout.close(); } void datal(const char *cinima) { ofstream fout(cinima,ios::out); fout<<"A - - - - - - - - - - - -\n"; fout<<"B - - - - - - - - - - - -\n"; fout<<"C - - - - - - - - - - - -\n"; fout<<"D - - - - - - - - - - - -\n"; fout<<"E - - - - - - - - - - - -\n"; fout<<"F - - - - - - - - - - - -\n"; fout<<"G - - - - - - - - - - - -\n"; fout<<"H - - - - - - - - - - - -\n"; fout<<"I - - - - - - - - - - - -\n"; fout<<"J - - - - - - - - - - - -\n"; fout<<"K - - - - - - - - - - - -\n"; fout<<"L - - - - - - - - - - - -\n"; fout.close(); }
|