-
Notifications
You must be signed in to change notification settings - Fork 0
/
faculty.h
146 lines (131 loc) · 4.04 KB
/
faculty.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_fcdata
{
public:
void setfacultydata(string, string, string, string); //---> to set a faculty's data and make a new entry
void displayfacultydata(); //---> to display the list of facultys and their data
void fcid_display(string); //---> to display a specific faculty's data
};
class mca_fcdata
{
public:
void setfacultydata(string, string, string, string); //---> to set a faculty's data and make a new entry
void displayfacultydata(); //---> to display the list of facultys and their data
void fcid_display(string); //---> to display a specific faculty's data
};
void bca_fcdata::setfacultydata(string name, string id, string course, string email)
{
ofstream fo("Storage/bca_faculty.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";
}
fo.close();
}
void bca_fcdata::displayfacultydata()
{
string line;
ifstream fi("Storage/bca_faculty.txt");
cout << blue << "List of Faculty :\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_fcdata::fcid_display(string id)
{
string line;
fstream f("Storage/bca_faculty.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_fcdata::setfacultydata(string name, string id, string course, string email)
{
ofstream fo("Storage/mca_faculty.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_fcdata::displayfacultydata()
{
string line;
ifstream fi("Storage/mca_faculty.txt");
cout << blue << "List of Faculty :\n\n";
if (!fi)
cout << red << "Error fetching details!\n" << reset;
else
{
while (getline(fi, line))
{
cout << yellow << line << endl;
}
cout << endl;
}
}
void mca_fcdata::fcid_display(string id)
{
string line;
fstream f("Storage/mca_faculty.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();
}