-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.h
146 lines (131 loc) · 4.06 KB
/
student.h
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
145
146
#include "colors.hpp"
#define red colors::bright_red
#define blue colors::bright_cyan
#define yellow colors::bright_yellow
#define green colors::bright_green
#define reset colors::reset
using namespace std;
class bca_stdata
{
public:
void setstudentdata(string, string, string, string); //---> to set a student's data and make a new entry
void displaystudentdata(); //---> to display the list of students and their data
void stid_display(string); //---> to display a specific student's data
};
class mca_stdata
{
public:
void setstudentdata(string, string, string, string); //---> to set a student's data and make a new entry
void displaystudentdata(); //---> to display the list of students and their data
void stid_display(string); //---> to display a specific student's data
};
void bca_stdata::setstudentdata(string name, string id, string course, string email)
{
ofstream fo("Storage/bca_student.txt", ios::app);
if (!fo)
cout << red << "Error entering the data!\n" << reset;
else
{
// using setw() from iomanip header file to align the text in storage files
fo << setw(4) << id << " | " << setw(18) << name << " | " << setw(6) << course << " | " << setw(24) << email << endl;
cout << green << "\nData entered sucessfully!!!\n\n" << reset;
}
fo.close();
}
void bca_stdata::displaystudentdata()
{
string line;
ifstream fi("Storage/bca_student.txt");
cout << blue << "List of Students :\n\n";
if (!fi)
cout << red << "Error fetching details!\n" << reset;
else
{
// printing the whole text file
while (getline(fi, line))
{
cout << yellow << line << endl;
}
cout << endl;
}
}
void bca_stdata::stid_display(string id)
{
string line;
fstream f("Storage/bca_student.txt");
if (!f)
{
cout << red << "Error fetching details!\n" << reset;
}
else
{
while (getline(f, line)) // reads/traverses every line of the text file
{
if (line.find(id) != string::npos) // searches & if finds the id in the line in iteration
{
cout << yellow << "\n ID | NAME | COURSE | EMAIL ADDRESS\n" << line << "\n\n";
break;
}
}
if (line.find(id) == string::npos) // if find function returns (string::npos)
{
cout << red << "\nNo such record found!\n\n" << reset;
}
}
f.close();
}
// concepts same as bca member functions are used here
void mca_stdata::setstudentdata(string name, string id, string course, string email)
{
ofstream fo("Storage/mca_student.txt", ios::app);
if (!fo)
cout << red << "Error entering the data!\n" << reset;
else
{
fo << setw(4) << id << " | " << setw(18) << name << " | " << setw(6) << course << " | " << setw(24) << email << endl;
cout << green << "\nData entered sucessfully!!!\n\n" << reset;
}
fo.close();
}
void mca_stdata::displaystudentdata()
{
string line;
ifstream fi("Storage/mca_student.txt");
cout << blue << "List of Students :\n\n";
if (!fi)
cout << red << "Error fetching details!\n" << reset;
else
{
while (getline(fi, line))
{
cout << yellow << line << endl;
}
cout << endl;
}
}
void mca_stdata::stid_display(string id)
{
string line;
fstream f("Storage/mca_student.txt");
if (!f)
{
cout << red << "Error fetching details!\n" << reset;
}
else
{
while (getline(f, line))
{
if (line.find(id) != string::npos)
{
cout << yellow << "\n ID | NAME | COURSE | EMAIL ADDRESS\n"
<< line << "\n\n";
break;
}
}
if (line.find(id) == string::npos)
{
cout << red << "\nNo such record found!\n\n" << reset;
}
}
f.close();
}