1 / 14

The evolution of Pokemon society

The evolution of Pokemon society. Structures. “Good Old Days” At first it was Pokemon and his variables. Name. Id. Gender. Dept. “Old Days” Then there were more Pokemons and their variables. Name_1. Id_1. Gender_1. Dept_1. Name_2. Id_2. Gender_2. Dept_2. “Old Days” And more….

mauve
Download Presentation

The evolution of Pokemon society

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. The evolution of Pokemon society Structures

  2. “Good Old Days”At first it was Pokemon and his variables Name Id Gender Dept

  3. “Old Days”Then there were more Pokemons and their variables Name_1 Id_1 Gender_1 Dept_1 Name_2 Id_2 Gender_2 Dept_2

  4. “Old Days”And more… Name_1 Id_1 Gender_1 Dept_1 Name_2 Id_2 Gender_2 Dept_2 Name_3 Id_3 Gender_3 Dept_3

  5. “Old Days”And more… Name_1 Id_1 Gender_1 Dept_1 Name_2 Id_2 Gender_2 Dept_2 Name_3 Id_3 Gender_3 Dept_3 Name_4 Id_4 Gender_4 Dept_4

  6. “Old Days”And more and more Name_m Id_m Gender_m Dept_m Name_1 Id_1 Gender_1 Dept_1 Name_2 Id_2 Gender_2 Dept_2 Name_3 Id_3 Gender_3 Dept_3 Name_4 Id_4 Gender_4 Dept_4 Name_n Id_n Gender_n Dept_n

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

  8. Name Id Gender Dept Name Id Gender Dept Name Id Gender Dept Name Id Gender Dept New World Order: An almost perfect world! Pokemon_n Pokemon_1 Pokemon_2 Pokemon_3

  9. struct examples • Example: struct Pokemon{ char Name[15]; int Id; char Dept[5]; char Gender; }; The “Pokemon” structure has 4 members.

  10. Name Id Gender Dept Name Id Gender Dept struct basics • Declaration of a variable of struct type: <struct-type> <identifier_list>; • Example: Pokemon Pokemon_1, Pokemon_2; Pokemon_1andPokemon_2are variables of Pokemon type. Pokemon_1 Pokemon_2

  11. Chan Tai Man 12345 M COMP Name Id Gender Dept Ex. 1: struct basics • The members of a struct type variable are accessed with the dot (.) operator: <struct-variable>.<member_name>; • 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

  12. Ex. 2: struct-to-struct assignment • The value of one struct type variable can be assigned to another variable of the same struct type. • 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 Chan Tai Man 12345 M COMP Pokemon_2

  13. Name Id Gender Dept Name Id Gender Dept Name Id Gender Dept Name Id Gender Dept New World Order: An almost perfect world! Pokemon[n] Pokemon[0] Pokemon[1] Pokemon[2]

  14. Ex. 2: struct-to-struct assignment • The value of one struct type variable can be assigned to another variable of the same struct type. • 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 Chan Tai Man 12345 M COMP Pokemon[2]

More Related