Thursday 20 October 2016

student database using Dynamic Memory Allocation

//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
//author:rushikesh sanjay palke
//class : SE comp
//roll no: 237
//date: 05 july 2016
//subject: object oriented programming
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
/*                          

Develop an object oriented program in C++ to create a database of student information
system containing the following information: Name, Roll number, Class, division, Date of
Birth, Blood group, 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.*/


#include<iostream>
#include<unistd.h>
#include<cstring>
#include<string>
using namespace std;
int cnt=0;
class student
{
public:
int roll_no,age;
long int mob_no;
string b_g,clas,div;
string name,adr;
student()
{
name=" ";
roll_no=0;
clas="SE";
div="A";
adr="PCCOE HOSTEL";
b_g="A+";
mob_no=7777777777;
age=19;
}

void enter(student list[20])
{
char temp[30];
student *ptr=new student();
cout<<"enter name:\n";
cin.clear();
cin.ignore();
cin.getline(temp,30);
ptr->name=temp;
cout<<"enter roll no:\n";
cin>>ptr->roll_no;
cout<<"enter class :\n";
cin>>ptr->clas;
cout<<"enter division:\n";
cin>>ptr->div;
cout<<"enter address:\n";
cin.clear(); //used to clear input buffer
cin.ignore(); //used to clear input buffer
cin.getline(temp,30);
ptr->adr=temp;
cout<<"enter mobile number:\n";
cin>>ptr->mob_no;
cout<<"enter blood group:\n";
cin>>ptr->b_g;
cout<<"enter age:\n";
cin>>ptr->age;
list[cnt]=*ptr;
cnt++;
}
void update(student list[20])
{int r;
cout<<"enter roll no for updation";
cin>>r;
for(int i=0;i<20;i++)
{
if(r==list[i].roll_no)
{cout<<"OLD DATA\n";
cout<<"name: "<<list[i].name<<"\n";
cout<<"age: "<<list[i].age<<"\n";
cout<<"ENTER NEW DATA\n";
cout<<"Name:\n";
cin>>list[i].name;
cout<<"class :\n";
cin>>list[i].clas;
cout<<"division:\n";
cin>>list[i].div;
cout<<"address:\n";
cin>>list[i].adr;
cout<<"mobile number:\n";
cin>>list[i].mob_no;
cout<<"blood group:\n";
cin>>list[i].b_g;
cout<<"age:\n";
cin>>list[i].age;
usleep(30000);
cout<<"data updated succesfully";
}
else
cout<<"No data found\n";
break;
}

}

void display(student list[20])
{int r;
cout<<"enter students roll no";
cin>>r;
for(int i=0;i<20;i++)
{
if(r==list[i].roll_no)
{
cout<<"name: "<<list[i].name<<"\n";
cout<<"age: "<<list[i].age<<"\n";
cout<<"class:"<<list[i].clas<<endl;
cout<<"division:"<<list[i].div<<endl;
cout<<"address:"<<list[i].adr<<endl;
cout<<"mobile number:"<<list[i].mob_no<<endl;
cout<<"blood group:"<<list[i].b_g<<endl;
}
}

}


~student(){};

};

int main()
{
int ch;
student s;
student list[20];
char c;
do
{
cout<<"############STUDENT DATABASE#############\n";
cout<<"1] enter data\n";
cout<<"2] update data\n";
cout<<"3] display data\n";
cout<<"4] delete data\n";
cout<<"5] Exit student database\n";
cout<<"enter your choise:";
cin>>ch;
switch (ch)
{
case 1:
   
      s.enter(list);
      break;
   
case 2:
      s.update(list);
      break;
case 3:
      s.display(list);
      break;
case 4:
      cout<<"deleting memory..............\n";
      s.~student();
      usleep(300000);
      cout<<"memory cleaned\n";
      break;                

}
if(ch==5)
c='n';
else{
cout<<"do you want to continue (y/n)";
cin>>c;
}
}while(c=='y'||c=='Y');

cout<<"Googby Have a nice day.....\n";


}


/*
output:
############STUDENT DATABASE#############
1] enter data
2] update data
3] display data
4] delete data
5] Exit student database
enter your choise:1
enter name:
rushikesh phalke
enter roll no:
32
enter class :
SE
enter division:
B
enter address:
PCCOE Hostel
enter mobile number:
7775910607
enter blood group:
A+
enter age:
19
do you want to continue (y/n)y
############STUDENT DATABASE#############
1] enter data
2] update data
3] display data
4] delete data
5] Exit student database
enter your choise:3
enter students roll no32
name: rushikesh phalke
age: 19
class:SE
division:B
address:PCCOE Hostel
mobile number:7775910607
blood group:A+
do you want to continue (y/n)
*/

No comments:

Post a Comment