Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Programming II

Similar presentations


Presentation on theme: "Computer Programming II"— Presentation transcript:

1 Computer Programming II
Lecture 3

2 Data Structures: Definition: A data structure is a group of data elements grouped together under one name. These data elements, known as members, can have different types and different lengths.

3 Data Structures: Data structures can be declared in C++ using the following syntax: struct structure_name { data_type1 member_name1; data_type2 member_name2; data_type3 member_name3; . . } ;

4 Data Structures: For example: struct product { int weight; double price; } ;

5 Data Structures: Initializing a Structure: for example, the following date structure has been declared: struct date { int day, month, year; }; A date variable can now be defined and initialized by following the variable name with the assignment operator and an initialization list, as shown here: date birthday = {23, 8, 1983};

6 Data Structures: Declaring Structure Variables: There are two ways to declare variables of structures: 1- Declaring Structure Variables at Definition: Syntax: struct type_name { data_type1 member_name1; data_type2 member_name2; . . } variable_name ; For example: struct product { int weight; double price; } apple, banana, melon ;

7 Data Structures: 2- Declaring Structure Variables After Definition: Synatx: structure_name variable_name; For example: struct product { int weight; double price; } ; product apple; product banana , melon;

8 Data Structures: Accessing Structure Members: To access any member of a structure, we use the member access operator (.). The member access operator is coded between the structure variable name and the structure member that we wish to access. For example: apple.weight apple.price banana.weight banana.price melon.weight melon.price

9 Data Structures: - Write a program that used to print the student data (Using structure). Note : The first student : Name: Sarah Age: 19 The second student : Name: Maha Age: 20 The third student : Name: Nuha Age: 22

10

11 Data Structures: - Write a program that used to read the student data for three students which are (student_number , student_name and student_tel) and print it .(Using structure).

12

13

14 Structure and array: - Write a program to enter the addresses of five customers where the address includes (customer number, customer name and city).

15 Structure and array:

16 Structure and function:
- Write a program to read the student data for two students and print it. (Using structure and function) Note : Student data includes(student number , student name and the department)

17 Structure and function:

18 Structure and function:


Download ppt "Computer Programming II"

Similar presentations


Ads by Google