Page 79 - DCAP404 _Object Oriented Programming
P. 79

Object-oriented Programming




                    Notes                        private:
                                                        //data
                                                        //  functions
                                                 public:
                                                        //functions
                                          };
                                          <class_name> object1, object2,… objectN;

                                   where object1, object2 and objectN are the instances of the class <class_name>.
                                   A class definition is very similar to a structure definition except the class definition defines the
                                   variables and functions.

                                   Consider the following program segment which declares and creates a class of objects.
                                          class  student
                                          {
                                          private:
                                                 int  rollno;

                                                 int  age;
                                                 float  height;
                                                 float  weight;
                                          public:
                                                 void  getinfo(  );
                                                 void  disinfo(  );
                                                 void  process(  );
                                                 void  personal(  );
                                          };
                                          student std;  //std is the object of the class student

                                   In another example the employee details such as name. code, designation, address, salary age
                                   can be grouped as follows.

                                          class  employee
                                          {
                                          private:
                                                 char  name[20];
                                                 int  code;
                                                 char  designation[20];
                                                 char  address[30];

                                                 float  salary;
                                                 int  age;
                                          public:




          72                                LOVELY PROFESSIONAL UNIVERSITY
   74   75   76   77   78   79   80   81   82   83   84