Objects -
In
structured programming language a problem is approached by dividing it into
functions however in object-oriented programming the problem is divided into
objects. An object is a component of a program that can have its own set of
data and can be used to perform more than a repeated task. Designing the system
with objects allowed developer to model system after the real world.
For Example
– The developer has created an object of the student class to store data
associated with a single student using member data and can perform certain
operations using this object such as adding a new student, listing a student,
checking whether a particular student record exist or not using the member
functions of the class.
The
object has been defined using the class name and object name with the following
format –
void
student_module()
{
student student_record;
// ............CREATING THE OBJECT OF THE STUDENT CLASS.............
char ch,che;
int
count = 0;
There
are many candidates that are treated as objects in the system which are
students, books, and administrator.
Inheritance -
As
C++ allowed developer to create its own data types (classes) just like built in
data types, C++ allowed the developer to use classes as building blocks of
other classes using a concept called inheritance, new classes are built on top
of the old ones. The new class referred to as a derived class, can inherit the
data and functions of the original or the base class and can add its own data
elements and functions.
For
Example – The developer has designed a class named login as base class and
inherited the class in the admin as well as student class as both student and
admin need to login in the system. Data member for login class is a structure
named login info having structure elements username and password, and a virtual
member function system login. Both the admin and student class inherited login
class and added its own data member’s admin name, structure student information
etc.
The
base class is inherited in the derived classes in following format –
Base Class –
class login
{
public:
struct log_info{
int username;
char password[20];
}log;
//__________PURE
VIRTUAL FUNCTION______________
virtual int
system_login() = 0;
};
Derived Classes –
class admin: public login
//.........ADMIN
CLASS INHERITING THE LOGIN CLASS..............
{
private:
char admin_name[20];
char flag;
fstream file;
public:
admin();
int system_login(); //overriding
void addrec();
};
class student: public login //______INHERITANCE________
{
public:
struct student_information{
char flag;
int roll_number;
char student_name[20];
char course[20];
char branch[16];
int book_code;
char issue_date[10],
return_date[10];
int fine;
}b;
private:
fstream file;
public:
student();
int system_login();
void addrecUser();
void addrec();
void listrec();
void delrec();
void modrec();
int check_record(int student_roll_number, int
check_information);
int check_exist( int student_roll_number); //overloading
void Uprec();
int GetRoll();
//______________FOR
RANDOMLY GENERATING THE STUDENT ROLL NUMBER_____________
};
No comments:
Post a Comment