-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDeveloper.h
340 lines (301 loc) · 9.21 KB
/
Developer.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
#pragma once
#include<iostream>
#include<istream>
#include<string.h>
#include<vector>
#include<fstream> // use for file handling
#include<sstream>
#include<cstdio>
using namespace std;
void addCompany(string, int, int);
int hashFunction(string);
void displayCompanyDetails();
void displayJobDetails();
bool findduplicates(int);
void writeToCompany(string);
const int N = 10; // Size of ComPany HashArray;
int k = 0; // variable that used to detect the Job Titles
struct Company* HashArray[N]; // Initializing of the Hash Array // # USING OF HASHTABLE DATA STRUCTURE
int sortArray[5]; // Array that store distinct job titles // # USING OF ARRAYS DATA STRUCTURE
int isAvailableCompanyCSV = 0;
void displayJobDetails() {
cout << "-----------------------JoB Titles with Reference Number----------------------------" << endl;
cout << "Software Engineering => 100" << endl;
cout << "Electronic Engineering => 101" << endl;
cout << "Electircal Engineering => 102" << endl;
cout << "Telecommuincation Engineering => 103" << endl;
cout << "Power Engineering => 104" << endl;
cout << endl;
}
void findJob(int jobIndex) { // Display the available jobs for user
switch (jobIndex)
{
case 100:
cout << "100-> Software Engineering " << endl;
break;
case 101:
cout << "101->Electronic Engineering " << endl;
break;
case 102:
cout << "102-> Electrical Engineering" << endl;
break;
case 103:
cout << "103-> Telecomunication Engineering" << endl;
break;
case 104:
cout << "104-> Power Enginnering" << endl;
break;
default:
cout << "104-> Power Enginnering" << endl;
break;
}
}
struct Company
{
string comName; // key value of the HashArray
int refNumber = 0;
//string jobTitle;
int noOfVacancies = 0;
};
void inputCompanyDetails() {
string Name;
int jobRefNo, vacancies;
cout << "--------------------------Enter the Company Details-------------------------------" << endl << endl;
cout << "Enter the Company Name: ";
cin >> Name;
cout << endl;
displayJobDetails();
cout << "Enter the Job Referance Number: ";
cin >> jobRefNo;
cout << endl;
cout << "Enter the Number of Vacancies: ";
cin >> vacancies;
cout << endl;
addCompany(Name, jobRefNo, vacancies);
}
void addCompany(string Name, int refNo, int vacancies) { // adding elements for the HashArray
struct Company* company = new struct Company;
company->comName = Name;
company->refNumber = refNo;
company->noOfVacancies = vacancies;
int index = hashFunction(Name);
while (HashArray[index] != NULL) { // Collision method is linear probing algorithm
index++;
index = index % N;
}
HashArray[index] = company;
}
int hashFunction(string key) { // hashfunction
int sum = 0;
for (int i = 0; i < key.length(); i++) {
sum += key[i];
}
return (sum % N);
}
void displayCompanyDetails() { // Dispaly full details about the companies
for (int i = 0; i < N; i++) {
if (HashArray[i] != NULL) {
cout << "Company Name : " << HashArray[i]->comName << "==> Index Number : " << i << endl;
cout << "Job details" << endl;
cout << "Job Title :- ";
findJob(HashArray[i]->refNumber);
cout << " No of Vaccancies :- " << HashArray[i]->noOfVacancies << endl;
cout << endl;
}
}
}
void sortJobs() { //function that insert disctint Job titles into an array
for (int i = 0; i < N; i++) {
if (HashArray[i] != NULL) {
if (findduplicates(HashArray[i]->refNumber)) {
sortArray[k] = (HashArray[i]->refNumber);
k++;
}
}
}
}
bool findduplicates(int number) { // remove duplicats to create above array
for (int i = 0; i < k; i++) {
if (sortArray[i] == number) {
return false;
}
}
return true;
}
void displayAvailableJobs() { // Display the available jobs for user
cout << "---------------Available Jobs Oppotunities----------------------" << endl;
for (int i = 0; i < k; i++) {
switch (sortArray[i])
{
case 100:
cout << "100-> Software Engineering " << endl;
break;
case 101:
cout << "101->Electronic Engineering " << endl;
break;
case 102:
cout << "102-> Electrical Engineering" << endl;
break;
case 103:
cout << "103-> Telecomunication Engineering" << endl;
break;
case 104:
cout << "104-> Power Enginnering" << endl;
break;
default:
cout << "104-> Power Enginnering" << endl;
break;
}
}
}
void update(int comIndex) {
int jobrefNo, noOfVacancies;
cout << "Exist Details:- " << endl;
cout << "Company Name : " << HashArray[comIndex]->comName << endl;
cout << "Job Title : ";
findJob(HashArray[comIndex]->refNumber);
cout << endl;
cout << "No of Vacancies : " << HashArray[comIndex]->noOfVacancies << endl;
cout << "Let's start updating purposes" << endl;
displayJobDetails();
cout << "Enter the Job Referance Number : ";
cin >> jobrefNo;
cout << "Enter the Number of Vacancies : ";
cin >> noOfVacancies;
HashArray[comIndex]->refNumber = jobrefNo;
HashArray[comIndex]->noOfVacancies = noOfVacancies;
cout << " Succesfully updated " << endl;
}
/* functions used to write, read, update and resotre CSV file
void readToCompany(string fileName) { //read the data from CSV file
fstream file(fileName, ios::in);
string line;
string Comref;
string Comname;
string refNumber;
string jobTitle;
string noOfVacancies;
while (getline(file, line)) {
stringstream ss(line); //using stringtream seperate the row into words
getline(ss, Comref, ',');
getline(ss, Comname, ',');
getline(ss, refNumber, ',');
getline(ss, jobTitle, ',');
getline(ss, noOfVacancies, '\n');
addCompany(Comname, stoi(refNumber), jobTitle, stoi(noOfVacancies));
}
file.close();
}
void writeToCompany(string fileName) { //write the data into CSV file
isAvailableCompanyCSV = 1;
fstream file;
file.open(fileName, ios:: out| ios::app);// open an existing file or creates a new file
for (int i = 0; i < N; i++) {
if (HashArray[i] != NULL) {
file << i<<","<<HashArray[i]->comName << "," << HashArray[i]->refNumber <<"," << HashArray[i]->jobTitle << "," << HashArray[i]->noOfVacancies <<endl;
}
}
file.close();
}
void update_recode()
{
// File pointer
fstream fin, fout;
// Open an existing record
fin.open("Company.csv", ios::in);
// Create a new file to store updated data
fout.open("Companynew.csv", ios::out | ios::app);
int comRefNumber, roll1, count = 0, i;
int refNumber, noOfVacancies;
//int index, new_marks;
string line, word,jobTitle;
vector<string> row;
// Get the roll number from the user
cout << "Enter the Company Referance number of the record to be updated : ";
cin >> comRefNumber;
// Get the data to be updated
displayJobDetails();
cout << "Enter the New/Existing Job referenace Number : ";
cin >> refNumber;
cout << endl;
cout << "Enter the New/Existing Job Title : ";
cin >> jobTitle;
cout << endl; cout << "Enter the Number of Vacancies : ";
cin >> noOfVacancies;
cout << endl;
// Traverse the file
while (!fin.eof()) {
row.clear();
getline(fin, line);
stringstream s(line);
while (getline(s, word, ',')) {
row.push_back(word);
}
roll1 = stoi(row[0]);
int row_size = row.size();
if (roll1 == comRefNumber) {
count = 1;
stringstream newJobRefNumber;
stringstream newJobTitle;
stringstream newNoOfVacancies;
// sending a number as a stream into output string
newJobRefNumber << refNumber;
newJobTitle << jobTitle;
newNoOfVacancies << noOfVacancies;
// the str() converts number into string
row[2] = newJobRefNumber.str();
row[3] = newJobTitle.str();
row[4] = newNoOfVacancies.str();
if (!fin.eof()) {
for (i = 0; i < row_size - 1; i++) {
// write the updated data
// into a new file 'reportcardnew.csv'
// using fout
fout << row[i] << ",";
}
fout << row[row_size - 1] << "\n";
}
}
else {
if (!fin.eof()) {
for (i = 0; i < row_size - 1; i++) {
// writing other existing records
// into the new file using fout.
fout << row[i] << ", ";
}
// the last column data ends with a '\n'
fout << row[row_size - 1] << "\n";
}
}
if (fin.eof())
break;
}
if (count == 0)
cout << "Record not found\n";
fin.close();
fout.close();
// removing the existing file
remove("Company.csv");
// renaming the updated file with the existing file name
rename("Companynew.csv", "Company.csv");
/*if (rename("Companynew.csv", "Company.csv") == 0) {
cout << "Updated Successfully" << endl;
}
}
void restoreCompanyData() {
fstream fin, fout;
fin.open("Company.csv", ios::in);
fout.open("Companynew.csv", ios::out | ios::app);
for (int i = 0; i < N; i++) {
if (HashArray[i] != NULL) {
fout << i << "," << HashArray[i]->comName << "," << HashArray[i]->refNumber << "," << HashArray[i]->jobTitle << "," << HashArray[i]->noOfVacancies << endl;
}
fout.close();
}
fin.close();
remove("Company.csv");
// renaming the restored file with the existing file name
if (rename("Companynew.csv", "Company.csv") == 0) {
cout << "Resotred Successfully" << endl;
}
}*/