1 / 12

Multidimensional Array:

Multidimensional Array:. อนันต์ ผลเพิ่ม Anan Phonphoem anan@cpe.ku.ac.th. Score[1]. 90. Score[2]. 75. Score[3]. 40. Score[4]. 67. Score[5]. 55. Score[6]. 30. One dimensional Array. Type ScoreArr = array [1..6] of integer ; var score: ScoreArr;. Election Score.

tamar
Télécharger la présentation

Multidimensional 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. Multidimensional Array: อนันต์ ผลเพิ่ม Anan Phonphoem anan@cpe.ku.ac.th

  2. Score[1] 90 Score[2] 75 Score[3] 40 Score[4] 67 Score[5] 55 Score[6] 30 One dimensional Array Type ScoreArr = array[1..6] of integer; var score: ScoreArr;

  3. Election Score Type ScoreArr = array[1..6] of integer; var Score: ScoreArr; Score Candidate # 1 90 2 75 3 40 4 67 5 55 6 30

  4. Election: 3 districts Type ScoreArr = array[1..6] of integer; var scoreD1, scoreD2, scoreD3: ScoreArr; Candidate # ScoreD1 ScoreD2 ScoreD3 1 90 10 34 2 75 5 78 3 40 60 9 4 67 72 22 5 55 12 66 6 30 44 3

  5. Score 1 90 10 34 2 75 5 78 3 40 60 9 4 67 72 22 5 55 12 66 6 30 44 3 2-dimensional array ScoreD1 ScoreD2 ScoreD3 90 10 34 75 5 78 40 60 9 67 72 22 55 12 66 44 3 30

  6. Candidate # District 2-dimensional array Score 1 2 3 1 90 10 34 2 75 5 78 3 40 60 9 4 67 72 22 5 55 12 66 6 30 44 3 Score[candidate, district] Score[1,1] = Score[4,2] = Score[5,3] =

  7. 2-dimensional array Score 1 2 3 1 90 10 34 2 75 5 78 3 40 60 9 4 67 72 22 5 55 12 66 6 30 44 3 Type Score2Arr = array[1..6,1..3] of integer; var Score: Score2Arr;

  8. Accessing Array elements • Score[1,1] = 10 • For I := 1 to 6 do Readln(Score[I,1]); • For candidate := 1 to 6 do For district := 1 to 3 do Readln(Score[candidate, district]); • For district := 1 to 3 do Writeln(Score[3,district]);

  9. Practice 1 • Write a program to find the winner of the election in each district • Write a program to find the winner of the election Score 1 2 3 1 90 10 34 2 75 5 78 3 40 60 9 4 67 72 22 5 55 12 66 6 30 44 3

  10. Practice 2 • Write a program to add two table + =

  11. Practice 3 • Write an O-X game (Tic-Tac-Toe)

  12. Movie Title: Men in Black II 1 2 3 1 2 3 1 X - - - - - 2 X X X - X X 3 - X - - X - 4 - - - X X X Midnight 8 PM 3-dimensional array Seat[round, row, col] Seat[Evening, 3, 1] = Available; Seat[Midnight, 2, 4] = Taken;

More Related