

















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















































1
2
4
5
.id 2037581 .name “giant panda” .genus “Ailuropoda” .species “melanoluka” .country “China” .age 18 .weight 234. .health Good
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; }; // Declare variables of AnimalType AnimalType thisAnimal; AnimalType anotherAnimal; 7 7
struct TypeName // Does not allocate memory { MemberList };
DataType MemberName; DataType MemberName; . . . 8
More about struct type declarations
10
11
13
14
void WriteOut( /* in */ AnimalType thisAnimal) // Prints out values of all members of thisAnimal // Precondition: all members of thisAnimal are assigned // Postcondition:all members have been written out { cout << “ID # “ << thisAnimal.id << thisAnimal.name << endl; cout << thisAnimal.genus << thisAnimal.species << endl; cout << thisAnimal.country << endl; cout << thisAnimal.age << “ years “ << endl; cout << thisAnimal.weight << “ lbs. “ << endl; cout << “General health : “; WriteWord (thisAnimal.health); } 16 Docsity.com
Passing a struct Type by Reference void ChangeAge(/* inout */ AnimalType& thisAnimal) // Adds 1 to age // Precondition: thisAnimal.age is assigned // Postcondition:thisAnimal.age == // thisAnimal.age@entry + 1 { thisAnimal.age++; } 17
19
20