9. Structures
•A member could be from a struct type .
struct Date{
int month;
int day;
int year;
} x,y ;
struct PersonInfo
{
double height;//in cm
int weight;//in kg
Date birthday;
};
10. Structures
•A member could be from a struct type .
struct Date{
int month;
int day;
int year;
} x,y ;
struct PersonInfo
{
double height;//in cm
int weight;//in kg
Date birthday;
};
You can define Like this or like this : Date x,y ;
11. Structures
•A member could be from a struct type .
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
Don’t forget comma !
12. Structures
struct structName{
……….members
……..
} its objects(if any) ;
…..
……
int main()
{
….
}
•This declaration must be Global , to be seen by all functions.
13. Structures
•It’s a type ! So it means :
struct Date{
int month;
int day;
int year;
}
void get(Date x, int count )
14. Structures
struct Date{
int month;
int day;
int year;
};
Date get (int z , int count )
•It’s a type ! So it means :
15. struct Date{
int month;
int day;
int year;
} x,y ;
struct PersonInfo
{
double height;//in cm
int weight;//in kg
Date birthday;
};
Structures
PersonInfo christoph ;
christoph.height=170;
christoph.weight=70;
christoph.birthday.month=10 ;
christoph.birthday.day=3 ;
christoph.birthday.year=1978 ;
•To reach to its members :
16. struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
Structures
PersonInfo christoph ;
christoph.height=170;
christoph.weight=70;
christoph.birthday.month=10 ;
christoph.birthday.day=3 ;
christoph.birthday.year=1978 ;
•To reach to its members :
17. Structures
•Initialize :
struct Date{
int month;
int day;
int year;
} x,y ;
struct PersonInfo
{
double height;//in cm
int weight;//in kg
Date birthday;
};
•Like Arrays
18. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
19. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
20. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
21. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
22. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
23. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
•month
•day
•year
24. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
•month
•day
•year
25. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
•month
•day
•year
26. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
•month
•day
•year
27. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
•Like Arrays
•Sequentially
•PersonInfo
•height
•weight
•birthday
•month
•day
•year
28. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70, 10,3,1978};
29. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70, 10,3,1978};
30. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70, 10,3,1978};
31. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70, 10,3,1978};
32. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70, 10,3,1978};
33. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70};
34. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70};
month=0;
day=0;
year=0;
35. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
PersonInfo christoph ={170,70};
month=0;
day=0;
year=0;
36. Structures
•Initialize :
struct Date{ int month; int day; int year; } x,y ; struct PersonInfo { double height;//in cm int weight;//in kg Date birthday; };
Note :
Unlike Array , when you initialize , if you pass the number of members !
You will have an Error !
43. Classes
•It’s like a Struct.
•Its members could be Functions and data
• it supports( information hiding, data abstraction, and encapsulation )
44. Classes
•It’s like a Struct.
•Its members could be Functions and data
• it supports( information hiding, data abstraction, and encapsulation )
•private, only seen in the current class(for class functions) , unseen out of class !
• public, seen everywhere (in current class and out of class)
•We use two things in classes :
45. Classes
•It’s like a Struct.
•Its members could be Functions and data
• it supports( information hiding, data abstraction, and encapsulation )
•Mostly in each class , you might have get(privateto variables )and set(variablesprivate) functions
•private, only seen in the current class(for class functions) , unseen out of class !
• public, seen everywhere (in current class and out of class)
•We use two things in classes :
46. Classes
•Mostly in each class , you might have get(privateto variables )and set(variablesprivate) functions
47. Classes
•Mostly in each class , you might have get(privateto variables )and set(variablesprivate) functions
Accessor functions
Mutator functions