-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent.cpp
More file actions
144 lines (133 loc) · 3.32 KB
/
student.cpp
File metadata and controls
144 lines (133 loc) · 3.32 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include <iostream>
#include <string>
using namespace std;
class info
{
private:
string nm, drv_lic, cl, dob;
int roll;
char* div, *bdgp;
long int ctnum;
public:
// Default constructor
info()
{
nm = "";
dob = "";
cl = "";
roll = 0;
ctnum = 0;
div = new char[1];
bdgp = new char[3];
}
// Destructor
~info()
{
delete[] div;
delete[] bdgp;
}
friend class addinfo;
void inputinfo()
{
cin.ignore(); // Ignore the newline character left in the input stream
cout << "\n\n_______________*STUDENT DATABASE*______________\n\n";
cout << "Student Name: ";
getline(cin, nm);
cout << "\nClass: ";
getline(cin, cl);
cout << "\nDivision: ";
div = new char[10]; // Allocate memory for division
cin >> div;
cout << "\nRoll number: ";
cin >> roll;
cout << "\nDate of Birth (Format- dd/mm/yyyy): ";
cin.ignore(); // Ignore the newline character left in the input stream
getline(cin, dob);
cout << "\nBlood Group (A+, A-, B+, B-, AB+, AB-, O+, O-): ";
bdgp = new char[10];
cin >> bdgp;
cout << "\nEnter driving licence number: ";
cin >> drv_lic;
}
};
class addinfo
{
public:
long int ctnum;
void getinfo()
{
try
{
cout << "\nContact Number: ";
cin >> ctnum;
if (ctnum < 1000000000 || ctnum > 9999999999)
throw ctnum;
}
catch (long int ctnum)
{
cout << "\nException caught!";
cout << "\nContact number entered '" << ctnum << "' is too long!\nTry again!";
cout << "\nContact Number: ";
cin >> ctnum;
}
}
int getroll(info &obj)
{
return obj.roll;
}
void show(info &obj);
};
void addinfo::show(info &obj)
{
cout << "\nStudent Name: " << obj.nm;
cout << "\nClass: " << obj.cl;
cout << "\nDivision: " << obj.div;
cout << "\nRoll number: " << obj.roll;
cout << "\nDate of Birth: " << obj.dob;
cout << "\nBlood Group: " << obj.bdgp;
cout << "\nDriving licence number: " << obj.drv_lic;
cout << "\n-------------------------------------\n";
}
int main()
{
info x[30];
int i, n;
cout << "Enter the number of students: ";
cin >> n;
addinfo s[30];
for (i = 0; i < n; i++)
{
cout << "\n---------------------------------------\n\nEnter Details of student " << i + 1;
x[i].inputinfo();
s[i].getinfo();
}
cout << "\n_____________________________________________________________" << endl;
for (i = 0; i < n; i++)
{
s[i].show(x[i]);
}
while (true)
{
int r, ch;
int flag = 0;
cout << "\nEnter student roll number to get info: ";
cin >> r;
for (i = 0; i < n; i++)
{
if (r == s[i].getroll(x[i]))
{
s[i].show(x[i]);
flag = 1;
break;
}
}
if (flag == 0)
cout << "\nRecord not found!";
cout << "\nDo you want to continue? (Enter 1 for Yes, 0 for No): ";
cin >> ch;
if (ch != 1)
break;
}
cout<<"\nEnding the Program!";
return 0;
}