0% found this document useful (0 votes)
115 views2 pages

Ass.2. Student Database - Doc 0

This C++ program develops a student information system database containing student name, roll number, class, division, date of birth, blood group, contact details, phone number, and driver's license number. The database uses object-oriented programming concepts like classes, constructors, destructors, static member functions, friend classes, this pointer, and dynamic memory allocation. It defines a class called studdb with member variables to store the student data and various member functions like default constructor, copy constructor, getter and setter functions, and destructor. The main function creates objects using new operator, gets input using constructor and member functions, displays output using a friend function, and deletes the objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views2 pages

Ass.2. Student Database - Doc 0

This C++ program develops a student information system database containing student name, roll number, class, division, date of birth, blood group, contact details, phone number, and driver's license number. The database uses object-oriented programming concepts like classes, constructors, destructors, static member functions, friend classes, this pointer, and dynamic memory allocation. It defines a class called studdb with member variables to store the student data and various member functions like default constructor, copy constructor, getter and setter functions, and destructor. The main function creates objects using new operator, gets input using constructor and member functions, displays output using a friend function, and deletes the objects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

#include <iostream>
#include<string.h>
#include<iomanip>

using namespace std;

class studdb
{
int roll;
char name[20];
char Class[10];
char Div[10];

public:
static int stdno;

static void count()


{
cout<<"\nNo. of objects created: "<<stdno;
}

void fin()
{
cout<<"\nInline Function!";
}

studdb()
{
roll=0;
strcpy(name,"Sachin");
strcpy(Class,"I");
strcpy(Div,"A");

++stdno;
}

studdb(studdb *ob)
{
strcpy(name,ob->name);

strcpy(Class,ob->Class);
strcpy(Div,ob->Div);

++stdno;
}

void getdata()
{
cout<<"\n\nEnter:name,roll,Class,Div \n\n\n";
cin>>name>>roll>>Class>>Div;
}

friend void display(studdb d);

~studdb()
{
cout<<"\n\n"<<this->name<<"(Object) is destroyed!";
}

};

void display(studdb d)
{
cout<<"\n"<<setw(12)<<d.name<<setw(5)<<d.roll<<setw(4);
cout<<d.Class<<setw(3)<<d.Div<<setw(12);
}
int studdb::stdno;

int main()
{
int n,i;
studdb d1,*ptr[5]; // calls constructor
cout<<"\nDefault values:";
display(d1);

d1.getdata();
display(d1);

studdb d2(&d1);
cout<<"\n\nUse of copy constructor :\n";
display(d2);

cout<<"\nHow many objects u want to create?:";


cin>>n;
for(i=0;i<n;i++)
{
ptr[i]=new studdb();
ptr[i]->getdata();
}
cout<<"\
n"<<setw(12)<<"name"<<setw(5)<<"roll"<<setw(4)<<"Class"<<setw(4)<<"Div"<<setw(12
);

for(i=0;i<n;i++)
display(*ptr[i]);

studdb::count();

for(i=0;i<n;i++)
{
delete(ptr[i]);
}
cout<<"\nObjects deleted!" ;
return 0;
}

You might also like