-
Notifications
You must be signed in to change notification settings - Fork 0
/
STUDENT DATABASE
102 lines (93 loc) · 2.1 KB
/
STUDENT DATABASE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include<string.h>
#include<iomanip>
using namespace std;
class db
{
int roll;
char name[20];
char Class[10];
char Div[10];
char dob[10];
char bg[3],contact[10];
char phone[10],license[12];
public:
static int stdno;
static void count()
{
cout<<"\nNo. of objects created: "<<stdno;
}
void fin()
{
cout<<"\nInline Function!";
}
db()
{
roll=0;
strcpy(name,"Sachin");
strcpy(Class,"I");
strcpy(Div,"A");
strcpy(dob,"11/11/1111");
strcpy(bg,"A");
strcpy(contact,"city");
strcpy(phone,"9000000000");
strcpy(license,"A0101010");
++stdno;
}
db(db *ob)
{
strcpy(name,ob->name);
strcpy(dob,ob->dob);
strcpy(Class,ob->Class);
strcpy(Div,ob->Div);
strcpy(bg,ob->bg);
strcpy(contact,ob->contact);
strcpy(phone,ob->phone);
strcpy(license,ob->license);
++stdno;
}
void getdata()
{
cout<<"\n\nEnter:name,roll,Class,Div,Dob,bg,contact,phone,license \n\n\n";
cin>>name>>roll>>Class>>Div>>dob>>bg>>contact>>phone>>license;
}
friend void display(db d);
~db()
{
cout<<"\n\n"<<this->name<<"(Object) is destroyed!";
}
};
void display(db d)
{
cout<<"\n"<<setw(12)<<d.name<<setw(5)<<d.roll<<setw(4)<<d.Class<<setw(3)<<d.Div<<setw(12)<<d.dob<<setw(4)<<d.bg<<setw(12)<<d.contact<<" "<<setw(12)<<d.phone<<" "<<setw(12)<<" "<<d.license;
}
int db::stdno;
int main()
{
int n,i;
db d1,*ptr[5];
cout<<"\nDefault values:";
display(d1);
d1.getdata();
display(d1);
db 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 db();
ptr[i]->getdata();
}
cout<<"\n"<<setw(12)<<"name"<<setw(5)<<"roll"<<setw(4)<<"Class"<<setw(4)<<"Div"<<setw(12)<<"dob"<<setw(4)<<"bg"<<setw(12)<<"contact"<<setw(12)<<"phone"<<setw(12)<<"license";
for(i=0;i<n;i++)
display(*ptr[i]);
db::count();
for(i=0;i<n;i++)
{
delete(ptr[i]);
}
cout<<"\nObjects deleted!" ;
return 0;
}