EC101A_U5_3(const) - EC-101A COMPUTER SYSTEMS AND...

This preview shows page 1 - 8 out of 46 pages.

EC-101A COMPUTER SYSTEMS AND PROGRAMMING Object Oriented Programming Concepts: Data hiding, abstract data types, classes, access control; Class implementation-default constructor, constructors, copy constructor, destructor, operator overloading, friend functions; Introduction to data structures, use of pointers in linked structures; Object oriented design (an alternative to functional decomposition) inheritence and composition; Dynamic binding and virtual functions; Polymorphism; Dynamic data in classes. (15 Hrs., 5 Labs)
Image of page 1

Subscribe to view the full document.

Constructors and Destructors
Image of page 2
There are two Special members functions 1. Constructors 2. Destructors Constructors are called every time we create an object. Destructors are called every time we destroy an object.
Image of page 3

Subscribe to view the full document.

Constructors Default Constructors Parameterized Constructors Copy Constructors
Image of page 4
A constructor is a special member function whose task is to initialize the objects of its class. This is known as automatic initialization of objects. It is special because its name is the same as the class name. The constructor is invoked whenever an object of its associated class is created. It is called constructor because it constructs the values of data members of the class.
Image of page 5

Subscribe to view the full document.

Why constructors First a variable declared. Example: int x; //variable x of type integer float y; //variable y of type float Variable x or y would have garbage value before initialization. We needed to initialize the variable to 0 or to some other useful value before using it. Example: int x =0; //variable x of type integer initialized to 0 float y= 22.5 ; //variable y of type float initialized to 22.5
Image of page 6
The same is true of objects. i.e. declaration and initialization of objects The difference is that with an object, we can't just assign it a value. We can't say: Student s1 = 0; because that doesn't make sense. (here s1 is an object of class Student) A Student is not a number, so we can't just set it to 0.
Image of page 7

Subscribe to view the full document.

Image of page 8

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern