1 / 23

ตะลุย โจทย์ Array

ตะลุย โจทย์ Array. Ex1. ประกาศตัวแปรอาร์เรย์. เก็บค่าลงทะเบียนของนักศึกษาในSection (มีนักศึกษา 80 คน) ……………………………………………………………………. เก็บค่าลงทะเบียนของนักศึกษา 4 Section ๆ ละ 80 คน ………………………………………………………………… เก็บเวลาที่โทรของลูกค้า AIS จำนวน 100 คน ………………………………………………………………..

scot
Download Presentation

ตะลุย โจทย์ Array

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ตะลุยโจทย์Array BC320 Introduction to Computer Programming

  2. Ex1. ประกาศตัวแปรอาร์เรย์ • เก็บค่าลงทะเบียนของนักศึกษาในSection (มีนักศึกษา 80 คน) ……………………………………………………………………. • เก็บค่าลงทะเบียนของนักศึกษา 4 Section ๆ ละ 80 คน ………………………………………………………………… • เก็บเวลาที่โทรของลูกค้า AIS จำนวน 100 คน ……………………………………………………………….. • เก็บเวลาที่โทรของลูกค้า AIS ,DTAC และ TRUE MOVE ลูกค้ามีจำนวนเครือข่ายละ 100 คน ……………………………………………...................….. int Cost[80] int Cost[4][80] int Time[100] int Time[3][100] BC320 Introduction to Computer Programming

  3. Ex2. จงเขียน Pseudo code เพื่อรับจำนวนหน่วยกิตของนักศึกษา 15 คน เก็บในอาร์เรย์ Credit แล้วคิดค่าลงทะเบียนของนักศึกษาแต่ละคนเก็บในอาร์เรย์ Money โดยคิดค่าลงทะเบียนหน่วยกิตละ 1200 บาท พร้อมทั้งแสดงผลค่าลงทะเบียนของนักศึกษาแต่ละคน Int Credit[15],Money[15] ประกาศตัวแปร .................................................................. Begin for(i=0;i<15;i++) read Credit[i] end for for(i=0;i<15;i++) Money[i]= Credit[i]*1200 end for for(i=0;i<15;i++) write Money[i] end for End BC320 Introduction to Computer Programming

  4. Begin for (i=0;i<5;i++) read Midterm[i] read Final[i] Total[i]=Midterm[i]+Final[i] write Total[i] end for End Begin i=0 while i<5 read Midterm[i] read Final[i] Total[i]=Midterm[i]+Final[i] write Total[i] i=i+1 end do End Ex3 จงแปลง Pseudo code ของคำสั่ง for ต่อไปนี้ ให้เป็นคำสั่ง while BC320 Introduction to Computer Programming

  5. Ex4. จงเขียน Pseudo Code เพื่อรับปี พ.ศ เกิดของนักศึกษา 8 คน เก็บในอาร์เรย์ Year ถ้านักศึกษาอายุไม่เกิน 20 ปี แสดงข้อความ “Young” ถ้านักศึกษาอายุมากกว่า 20 ปี แสดงข้อความ “Old” แล้วเก็บอายุของนักศึกษาแต่ละคนลงในอาร์เรย์ Age หาอายุต่ำสุดของนักศึกษาทั้ง 8 คน int Year[8],Age[8] ประกาศตัวแปร .................................................................. BC320 Introduction to Computer Programming

  6. Begin for(i=0;i<8;i++) read Year[i] end for for(i=0;i<8;i++) Age[i]=2549-Year[i] write Age[i] if Age[i]>20 then write “Old” else write “Young” end if end for Min=999 for(i=0;i<8;i++) if Min> Age[i] then Min=Age[i] end for Write Min End BC320 Introduction to Computer Programming

  7. Ex5. จากอาร์เรย์ต่อไปนี้ จงแสดงวิธีการค้นหาเลข 10 โดยใช้วิธีการค้นหา 2 วิธี Sequencial Search รอบที่ i=2 รอบที่ i=0 10=x[2] 10=10 หยุดการทำงาน เจอข้อมูลในตำแหน่งที่ 2 10>x[0] 10>3 ค้นหาต่อ รอบที่ i=1 10>x[1] 10>8 ค้นหาต่อ BC320 Introduction to Computer Programming

  8. Mid Last First First Mid Last Binary Search รอบที่ i=0 รอบที่ i=1 Mid=(0+6)/2 =3 Mid=(0+2)/2 =1 เปรียบเทียบค่า Search กับ X[3] 10<17  เลือกครึ่งแรก เปรียบเทียบค่า Search กับ X[1] 10>8  เลือกครึ่งหลัง BC320 Introduction to Computer Programming

  9. First Mid Last Binary Search(ต่อ) รอบที่ i=2 Mid=(2+2)/2 =2 เปรียบเทียบค่า Search กับ X[2] 10=10  เจอข้อมูล ในตำแหน่งช่องที่ 2 BC320 Introduction to Computer Programming

  10. Ex 6. จาก Ex4 เมื่อต้องการเปลี่ยนการเก็บข้อมูล โดยเก็บจากนักศึกษา ม.กรุงเทพ ,ม.ธรรมศาสตร์,ม.รังสิต,ม.สยาม อย่างละ 8 คน จะต้องเขียน Pseudo code อย่างไร /* ไม่ต้องหาค่า Min*/ Int Year[4][8],Age[4][8] ประกาศตัวแปร .................................................................. BC320 Introduction to Computer Programming

  11. Begin for(i=0;i<4;i++) for(j=0;j<8;j++) read Year[i][j] end for end for for(i=0;i<4;i++) for(j=0;j<8;j++) Age[i][j]=2549-Year[i][j] write Age[i][j] if Age[i][j]>20 then write “Old” else write “Young” end if end for end for End BC320 Introduction to Computer Programming

  12. Ex7. เรียงลำดับข้อมูลจากน้อยไปหามากของอาร์เรย์ต่อไปนี้ Selection sort รอบที่ i=0  8 13 2 16 7  8 13 2 16 7  8 13 2 16 7  2 13 8 16 7 BC320 Introduction to Computer Programming

  13. Selection sort(ต่อ) รอบที่ i=1    * BC320 Introduction to Computer Programming

  14. Selection sort(ต่อ) รอบที่ i=2   * * BC320 Introduction to Computer Programming

  15. Selection sort(ต่อ) รอบที่ i=3  * * * ผลลัพธ์ BC320 Introduction to Computer Programming

  16. Ex7. เรียงลำดับข้อมูลจากน้อยไปหามากของอาร์เรย์ต่อไปนี้ Bubble sort รอบที่ i=0 สลับ สลับ BC320 Introduction to Computer Programming

  17. Bubble sort(ต่อ) รอบที่ i=1 สลับ สลับ BC320 Introduction to Computer Programming

  18. Bubble sort(ต่อ) รอบที่ i = 2 สลับ BC320 Introduction to Computer Programming

  19. Bubble sort(ต่อ) รอบที่ i = 3 ผลลัพธ์ BC320 Introduction to Computer Programming

  20. ข้อแถม จงเขียน Pseudo code • วน loop รับคะแนนกลางภาคเก็บในอาร์เรย์ Midterm และรับคะแนนสอบปลายภาคเก็บในอาร์เรย์ Final ของ นศ.10 คน • วน loop เพื่อคิดหาคะแนนรวมเก็บในอาร์เรย์ Total โดยคะแนนรวมเกิดจากการเก็บคะแนน Miterm 40% และ Final 60% • คิดเกรดของนักศึกษาเก็บในอาร์เรย์ Grade โดยที่เกรดมี 3 เงื่อนไข ดังนี้ ถ้าได้คะแนนรวม 0-30 คะแนน ได้เกรด ‘U’ ถ้าได้คะแนนรวม 31-60 คะแนน ได้เกรด ‘P’ ถ้าได้คะแนนรวม 61 ขึ้นไป ได้เกรด ‘G’ • วน loop เพื่อแสดงผลคะแนนรวม และเกรดของนักศึกษาแต่ละคน BC320 Introduction to Computer Programming

  21. Begin for(i=0;i<10;i++) read Midterm[i],Final[i] end for for(i=0;i<10;i++) Total[i]= (Midterm[i]*40/100) +(Final[i]*60/100) if Total[i]<=30 then Grade[i]=‘U’ else if Total[i]<=60 then Grade[i]=‘P’ else Grade[i]=‘G’ end if end for for(i=0;i<10;i++) write Total[i],Grade[i] end for End BC320 Introduction to Computer Programming

  22. ประเมินผลการเรียนวิชานี้หรือยัง? http://assessment.bu.ac.th BC320 Introduction to Computer Programming

  23. EndofBC320 BC320 Introduction to Computer Programming

More Related