09-07-2013, 04:21 PM
PERSONAL INFORMATION SYSTEM
AIM:
Develop an object oriented program in C++ to create a database of the personnel information system containing the following information: Name, Date of Birth, Blood group ,Height, Weight, Insurance Policy number, Contact address ,telephone number, driving license no. etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor ,copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.
OBJECTIVE:
Static member functions, friend class, this pointer, inline code and dynamic memory allocation.
THEORY:
Static members
A class can contain static members, either data or functions.
A static member variable has following properties:
• It is initialized to zero when the first object of its class is created. No other initialization is permitted.
• Only one copy of that member is created for the entire class and is shared by all the objects of that class.
• It is the visible only within the class but its lifetime is the entire program.
Static data members of a class are also known as "class variables", because there is only one unique value for all the objects of that same class. Their content is not different from one obje static members have the same properties as global variables but they enjoy class scope. For that reason, and to avoid them to be declared several times, we can only include the prototype (its declaration) in the class declaration but not its definition (its initialization). In order to initialize a static data-member we must include a formal definition outside the class, in the global scope of this class to another. Because it is a unique variable value for all the objects of the same class, it can be referred to as a member of any object of that class or even directly by the class name (of course this is only valid for static members.
Friend functions:
In principle, private and protected members of a class cannot be accessed from outside the same class in which they are declared. However, this rule does not affect friends. Friends are functions or classes declared as such. If we want to declare an external function as friend of a class, thus allowing this function to have access to the private and protected members of this class, we do it by declaring a prototype of this external function within the class, and preceding it with the keyword friend.
Properties of friend function:
• It is not in the scope of the class to which it has been declared as friend.
• Since it is not in the scope of the class , it cannot be called using the object of that class
• It can be invoked like a normal function w/o the help of any object.
• It can be declared in private or in the public part of the class.
• Unlike member functions , it cannot access the member names directly and has to use an object name and dot operator with each member name.
PRACTICE ASSIGNMENTS:
1. Develop an object oriented program in C++ to create a database of the Student information system containing the following information: Name, Date of Birth, Class, Marks, Contact address, telephone number, etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.
2. Develop an object oriented program in C++ to create a database of the Employee information system containing the following information: Name, Date of Birth, Empcode, Contact address, telephone number, etc Construct the database with suitable member functions for initializing and destroying the data viz constructor, default constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation operators-new and delete.