Programming in C++ thisAnimal 5000 2037581 name “ giant panda genus Ailuropoda species“ melanoluka” country"China .age 18 weight 234.6 health Good
6 thisAnimal 5000 .id 2037581 .name “giant panda” .genus “Ailuropoda” .species “melanoluka” .country “China” .age 18 .weight 234.6 .health Good
Programming in C++ anotherAnimal 6000 5281003 name llama genus “Lama .species"peruana country"Peru .age weight 278.5 health Excellent
7 anotherAnimal 6000 .id 5281003 .name “llama” .genus “Lama” .species “peruana” .country “Peru” .age 7 .weight 278.5 .health Excellent
Programming in C++ struct AnimalT'ype enum HealthType Poor, Fair, Good, Excellent) struct Animaltype // declares a struct data type M does not allocate memory long id string name 3 string genus 3 string species 3 struct members string country 3 int age float weight: Health Type health AnimalType thisAnimal; //declare variables of AnimalType AnimalType anotherAnimal; 8
8 struct AnimalType enum HealthType { Poor, Fair, Good, Excellent } ; struct AnimalType // declares a struct data type { // does not allocate memory long id ; string name ; string genus ; string species ; struct members string country ; int age ; float weight ; HealthType health ; } ; AnimalType thisAnimal ; // declare variables of AnimalType AnimalType anotherAnimal ;
Programming in C++ struct type Declaration SYNTAX struct TypeName /does not allocate memory Mem berlist } ∥ ends with a semicolon Mem berList SYNTAX Data Type Mem benAme; Data Type Mem benAme 9
9 struct type Declaration SYNTAX struct TypeName // does not allocate memory { MemberList } ; // ends with a semicolon MemberList SYNTAX DataType MemberName ; DataType MemberName ; . .
Programming in C++ struct type Declaration The struct declaration names a type and names the members of the struct Note that each member name is given a type Also, member names must be unique within a struct type y It does not allocate memory when you make a struct declaration None of the struct members are associated with memory until we declare a struct variable 10
10 struct type Declaration ➢ The struct declaration names a type and names the members of the struct. Note that each member name is given a type. Also,member names must be unique within a struct type. ➢ It does not allocate memory when you make a struct declaration. ➢ None of the struct members are associated with memory until we declare a struct variable