Presentation is loading. Please wait.

Presentation is loading. Please wait.

The evolution of Pokemon society Structures. COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables.

Similar presentations


Presentation on theme: "The evolution of Pokemon society Structures. COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables."— Presentation transcript:

1 The evolution of Pokemon society Structures

2 COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables NameIdGenderDept

3 COMP102 Prog. Fundamentals, Structures / Slide 3 “Old Days” Then there were more Pokemons and their variables Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2

4 COMP102 Prog. Fundamentals, Structures / Slide 4 “Old Days” And more… Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3

5 COMP102 Prog. Fundamentals, Structures / Slide 5 “Old Days” And more… Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3 Name_4Id_4Gender_4Dept_4

6 COMP102 Prog. Fundamentals, Structures / Slide 6 “Old Days” And more and more Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3 Name_4Id_4Gender_4Dept_4 Name_nId_nGender_nDept_n Name_mId_mGender_mDept_m

7 COMP102 Prog. Fundamentals, Structures / Slide 7 “What a mess! How can any Pokemon find his variables? We got to get organized!” Every Pokemon’s variable should stay together!

8 COMP102 Prog. Fundamentals, Structures / Slide 8 New World Order: An almost perfect world! Name IdGender Dept Pokemon_1 Name IdGender Dept Pokemon_2 Name IdGender Dept Pokemon_3 Name IdGender Dept Pokemon_n

9 COMP102 Prog. Fundamentals, Structures / Slide 9 struct examples l Example: struct Pokemon{ char Name[15]; int Id; char Dept[5]; char Gender; }; The “Pokemon” structure has 4 members.

10 COMP102 Prog. Fundamentals, Structures / Slide 10 struct basics l Declaration of a variable of struct type: ; l Example: Pokemon Pokemon_1, Pokemon_2; Pokemon_1 and Pokemon_2 are variables of Pokemon type. Pokemon_1Pokemon_2 Name IdGender Dept Name IdGender Dept

11 COMP102 Prog. Fundamentals, Structures / Slide 11 Chan Tai Man 12345 M COMP Ex. 1: struct basics l The members of a struct type variable are accessed with the dot (.) operator:. ; l Example: strcpy(Pokemon_1.Name, "Chan Tai Man"); Pokemon_1.Id = 12345; strcpy(Pokemon_1.Dept, "COMP"); Pokemon_1.gender = 'M'; cout << "The student is "; switch (Pokemon_1.gender){ case 'F': cout << "Ms. "; break; case 'M': cout << "Mr. "; break; } cout << Pokemon_1.Name << endl; Pokemon_1 Name IdGender Dept

12 COMP102 Prog. Fundamentals, Structures / Slide 12 Chan Tai Man 12345 M COMP Ex. 2: struct-to-struct assignment The value of one struct type variable can be assigned to another variable of the same struct type. l Example: strcpy(Pokemon_1.Name, "Chan Tai Man"); Pokemon_1.Id = 12345; strcpy(Pokemon_1.Dept, "COMP"); Pokemon_1.gender = 'M'; Pokemon_2 = Pokemon_1; Pokemon_1 Chan Tai Man 12345 M COMP Pokemon_2

13 COMP102 Prog. Fundamentals, Structures / Slide 13 New World Order: An almost perfect world! Name IdGender Dept Pokemon[0] Name IdGender Dept Pokemon[1] Name IdGender Dept Pokemon[2] Name IdGender Dept Pokemon[n]

14 COMP102 Prog. Fundamentals, Structures / Slide 14 Chan Tai Man 12345 M COMP Ex. 2: struct-to-struct assignment The value of one struct type variable can be assigned to another variable of the same struct type. l Example: strcpy(Pokemon[1].Name, "Chan Tai Man"); Pokemon[1].Id = 12345; strcpy(Pokemon[1].Dept, "COMP"); Pokemon[1].gender = 'M'; Pokemon[2] = Pokemon[1]; Pokemon[1] Chan Tai Man 12345 M COMP Pokemon[2]


Download ppt "The evolution of Pokemon society Structures. COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables."

Similar presentations


Ads by Google