

















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
During the course of work of the programming, we learn the core of the programming. The main points disucss in these lecture slides are:Structured Types, Data Abstraction, Abstract Data Type, Separate Specification, Implementation Files, Member Functions in Client Code, Allocate Memory, Member Selection Operator, Aggregate Operation, Unions in C
Typology: Slides
1 / 57
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