You are on page 1of 9

#include<iostream>

#include<ios>
#include<string>
#include<stdio.h>
#include<fstream>
using namespace std;
struct result
{
string username;
string term;
int no_of_courses;
int marks;
float percentage;
};
struct timetable
{
string username;
string slots[7];
};
class student
{
private:
string clas;
string section;
string rollno;
string fathername;
string name;
string department;
string username;
string password;
public:
friend class you;
friend istream& operator >> (istream& isobj , student& st);
//friend ofstream& operator << (ofstream& fobj , student& st);
friend ostream& operator << (ostream& obj, student& st);
};
istream& operator >> (istream& isobj, student& st)
{
cout << endl << "Enter Name::.";
getline(isobj, st.name);
cout << endl << "Enter Father Name::.";
getline(isobj,st.fathername);
cout << endl << "Enter Class::.";
getline(isobj,st.clas);
cout << endl << "Enter Section::.";
getline(isobj,st.section);
cout << endl << "Enter Roll NO. ::.";
getline(isobj,st.rollno);
cout << endl << "Enter Department::.";
getline(isobj,st.department);
return isobj;
}
ostream& operator << (ostream& obj, student& st)
{
obj << "\nUser Name: " << st.username << endl;
obj << "\nName: " << st.name << endl;
obj << "\nFather Name: " << st.fathername << endl;
obj << "\nClass: " << st.clas << endl;
obj << "\nSection: " << st.section << endl;
obj << "\nRoll no.: " << st.rollno << endl;
obj << "\nDepartment: " << st.department << endl;
return obj;
}

class you
{
public:
void viewprofile()
{
char ch;
int pos,flag,label;
string username;
student S;
do
{
flag=0;
system("CLS");
label:cout << "\nEnter user name of student to v
iew profile::.";
getline(cin,username);
ifstream view;
view.open("student.dat",ios::binary );
if(view.is_open())
{
while(!view.eof())
{
view.read( (char*)&S,sizeof(stud
ent));
if(!(S.username.compare(username
)))
{
flag=1;
break;
}
}
view.close();
}
else
{
cout << "\nUnable to open the file!!!" <
< endl;
cout << "error wala";system("pause");
}
if(flag)
cout << S;
else
cout << "\nInvalid Username";
cout << "\nDo you want to view another profile?
(Y/N)";
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
void add_st()
{
student S;
char ch=0;
string key;
string temp1,temp2;
char c;
do
{
int top;
top:system("CLS");
cout << "\n\n****Student Record Entry****\n\n";
cin >> S;
int n;
ifstream ufile;
n:cout << "\nEnter a user name to be given to the student::.";
getline(cin,S.username);
ufile.open("usernames.dat",ios::binary);
if(ufile.is_open())
{
while( !ufile.eof() )
{
ufile.read( (char*)&temp1,sizeof(string));
if(!(temp1.compare(S.username)))
{
cout <<"\nNot a unique user name,can't b
e assigned";
ufile.close();
goto n;
}
}
ufile.close();
}
else
{
cout << "Unable to open file usernames"<<endl;
system("pause");
exit(1);
}
int h;
ifstream pfile;
h:cout << "\nEnter a password to be given to the student::.";
getline(cin,S.password);
pfile.open("passwords.dat",ios::binary);
if(pfile.is_open())
{
while( !pfile.eof() )
{
pfile.read( (char*)&temp2, sizeof(string));
if(!(temp2.compare(S.password)))
{
cout <<"\nNot a unique password, can't b
e assigned";
pfile.close();
goto h;
}
}
pfile.close();
}
else
{
cout << "unable to open file" << endl;
system("pause");
exit(1);
}
int label;
cout << "\nRecord you have entered is:" << endl;
cout << S;
label:cout << "\nPress W to add it to the record or C to make an
y changes in it" << endl;
cin >> c;
cin.ignore();
if (c=='W' || c=='w')
{
ofstream bfile;
bfile.open("student.dat", ios::binary | ios::app);
if(bfile.is_open())
{
bfile.write( (char*)&S,sizeof(student));
bfile.close();
}
else
{
cout << "unable to open file..." << endl;
system("pause");
exit(1);
}
ofstream mfile;
mfile.open("usernames.dat",ios::binary|ios::app);
if(mfile.is_open())
{
mfile.write( (char*)&S.username , sizeof(string)
);
mfile.close();
}
else
{
cout << "unable to open file..." << endl;
system("pause");
exit(1);
}
ofstream vfile;
vfile.open("passwords.dat",ios::binary|ios::app);
if(vfile.is_open())
{
vfile.write( (char*)&S.password , sizeof(string)
);
vfile.close();
}
else
{
cout << "unable to open file..." << endl;
system("pause");
exit(1);
}
key=S.username+S.password;
ofstream kfile;
kfile.open("skeys.dat",ios::binary | ios::app);
if(kfile.is_open())
{
kfile.write( (char*)&key,sizeof(string));
kfile.close();
}
else
{
cout << "unable to open file..." << endl;
system("pause");
exit(1);
}
}

else if(c=='C' || c=='c')


goto top;
else
{
cout << endl << "Invalid Choice"<< endl;
goto label;
}
cout << "\nDo you want to enter another record? (Y/N)";
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
void addresult()
{
struct result r;
int label,top;
char c, ch;
do
{
top:system("CLS");
cout << "\nEnter username of the student::. " ;
getline(cin,r.username);
cout << "\nEnter Term or Semester::. " ;
getline(cin,r.term);
cout << "\nEnter No. of courses::. " ;
cin >> r.no_of_courses;
cout << "\nEnter Marks::. ";
cin >> r.marks;
r.percentage= ((static_cast<float>(r.marks)) / (static_cast<floa
t>(r.no_of_courses*150))) *100 ; //considering each course has 150 marks
cout << "\nResult you have entered is:" << endl;
cout << "\nUsername: " << r.username << endl;
cout << "\nTerm/Semester: " << r.term << endl;
cout << "\nNo. of courses: " << r.no_of_courses << endl;
cout << "\nMarks: " << r.marks << " out of " << (150 * r.no_of_c
ourses) << endl;
cout << "\nPercentage: " << r.percentage << "%" << endl;
label:cout << "\nPress W to add it to the record or C to make an
y changes in it" << endl;
cin >> c;
cin.ignore();
if (c=='W' || c=='w')
{
ofstream res;
res.open("results.dat",ios::binary | ios::app);
if (res.is_open())
{
res.write( (char*)&r , sizeof(struct result) );
res.close();
}
else
{
cout << "\nUnable to open file!!!" << endl;
system("pause");
exit(1);
}
}
else if(c=='C' || c=='c')
goto top;
else
{
cout << endl << "Invalid Choice"<< endl;
goto label;
}
cout << "\nDo you want to enter another result? (Y/N)";
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
void viewresult()
{
char ch;
struct result r;
string username;
do
{
system("CLS");
cout << "\nEnter username to view result::.";
getline(cin,username);

ifstream viewr;
viewr.open("results.dat",ios::binary);
if (viewr.is_open())
{
while(!viewr.eof())
{
viewr.read( (char*)&r , sizeof(struct re
sult) );
if(!(r.username.compare(username)))
break;
}
viewr.close();
}
else
{
cout << "\nUnable to open file!!!" << endl;
system("pause");
exit(1);
}
cout << "\nUsername: " << r.username << endl;
cout << "\nTerm/Semester: " << r.term << endl;
cout << "\nNo. of courses: " << r.no_of_courses << endl;
cout << "\nMarks: " << r.marks << " out of " << (150 * r
.no_of_courses) << endl;
cout << "\nPercentage: " << r.percentage << "%" << endl;
cout << "\nDo you want to view another result? (Y/N)";
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
void addtime_t()
{
struct timetable tt;
int label,top;
char c, ch;
do
{
top:system("CLS");
cout << "\nEnter username of the teacher::. " ;
getline(cin,tt.username);
cout << "\nEnter the code of course for the correspondin
g time slot:" << endl;
cout << "\nSlot no.1 (08:30-09:20) : ";
getline(cin,tt.slots[0]);
cout << "\nSlot no.2 (09:20-10:10) : ";
getline(cin,tt.slots[1]);
cout << "\nSlot no.3 (10:10-11:00) : ";
getline(cin,tt.slots[2]);
cout << "\nSlot no.4 (11:30-12:20) : ";
getline(cin,tt.slots[3]);
cout << "\nSlot no.5 (12:20-01:10) : ";
getline(cin,tt.slots[4]);
cout << "\nSlot no.6 (02:00-02:50) : ";
getline(cin,tt.slots[5]);
cout << "\nSlot no.7 (02:50-03:40) : ";
getline(cin,tt.slots[6]);
system("CLS");
cout << "\nTime Table you have entered is: " <<endl;
cout << "\nSlot no.1 (08:30-09:20) : " << tt.slots[0] <
< endl;
cout << "\nSlot no.2 (09:20-10:10) : " << tt.slots[1] <
< endl;
cout << "\nSlot no.3 (10:10-11:00) : " << tt.slots[2] <
< endl;
cout << "\nSlot no.4 (11:30-12:20) : " << tt.slots[3] <
< endl;
cout << "\nSlot no.5 (12:20-01:10) : " << tt.slots[4] <
< endl;
cout << "\nSlot no.6 (02:00-02:50) : " << tt.slots[5] <
< endl;
cout << "\nSlot no.7 (02:50-03:40) : " << tt.slots[6] <
< endl;
label:cout << "\nPress W to add it to the record or C to
make any changes in it" << endl;
cin >> c;
cin.ignore();
if (c=='W' || c=='w')
{
ofstream time;
time.open("ttimetables.dat",ios::binary | ios::a
pp);
if (time.is_open())
{
time.write( (char*)&tt , sizeof(struct t
imetable) );
time.close();
}
else
{
cout << "\nUnable to open file!!!" << en
dl;
system("pause");
exit(1);
}
}
else if(c=='C' || c=='c')
goto top;
else
{
cout << endl << "Invalid Choice"<< endl;
goto label;
}
cout << "\nDo you want to enter another timetable? (Y/N)
";
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
void viewtime_t()
{
char ch;
struct timetable tt;
string username;
do
{
system("CLS");
cout << "\nEnter username of teacher to view timetable::
.";
getline(cin,username);
ifstream viewt;
viewt.open("ttimetables.dat",ios::binary);
if (viewt.is_open())
{
while(!viewt.eof())
{
viewt.read( (char*)&tt , sizeof(struct t
imetable) );
if(!(tt.username.compare(username)))
break;
}
viewt.close();
}
else
{
cout << "\nUnable to open file!!!" << endl;
system("pause");
exit(1);
}
system("CLS");
cout << "\n\t\tTime Table is: " <<endl;
cout << "\nSlot no.1 (08:30-09:20) : " << tt.slots[0] <
< endl;
cout << "\nSlot no.2 (09:20-10:10) : " << tt.slots[1] <
< endl;
cout << "\nSlot no.3 (10:10-11:00) : " << tt.slots[2] <
< endl;
cout << "\nSlot no.4 (11:30-12:20) : " << tt.slots[3] <
< endl;
cout << "\nSlot no.5 (12:20-01:10) : " << tt.slots[4] <
< endl;
cout << "\nSlot no.6 (02:00-02:50) : " << tt.slots[5] <
< endl;
cout << "\nSlot no.7 (02:50-03:40) : " << tt.slots[6] <
< endl;
cout << "\nDo you want to view another timetable? (Y/N)"
;
cin >> ch;
cin.ignore();
}while (ch=='Y' || ch=='y');
}
};
int main()
{
you y;
y.add_st();
y.viewprofile();
//y.viewtime_t();
system("pause");
}

You might also like