งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

งานนำเสนอกำลังจะดาวน์โหลด โปรดรอ

LAB # 7 CASE SWITCH CONTINUE. 2 /*Program : base_num.cpp Process : display change base number of decimal,octal,hexadecimal*/ #include void main() { cout<<

งานนำเสนอที่คล้ายกัน


งานนำเสนอเรื่อง: "LAB # 7 CASE SWITCH CONTINUE. 2 /*Program : base_num.cpp Process : display change base number of decimal,octal,hexadecimal*/ #include void main() { cout<<"— ใบสำเนางานนำเสนอ:

1 LAB # 7 CASE SWITCH CONTINUE

2 2 /*Program : base_num.cpp Process : display change base number of decimal,octal,hexadecimal*/ #include void main() { cout<< "Display change base number..."<<endl<<endl; cout<< "10 decimal to hexadecimal = "<<hex<<10<<endl; cout<< "5865 decimal to hexadecimal = "<<hex<<5865<<endl; cout<< "1250 decimal to octal = "<<oct<<1250<<endl; cout<< "02342 octal to decimal = "<<dec<<02342<<endl; cout<< "0xabc125 hexadecimal to decimal = "<<dec<<0xabc125<<endl; cout<< "0xf hexadecimal to decimal = "<<dec<<0xf<<endl; } ให้นักศึกษา ศึกษาตัวอย่างการแปลงค่าเลขฐานต่างๆ และทำความเข้าใจ

3 3 /*Program : break.cpp Process : display using 'break' in for loop */ #include void main() { int x,row,sum; row=0;sum=0; for(x=1;x<=100;++x) //condition for 100 loop { cout<<"x="<<x<<'\n'; sum+=x; row++; if(row>23) //condition of break break; } cout<<"summation 1-"<<x<<" = "<<sum; } ให้นักศึกษา ศึกษาตัวอย่างการใช้คำสั่ง Break และทำความเข้าใจ

4 4 /*Program : continue.cpp Process : display keyword 'continue' in do...while loop */ #include void main() { float x,y; char choice; do{ cout<< "\nProgram Divide Calculation x/y"; cout<< "\n******************************"; cout >x; cout >y; if(y==0) { cout<< "\a\n\nCan't divide by zero !!!"; cout<< "\npress any key to continue..."; continue; } cout<< "\n*** Result "<<x<<"/"<<y<<" = "<<x/y; cout ? "; cin>>choice; }while((choice!='n')&&(choice!='N')); } ให้นักศึกษา ศึกษาตัวอย่างการใช้คำสั่ง Continue และ ทำความเข้าใจ

5 5 /*Program : switch.cpp Process : test statement switch...case */ #include void main() { int first,second; char choice; //begin statement cout<<"Program Calcurate Area\n"; cout<<"1. Circle\n"; cout<<"2. Square\n"; cout<<"3. Triangle\n"; cout : "; cin>>choice; //begin switch statement switch(choice) { case '1': cout<<"\nYou select choice "<<choice<< " calculate Circle Area\n"; cout<<"Press any key to end program\n"; break; case '2': cout<<"\nYou select choice "<<choice<< " calculate Square Area\n"; cout<<"Press any key to end program\n"; break; case '3': cout<<"\nYou select choice "<<choice<< " calculate Triangle Area\n"; cout<<"Press any key to end program\n"; break; default: cout<<"\nYou select Another choice \a\a\n"; cout<<"Press any key to end program\n"; } ให้นักศึกษา ศึกษาตัวอย่างการใช้คำสั่ง Switch และ ทำความเข้าใจ

6 6 จงเขียนโปรแกรมต่อไปนี้ โดยใช้คำสั่ง Switch และ CASE 1. โปรแกรมนี้เป็นโปรแกรมเมนูที่รับการคีย์อักขระจากคีย์บอร์ด กด L เมื่อผู้ใช้ต้องการ Load กด S เมื่อผู้ใช้ต้องการ Save กด E เมื่อผู้ใช้ต้องการ Edit กด P เมื่อผู้ใช้ต้องการ Print กด Q เมื่อผู้ใช้ต้องการ Quit หากผู้ใช้ไม่กดอักขระ Q โปรแกรมจะวนรอบให้ผู้ใช้ป้อนข้อมูล ไปเรื่อย Lab7-1.cpp 2. จงเขียนโปรแกรมเพื่อสร้างเมนูรายการร้านขายอาหารอิตาลี ซึ่งมี อาหาร 2 ชนิด คือ SPAGHETTI และ PASTA ให้เมนูมีตัวเลือก 3 อย่างได้แก่ 1. SPAGHETTI ราคา 60 บาท 2. PIZZA ราคา 120 บาท 3. PASTA ราคา 40 บาท 4. SOAUP ราคา 80 บาท 5. Quit โดยจะทำการวนซ้ำรับข้อมูลการซื้ออาหารของลูกค้าทีละรายเพื่อ คำนวณรายรับสะสมแล้วแสดงผลเมื่อปิดร้าน ( กด 5) Lab7-2.cpp


ดาวน์โหลด ppt LAB # 7 CASE SWITCH CONTINUE. 2 /*Program : base_num.cpp Process : display change base number of decimal,octal,hexadecimal*/ #include void main() { cout<<

งานนำเสนอที่คล้ายกัน


Ads by Google