Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <windows.h>
- #include <conio.h>
- #include "header.h"
- using namespace std;
- int main()
- {
- system("color 0a");
- int i,c=0,attempt = 3,max = 10,auth = 1;
- string uname,pass,a,b;
- string str;
- ifstream Uname,Pass;
- ofstream u,p;
- Manage *ptr,*temp;
- ptr = new Manage [max];
- temp = ptr;
- au();
- ifstream ufile("u.txt"),pfile("p.txt");
- if(!ufile.good() || !pfile.good())
- {
- ufile.close();
- pfile.close();
- string admin = "admin";
- u.open("u.txt");
- p.open("p.txt");
- admin = encrypt(admin);
- u << admin;
- p << admin;
- u.close();
- p.close();
- }
- Uname.open("u.txt");
- Pass.open("p.txt");
- Uname >> a;
- Pass >> b;
- a = decrypt(a);
- b = decrypt(b);
- Uname.close();
- Pass.close();
- do
- {
- ptr = temp;
- while(auth == 0)
- {
- char ch;
- pass = "";
- if(attempt == 3)
- {
- cout << "Default username password is admin : admin" << endl;
- }
- cout << "Enter Username : ";
- cin >> uname;
- cout << "Enter Password : ";
- ch = _getch();
- while(ch != 13)
- {
- pass.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- cout << endl;
- if(uname == a && pass == b)
- {
- cout << "Login successful ! ";
- cout << "\nLoading =";
- for(int i=0;i<30;i++)
- {
- cout << "-" ;
- Sleep(100);
- }
- cout << "\nSuccessfully loaded ! " << endl;
- auth++;
- system("pause");
- system("cls");
- }
- else
- {
- if(attempt == 0)
- {
- goto end;
- }
- cout << "Invalid username or password ! " << attempt << " attempts left ! " << endl;
- attempt--;
- }
- }
- system("cls");
- au();
- cout << "Enter\n1 to add student\n2 to add acadamic activities\n3 to add non acadamic activities\n4 to show profile\n5 to show result\n6 to show non acadamic activities";
- cout << "\n7 to delete a student\n8 to register for a new semester\n9 to edit a student\n10 to append current data with previous data\n11 to save data\n12 to load data\n13 to update username and password" << "\n0 to exit !" << endl;
- while(!(cin >> c))
- {
- cin.clear();
- cin.ignore();
- cout << "Invalid input ! Try again : ";
- }
- if(c==1)
- {
- ptr->Manage::setData();
- }
- else if(c==2)
- {
- ptr->Acadamic::setData();
- }
- else if(c==3)
- {
- ptr->nonAcadamic::setData();
- }
- else if (c == 4)
- {
- ptr->Student::getData();
- }
- else if(c==5)
- {
- ptr->Acadamic::getData();
- }
- else if(c==6)
- {
- ptr->nonAcadamic::getData();
- }
- else if(c==7)
- {
- ptr->del();
- }
- else if( c == 8 )
- {
- ptr->Register();
- }
- else if ( c== 9)
- {
- ptr->edit();
- }
- else if(c == 10)
- {
- ptr->append();
- }
- else if (c == 11)
- {
- ptr->append();
- }
- else if (c == 12)
- {
- ptr->save();
- }
- else if (c == 13)
- {
- auth = 0;
- while(auth == 0)
- {
- char ch;
- pass = "";
- cout << "Enter current username : ";
- cin >> uname;
- cout << "Enter current password : ";
- ch = _getch();
- while(ch != 13)
- {
- pass.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- if(uname == a && pass == b)
- {
- pass = "";
- cout << endl << "Enter new username : ";
- cin >> uname;
- cout << "Enter new password : ";
- ch = _getch();
- while(ch != 13)
- {
- pass.push_back(ch);
- cout << '*';
- ch = _getch();
- }
- u.open("u.txt");
- p.open("p.txt");
- uname = encrypt(uname);
- pass = encrypt(pass);
- u << uname;
- p << pass;
- u.close();
- p.close();
- auth++;
- cout << endl << "Username and password updated ! ";
- }
- else
- {
- if(attempt == 0)
- {
- goto end;
- }
- cout << "Invalid username or password ! " << attempt << " attempts left ! " << endl;
- attempt--;
- }
- }
- }
- system("pause");
- system("cls");
- }
- while(c != 0);
- if(c == 0)
- {
- abc:
- cout << "Do you want to save data ? \nEnter\n1 to save data\n2 to append current data with previous one\n0 to exit without saving !";
- cin >> c;
- if(c == 1)
- {
- ptr->save();
- }
- else if(c == 2)
- {
- ptr->append();
- }
- else if(c == 0)
- {
- system("cls");
- cout << "Thanks for using our software ! Bye !" << endl;
- }
- else
- {
- cout << "Enter Again ! ";
- system("pause");
- goto abc;
- }
- }
- end:
- if(attempt == 0)
- {
- cout << "Login Failed ! Exiting ";
- }
- }
- =================================================================================
- ///////////////////////////////////// HEADER.H ///////////////////////////////////
- ---------------------------------------------------------------------------------
- _________________________________________________________________________________
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- int total = 0;
- class Manage;
- class Student
- {
- protected:
- int cs,num;
- string name,no,dept;
- public:
- int id;
- Student()
- {
- cs = 1;
- }
- void getData()
- {
- system("cls");
- Student *ptr;
- ptr = this;
- for(int i=0;i<=total;i++)
- {
- if(ptr->id!=0)
- {
- ptr->getID();
- ptr->getName();
- ptr->getNo();
- ptr->getDept();
- }
- ptr++;
- }
- }
- void getID()
- {
- cout << "ID : " << this->id << endl;
- }
- void getName()
- {
- cout << "Name : " << this->name << endl;
- }
- void getNo()
- {
- cout << "Contact no. : " << this->no << endl;
- }
- void getDept()
- {
- cout << "Department : " << this->dept << endl;
- }
- /////////////////////check if id is ZERO/////////////////////////////////
- int checkid()
- {
- if(id == 0)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- /////////////////////////////Input validation check////////////////////////////////
- int check(int x = 0)
- {
- while(!(cin >> x) || x < 0)
- {
- cin.clear();
- cin.ignore();
- cout << "Invalid input ! Try again : ";
- }
- return x;
- }
- };
- ///////// ACADAMIC /////////
- struct Subjects
- {
- int name,quiz,as,proj,exams;
- };
- class Acadamic : public virtual Student
- {
- protected:
- Subjects sub[6];
- float cgpa,gpa[8];
- public:
- void setData()
- {
- system("cls");
- Acadamic *ptr;
- ptr = this;
- ptr->setSub();
- ptr->calGpa();
- }
- void setSub()
- {
- cout << "Total marks are 100 " << endl;
- for(int i=0;i<6;i++)
- {
- cout << "Enter name of subject : ";
- cin >> sub[i].name;
- cout << "Enter marks of quizes : ";
- sub[i].quiz = Acadamic::check() ;
- cout << "Enter marks of assignments : ";
- sub[i].as = Acadamic::check() ;
- cout << "Enter marks of project : ";
- sub[i].proj = Acadamic::check() ;
- cout << "Enter marks of exams : ";
- sub[i].exams = Acadamic::check() ;
- }
- }
- void calGpa()
- {
- gpa[cs] = 0;
- for(int i=0;i<6;i++)
- {
- gpa[cs] = gpa [cs] + sub[i].quiz + sub[i].as + sub[i].proj + sub[i].exams;
- }
- gpa[cs] = gpa[cs] / 100;
- this->calCgpa();
- }
- void calCgpa()
- {
- cgpa = 0.0;
- for(int i=0;i<cs;i++)
- {
- cgpa = cgpa + gpa[i];
- }
- cgpa = cgpa / cs;
- }
- //////////////////getData///////////////////////////////
- void getData()
- {
- Acadamic *ptr;
- ptr = this;
- header();
- for(int i=0;i<total;i++)
- {
- if(ptr->id!=0)
- {
- getNum();
- ptr->getID();
- ptr->getName();
- ptr->getNo();
- ptr->getCS();
- ptr->getCGPA();
- ptr->getGPA();
- cout << endl << "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
- }
- ptr++;
- }
- }
- void getNum()
- {
- num++;
- cout << " " << left << setw(5) << num << left << setw(2) << "|";
- }
- void getID()
- {
- cout << left << setw(7) << id << left << setw(2) << "|";
- }
- void getName()
- {
- cout << left << setw(19) << name << left << setw(2) << "|";
- }
- void getNo()
- {
- cout << left << setw(15) << no << left << setw(5) << "|";
- }
- void getCS()
- {
- cout << left << setw(6) << cs << left << setw(2) << "|";
- }
- void getCGPA()
- {
- cout << fixed << setprecision(2) << left << setw(5) << cgpa << left << setw(2) << "|";
- }
- void getGPA()
- {
- for(int j=0;j<cs;j++)
- {
- cout << left << setw(7) << gpa[j]<< left << setw(2) << "|";
- }
- }
- ////////////Header//////////////
- void header()
- {
- system("cls");
- num = 0;
- cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
- cout << " " << left << setw(5) << "No." << left << setw(4) << "|";
- cout << left << setw(5) << "ID" << left << setw(9) << "|";
- cout << left << setw(12) << "Name" << left << setw(5) << "|";
- cout << left << setw(12) << "Contact"<< left << setw(2) << "|";
- cout << left << setw(9) << "Semester"<< left << setw(2) << "|";
- cout << left << setw(5) << "CGPA" << left << setw(2) << "|";
- for(int i=0;i<8;i++)
- {
- cout << left << setw(0) << "GPA("<<setw(0)<<i+1<<setw(2)<< ")" << left << setw(2) << "|";
- }
- cout << endl << "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
- }
- //////////get single student data//////////
- void get()
- {
- Acadamic *ptr;
- ptr = this;
- getNum();
- ptr->getID();
- ptr->getName();
- ptr->getNo();
- ptr->getCS();
- ptr->getCGPA();
- ptr->getGPA();
- cout << endl << "---------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
- }
- int check(int x = 0)
- {
- while(!(cin >> x) || x < 0 || x > 100)
- {
- cin.clear();
- cin.ignore();
- cout << "Invalid input ! Try again : ";
- }
- return x;
- }
- };
- ///////// NON-ACADAMIC /////////
- class nonAcadamic : public virtual Student
- {
- protected:
- string name,pos,role;
- public:
- void setData()
- {
- nonAcadamic *ptr;
- ptr = this;
- ptr->setName();
- ptr->setPos();
- ptr->setRole();
- }
- void setName()
- {
- cout << "Enter name of event : ";
- cin >> name;
- }
- void setPos()
- {
- cout << "Enter position : ";
- cin >> pos;
- }
- void setRole()
- {
- cout << "Enter role : ";
- cin >> role;
- }
- void getData()
- {
- nonAcadamic *ptr;
- ptr = this;
- for(int i=0;i<total;i++)
- {
- if(ptr->id!=0)
- {
- ptr->getName();
- ptr->getPos();
- ptr->getRole();
- }
- ptr++;
- }
- }
- void getName()
- {
- cout << "Name of event : " << this->name << endl;
- }
- void getPos()
- {
- cout << "Position : " << this->pos << endl;
- }
- void getRole()
- {
- cout << "Role : " << this->role << endl << endl;
- }
- };
- ///////// Manage /////////
- class Manage : public nonAcadamic, public Acadamic
- {
- protected:
- public:
- ////////////////setData//////////
- /////////////setData////////////////////
- void setData()
- {
- system("cls");
- Manage *ptr;
- ptr = this;
- int x=0;
- while (x == 0)
- {
- system("cls");
- if(ptr->id == 0)
- {
- ptr->setID();
- ptr->setName();
- ptr->setNo();
- ptr->setDept();
- total++;
- x++;
- }
- ptr++;
- }
- }
- void setID()
- {
- cout << "Enter ID : ";
- id = check();
- }
- void setName()
- {
- cout << "Enter name : ";
- cin.ignore();
- getline(cin,name);
- }
- void setNo()
- {
- cout << "Enter contact no. : ";
- cin >> no;
- }
- void setDept()
- {
- cout << "Enter department : ";
- cin >> dept;
- }
- //////////////Search///////////
- void search()
- {
- float Gpa;
- string Name;
- int ser,Id,count=0;
- Manage *ptr;
- ptr = this;
- search:
- system("cls");
- cout << "Enter\n1 to Search by GPA\n2 to Search by Name\n3 to Search all who are above 3.5 GPA\n";
- cout << "4 to Search all who are under serious warning (i.e. CGPA below 1.8)\n5 to Search all who are under warning ";
- cout << "(i.e. CGPA below 2.0 and above 1.8)\n6 to Search by ID " << endl;
- cin >> ser;
- if(ser==1)
- {
- cout << "Enter GPA to search : ";
- cin >> Gpa;
- }
- else if (ser==2)
- {
- cout << "Enter name to search : ";
- cin >> Name;
- }
- else if(ser==6)
- {
- cout << "Enter ID to search : ";
- cin >> Id;
- }
- else if (ser < 1 || ser > 6)
- {
- cout << "Wrong choice ! " << endl;
- system("pause");
- goto search;
- }
- header();
- for(int j=0;j<total;j++)
- {
- if(ser == 1)
- {
- for(int i=0;i<ptr->cs;i++)
- {
- if(Gpa == ptr->gpa[i])
- {
- ptr->get();
- count++;
- }
- }
- }
- else if(ser == 2)
- {
- if(Name == ptr->name)
- {
- ptr->get();
- count++;
- }
- }
- else if(ser == 3)
- {
- for(int i=0;i<ptr->cs;i++)
- {
- if(ptr->gpa[i] > 3.5)
- {
- ptr->get();
- count++;
- }
- }
- }
- else if(ser == 4)
- {
- for(int i=0;i<ptr->cs;i++)
- {
- if(ptr->gpa[i] < 1.8)
- {
- ptr->get();
- count++;
- }
- }
- }
- else if(ser == 5)
- {
- for(int i=0;i<ptr->cs;i++)
- {
- if(ptr->gpa[i] < 2.0 && ptr->gpa[i] > 1.8)
- {
- ptr->get();
- count++;
- }
- }
- }
- else if(ser == 6)
- {
- if(Id == ptr->id)
- {
- ptr->get();
- count++;
- }
- }
- ptr++;
- }
- if(count == 0)
- {
- cout << "Error 404 ! Not found !";
- }
- }
- void dell()
- {
- Manage *ptr;
- ptr = this;
- ptr->id=0;
- ptr->cgpa=0;
- for(int i=0;i<ptr->cs;i++)
- {
- ptr->gpa[i] = 0.0;
- }
- ptr->cs=0;
- ptr->name = "Delete";
- ptr->no = "090078601";
- }
- void del()
- {
- Manage *ptr;
- ptr = this;
- int Id,count,ser;
- string Name;
- edit:
- system("cls");
- cout << "Enter 1 to delete by name,2 to edit by ID : " << endl;
- cin >> ser;
- if(ser==1)
- {
- cout << "Enter student name to delete : ";
- cin >> Name;
- }
- else if (ser==2)
- {
- cout << "Enter student ID to delete : ";
- cin >> Id;
- }
- else
- {
- cout << "Wrong choice ! " << endl;
- system("pause");
- goto edit;
- }
- for(int i=0;i<total;i++)
- {
- if(Id == ptr->id)
- {
- ptr->dell();
- cout << "Deleted !" << endl;
- count++;
- }
- else if(Name == ptr->name)
- {
- ptr->dell();
- cout << "Deleted !" << endl;
- count++;
- }
- ptr++;
- }
- if(count == 0)
- {
- cout << "Student not found ! " << endl;
- }
- }
- void Register()
- {
- system("cls");
- char c;
- cout << "Do you want to register for next course ? (Enter y or n):";
- cin >> c;
- if(c == 'y')
- {
- if(this->gpa[cs] > 2.0)
- {
- this->cs++;
- }
- else
- {
- cout << "You can not register for this course ! ";
- }
- }
- else if(c == 'n')
- {
- }
- else
- {
- cout << "Invalid choice ! ";
- system("pause");
- this->Register();
- }
- }
- void edit()
- {
- Manage *ptr;
- ptr = this;
- int Id,count,ser;
- string Name;
- edit:
- system("cls");
- cout << "Enter 1 to edit by name,2 to edit by ID : " << endl;
- cin >> ser;
- if(ser==1)
- {
- cout << "Enter student name to edit : ";
- cin >> Name;
- }
- else if (ser==2)
- {
- cout << "Enter student ID to edit : ";
- cin >> Id;
- }
- else
- {
- cout << "Wrong choice ! " << endl;
- system("pause");
- goto edit;
- }
- for(int i=0;i<total;i++)
- {
- if(Id == ptr->id)
- {
- ptr->Manage::setData();
- count++;
- }
- else if(Name == ptr->name)
- {
- ptr->Manage::setData();
- count++;
- }
- ptr++;
- }
- if(count == 0)
- {
- cout << "Student not found ! " << endl;
- }
- }
- /////////////////////////////////////////////// File Handling /////////////////////////////////////////////////////////////////////////////////
- //////////////////Append/////////////////////////
- void append()
- {
- Manage *ptr;
- ptr = this;
- ofstream Id,Name,dept,Gpa,Cgpa,No,Cs,Subj;
- Id.open("id.txt",fstream::app);
- Name.open("name.txt",fstream::app);
- dept.open("dept.txt",fstream::app);
- Gpa.open("gpa.txt",fstream::app);
- Cgpa.open("cgpa.txt",fstream::app);
- No.open("no.txt",fstream::app);
- Cs.open("cs.txt",fstream::app);
- Subj.open("subj.txt",fstream::app);
- for(int i=0;i<total;i++)
- {
- if(ptr->id != 0)
- {
- Cs << ptr->cs << endl;
- Id << ptr->id << endl;
- Name << ptr->name << endl;
- for(int j=0;j<ptr->cs;j++)
- {
- Gpa << ptr->gpa[j] <<"\t";
- }
- Gpa << endl;
- Name << ptr->dept << endl;
- for(int j=0;j<ptr->cs;j++)
- {
- Subj << ptr->sub[j].as << endl;
- Subj << ptr->sub[j].exams << endl;
- Subj << ptr->sub[j].name << endl;
- Subj << ptr->sub[j].proj << endl;
- Subj << ptr->sub[j].quiz << endl;
- }
- Cgpa << ptr->cgpa << endl;
- No << ptr->no << endl;
- }
- ptr++;
- }
- Id.close();
- Name.close();
- dept.close();
- Gpa.close();
- Cgpa.close();
- No.close();
- Cs.close();
- cout << "Successfully appended data in txt file ! ";
- }
- /////////////////Save/////////////////////
- void save()
- {
- Manage *ptr;
- ptr = this;
- ofstream Id,Name,Dept,Gpa,Cgpa,No,Cs,Subj;
- Id.open("id.txt");
- Name.open("name.txt");
- Dept.open("dept.txt");
- Gpa.open("gpa.txt");
- Cgpa.open("cgpa.txt");
- No.open("no.txt");
- Subj.open("subj.txt");
- Cs.open("cs.txt"); // n
- for(int i=0;i<total;i++)
- {
- if(ptr->id != 0)
- {
- Cs << ptr->cs << endl;
- Id << ptr->id << endl;
- Name << ptr->name << endl;
- for(int j=0;j<ptr->cs;j++)
- {
- Gpa << ptr->gpa[j] <<"\t";
- }
- Gpa << endl;
- Dept << ptr->dept << endl;
- for(int j=0;j<ptr->cs;j++)
- {
- Subj << ptr->sub[j].as << endl;
- Subj << ptr->sub[j].exams << endl;
- Subj << ptr->sub[j].name << endl;
- Subj << ptr->sub[j].proj << endl;
- Subj << ptr->sub[j].quiz << endl;
- }
- Cgpa << ptr->cgpa << endl;
- No << ptr->no << endl;
- }
- ptr++;
- }
- Id.close();
- Name.close();
- Subj.close();
- Gpa.close();
- Cgpa.close();
- No.close();
- Cs.close();
- cout << "Successfully saved data in txt file ! ";
- }
- /////////////////load from file/////////////////////////
- void load()
- {
- Manage *ptr;
- ptr = this;
- ifstream Id,Name,Sem,Gpa,Cgpa,No,N,Subj;
- Id.open("id.txt");
- Name.open("name.txt");
- Sem.open("sem.txt");
- Gpa.open("gpa.txt");
- Cgpa.open("cgpa.txt");
- No.open("no.txt");
- Subj.open("subj.txt");
- N.open("cs.txt");
- if(Id.is_open())
- {
- while(!Id.eof())
- {
- if(ptr->id == 0)
- {
- Id >> ptr->id;
- if(ptr->id == 0)
- {
- break;
- }
- N >> ptr->cs;
- getline(Name,ptr->name);
- for(int j=0;j<ptr->cs;j++)
- {
- Gpa >> ptr->gpa[j];
- }
- Name >> ptr->dept;
- for(int j=0;j<ptr->cs;j++)
- {
- Subj >> ptr->sub[j].as;
- Subj >> ptr->sub[j].exams;
- Subj >> ptr->sub[j].name;
- Subj >> ptr->sub[j].proj;
- Subj >> ptr->sub[j].quiz;
- }
- Cgpa >> ptr->cgpa;
- No >> ptr->no;
- total++;
- }
- ptr++;
- }
- }
- cout << "Successfully loaded data from txt file ! ";
- Id.close();
- Name.close();
- Sem.close();
- Gpa.close();
- Cgpa.close();
- No.close();
- N.close();
- }
- };
- ////////// FUNCTIONS ////////////
- void au()
- {
- cout << "\t\t _ _ _ _ _ _ " << endl;
- cout << "\t\t /\\ (_) | | | | (_) (_) | " << endl;
- cout << "\t\t / \\ _ _ __ | | | |_ __ ___ _____ _ __ ___ _| |_ _ _ " << endl;
- cout << "\t\t / /\\ \\ | | '__| | | | | '_ \\| \\ \\ / / _ \\ '__/ __| | __| | | |" << endl;
- cout << "\t\t / ____ \\| | | | |__| | | | | |\\ V / __/ | \\__ \\ | |_| |_| |" << endl;
- cout << "\t\t /_/ \\_\\_|_| \\____/|_| |_|_| \\_/ \\___|_| |___/_|\\__|\\__, |" << endl;
- cout << "\t\t __/ |" << endl;
- cout << "\t\t |___/ " << endl;
- cout << endl << "\t\t Welcome to Air University Students Managment System v1.0" << endl;
- cout << "\t\t ________________________________________________________" << endl;
- }
- string encrypt (string a)
- {
- for(int i=0;i<a.length();i++)
- {
- a.at(i) = a.at(i) + i - 64;
- }
- return a;
- }
- string decrypt (string a)
- {
- for(int i=0;i<a.length();i++)
- {
- a.at(i) = a.at(i) - i + 64;
- }
- return a;
- }
Add Comment
Please, Sign In to add comment