Personal information system using constructor, destructor, static member functions, friend class, this pointer, inline code and dynamic memory allocation.
Experiment:
Develop a program in C++ to create a database of student’s
information system containing the following information: Name, Roll number, Class,
Division, Date of Birth, Blood group, Contact address, Telephone number,
Driving license no. and other. Construct the database with suitable member
functions. Make use of constructor, default constructor, copy constructor,
destructor, static member functions, friend class, this pointer, inline code
and dynamic memory allocation operators-new and delete as well as exception
handling.
Problem
Statement:
Develop an object-oriented programming
in C++ to create a database of the Personal 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 via constructer, default constructer, copy constructer, destructor, static member function, friend class, this pointer, inline code, and dynamic memory allocation operators- new and delete as well as exception handling.
Objectives:
To learn the concept of Constructor, default Constructor, copy constructor, destructor, static member functions, friend class, this pointer, inline code, and dynamic memory allocation operators- new and delete.
Algorithm:
1. Start
2. Read
Personal information such as Name, Date of Birth, Blood group, Height, Weight,
Insurance policy, Contact address, Telephone number driving license no.
3. Print
all information from database
4. Stop
Program:
#include<iostream>
#include<string.h>
using namespace std;
class Data
{
string address;
long int *mobile_no;
long int *dl_no;
public:
Data(); // default constructor of
class Data
~Data(); // Destructor of class Data
void input_student_data();
void display_student_data();
friend class Student;
};
class Student
{
string Name;
int Roll;
string Class;
char *Div;
string dob;
char *bg;
static int count;
public:
Student();
~Student();
static int get_count()
{
return count;
}
void input_data(Data *);
void display_data(Data *);
};
Data::Data()
{
address = " ";
mobile_no = new long;
dl_no = new long;
}
Data::~Data()
{
delete mobile_no;
delete dl_no;
}
void Data::input_student_data()
{
cout<<"Contact Address :
";
cin.ignore();
getline(cin,address);
cout<<"Mobile Number :
";
cin>>*mobile_no;
cout<<"Driving License
Number : ";
cin>>*dl_no;
}
void Data::display_student_data()
{
cout<<"Contact Address :
"<<address<<endl;
cout<<"Mobile Number :
"<<*mobile_no<<endl;
cout<<"Driving License
Number : "<<*dl_no<<endl;
}
Student::Student()
{
Name = " ";
Roll = 0;
Class = " ";
Div = new char;
dob = "dd/mm/yyyy";
bg = new char[5];
}
Student::~Student()
{
delete Div;
delete[] bg;
}
inline void Student::input_data(Data
*stud1)
{
cout<<"Name : ";
cin.ignore();
getline(cin,Name);
cout<<"Roll Number :
";
cin>>Roll;
cout<<"Class : ";
cin.ignore();
getline(cin,Class);
cout<<"Division : ";
cin>>Div;
cout<<"Date of Birth :
";
cin.ignore();
getline(cin,dob);
cout<<"Blood Group :
";
cin>>bg;
stud1->input_student_data();
count++;
}
inline void
Student::display_data(Data *stud2)
{
cout<<"Name :
"<<Name<<endl;
cout<<"Roll Number :
"<<Roll<<endl;
cout<<"Class :
"<<Class<<endl;
cout<<"Division :
"<<Div<<endl;
cout<<"Date of Birth :
"<<dob<<endl;
cout<<"Blood Group :
"<<bg<<endl;
stud2->display_student_data();
cout<<"----------------------------------------------------------------------\n";
}
int Student::count;
int main()
{
Student *st1[100];
Data *st2[100];
int a;
int s=0;
char ch;
for(int i=0;i<2;i++)
{
cout<<"--------------------MENU--------------------\n";
cout<<"1. New
Student\n";
cout<<"2. View
Database\n";
cout<<"Enter your choice :
"<<endl;
cin>>a;
switch (a)
{
case 1 :
{
do
{
st1[s] = new Student;
st2[s] = new Data;
cout<<"Enter the details
of student "<<s+1<<" : "<<endl;
st1[s]->input_data(st2[s]);
s++;
cout<<"Do you want to create
a new student (y/n): ";
cin>>ch;
}while(ch=='y' || ch=='y');
}
break;
case 2:
{
cout<<"**************************StudentDatabase****************************"<<endl;
for(int j=0;j<s;j++)
{
st1[j]->display_data(st2[j]);
}
}
break;
default:
cout<<"WRONG CHOICE
EXECUTE AGAIN\n";
}
}
cout<<"Total Number of
Students : "<<Student::get_count()<<endl;
return 0;
}
Output:
--------------------MENU--------------------
1. New Student
2. View Database
Enter your choice :
1
Enter the details of student 1 :
Name : kdjkfjkj
Roll Number : 12
Class : 6
Division : A
Date of Birth : 24/6/2000
Blood Group : A+
Contact Address : jhkjyug
Telephone Number : 892563215
Driving License Number : 52258656
Do you want to create a new student
(y/n): y
Enter the details of student 2 :
Name : hdjhdjh
Roll Number : 21
Class : A
Division : B
Date of Birth : 27/8/2003
Blood Group : A+
Contact Address : 656853235
Telephone Number : 256656555
Driving License Number : 243546
Do you want to create a new student
(y/n): n
--------------------MENU--------------------
1. New Student
2. View Database
Enter your choice :
2
**************************StudentDatabase****************************
Name : kdjkfjkj
Roll Number : 12
Class : 6
Division : A
Date of Birth : 24/6/2000
Blood Group : A+
Contact Address : jhkjyug
Telephone Number : 892563215
Driving License Number : 52258656
----------------------------------------------------------------------
Name : hdjhdjh
Roll Number : 21
Class : A
Division : B
Date of Birth : 27/8/2003
Blood Group : A+
Contact Address : 656853235
Telephone Number : 256656555
Driving License Number : 243546
----------------------------------------------------------------------
Total Number of Students : 2
--------------------------------
Process exited after 374.7 seconds
with return value 0
Press any key to continue . .
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home