Professional Documents
Culture Documents
Fall 2018
Object Oriented Programming(OOP),
Classes
Lecture 5
M. Tahir Awan
(mtahir@cust.edu.pk)
Capital University of Science & Technology (CUST),
Islamabad
Structure in C\C++
• A structure is a collection of data values, called
data members, that form a single unit.
• Members of a structure can be of different types
• We can create new data types using structures
• Examples
struct complexNumber{
struct student{ float real;
char Name[20]; float complex;
float CGPA; };
};
struct book{
char title[30];
int price;
};
10/2/2018 CSEE2123: OOP and DS © M. Tahir Awan, CUST 2
Declaration of Structure type Variables
• Structure variables are declared like other
variables
struct student{
struct student{
char Name[20]; char Name[20];
float CGPA; float CGPA;
}; }s1, s2;
struct student s1, s2; Alternate Declaration Method
struct student *ptrs;
struct distance{
distance d1; float feet;
distance *ptr = &d1 float inches;
};
ptr-> feet = 10;
ptr-> inches = 5;
(*ptr).inches = 5;
5
10/2/2018 CSEE2123: OOP and DS © M. Tahir Awan, CUST
C++ : User-Defined Data Types
User-Defined Data
Types
C Program
public:
Circle() {
radius = 5.0;
}
float getArea() {
return radius* radius* 3.14159;
}
};
int getX() {
return x; }
};
}
int main() {
Complex c1, c2(4, 5);
c1.setReal(0);
c1.setImag(8);