-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomp.cpp
More file actions
136 lines (104 loc) · 3.27 KB
/
comp.cpp
File metadata and controls
136 lines (104 loc) · 3.27 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
#include<iostream>
#include<fstream>
#include<string>
#include<bits/stdc++.h>
#include"algo.h"
#include"comp.h"
using namespace std;
// This function is used to write a record to the global database i.e our "data.txt" file...
// This done used file stream commands..
// These commands have simpler syntax and are self explanatory...
void write(record* Data , std::ofstream& fnew){
fnew<<Data->roll_no<<"\t"<<Data->name<<"\t"<<Data->lname<<"\t"<<Data->dept<<"\t"<<Data->email<<"\t"<<Data->password<<endl;
}
// This function is used to write an entire subdivision to the database..
void write_map(map<int ,map<int,record*> > m , std::ofstream& fnew){
map<int ,map<int,record*>>::iterator it = m.begin();
while(it != m.end()){
map<int , record*>::iterator itr = it->second.begin();
while(itr != it->second.end()){
write(itr->second , fnew);
++itr;
}
++it;
}
}
/* This is another crucial function for our program...
What does this function does is that if there are changes in our data and need to be updated to the global
database then this function writes those changes globally...
This is achieved by making chnages in the file "data.txt" ..
*/
void update_database(db g){
ofstream fnew("/home/ishan/project/data.txt");
write_map(g.btech , fnew);
write_map(g.mtech , fnew);
write_map(g.phd , fnew);
fnew.close();
}
/* This is a crucial function for the program as it takes roll no as a input
and checks whether the roll no is present or not
and then if not present it creates a record for that student... */
record* info(db g){
int r;
string n,d,e,p,nl;
cout<<"Enter your roll_no"<<endl;
cin>>r;
if(!valid_roll_no(r)){
cout<<"Enter a valid Roll no."<<endl;
return nullptr;
}
record* get = g.search(r);
cin.ignore();
if(get != nullptr){
cout<<"Student Already exists..."<<endl;
cout<<"Please login to continue.."<<endl;
return nullptr;
}
ofstream fout("/home/ishan/project/data.txt" , ios::app);
cout<<"Enter your First name"<<endl;
getline(cin,n);
cout<<"Enter your Last name"<<endl;
getline(cin,nl);
cout<<"Enter your department"<<endl;
getline(cin,d);
cout<<"Enter your e-mail"<<endl;
getline(cin,e);
cout<<"Create your password"<<endl;
getline(cin,p);
record* info = new record(r,n,nl,d,e,p);
return info;
}
// This function loads the entire database in a local database that is in our program through the file "data.txt" ...
void initialization(db* g){
ifstream fin("/home/ishan/project/data.txt");
int rl = -1;
string fname,lname,dept,email,password;
while(1){
fin>>rl>>fname>>lname>>dept>>email>>password;
if(fin.eof())
break;
record* temp = new record(rl,fname,lname,dept,email,password);
g->insert(temp);
}
fin.close();
}
// Here I am creating a vector function to extract branch and type of degree from roll no. for using in my hash map
vector<int> hash_func(int roll_no){
vector<int> v;
int deg = roll_no%10000000;
v.push_back(deg/1000000);
int dept;
dept = roll_no%1000000;
dept = dept/1000;
v.push_back(dept);
v.push_back(roll_no%1000);
return v;
}
// Validity of the input i.e the roll no is checked through this function
bool valid_roll_no(int r){
string s = to_string(r);
int l = s.length();
if(l==9)
return true;
return false;
}