Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<fstream>
- #include <iomanip>
- #include <vector>
- #include <Windows.h>
- #include<stdlib.h>
- #include <string>
- using namespace std;
- ////////////////////////////////////////////////////////////
- // STRUCTURES //
- ////////////////////////////////////////////////////////////
- struct Student
- {
- string name;
- string id;
- int sectionNum;
- string academic_year;
- vector<double> grades;
- string totalGrade;
- double totalGPA;
- };
- ////////////////////////////////////////////////////////////
- // GLOBAL VARS //
- ////////////////////////////////////////////////////////////
- bool isRunning = true;
- string c_AcademicYear = "";
- string c_Year = "";
- ////////////////////////////////////////////////////////////
- // FUNCTION DEFINITIONS //
- ////////////////////////////////////////////////////////////
- void mainUI();
- template<typename T>
- void inputW_errorHandle(T &x,int maxnum,int minnum);
- void load_AcademicYear(string &A_Y);
- void adminPanel();
- void adminMenu();
- void admin_AddAcademicYear();
- bool ifExists(string a_yname);
- ////////////////////////////////////////////////////////////
- // M A I N //
- ////////////////////////////////////////////////////////////
- int main()
- {
- while (isRunning)
- {
- mainUI();
- cout <<" [1] Load Academic Year"<<endl
- <<" [2] Load Division"<<endl
- <<" [3] Search For Student"<<endl
- <<" [4] View All Students Info"<<endl
- <<" [5] Admin Panel (Add,Delete,Edit)"<<endl
- <<"------------------------------------------------------------------------"<<endl
- <<"Your Choice : ";
- int c;
- inputW_errorHandle(c,5,1);
- switch (c)
- {
- case 1:
- load_AcademicYear(c_AcademicYear);
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- adminPanel();
- break;
- }
- }
- return 0;
- }
- ////////////////////////////////////////////////////////////
- // FUNCTIONS //
- ////////////////////////////////////////////////////////////
- template<typename T> // This means that the function can use any datatype
- void inputW_errorHandle(T &x, int maxnum,int minnum)
- {
- while(!(cin >> x) || (x>maxnum || x<minnum))
- {
- cin.clear();
- cin.ignore(1000, '\n');
- cout << "Invalid input. Please enter a number from ("<<minnum<<"-"<<maxnum<< "). Try again: ";
- }
- }
- bool ifExists(string f_name)
- {
- ifstream file;
- file.open(f_name.c_str());
- if (file.is_open())
- {
- file.close();
- return true;
- }
- else
- return false;
- }
- void mainUI()
- {
- if (c_AcademicYear=="")
- {
- c_AcademicYear="None";
- c_Year="None";
- }
- if (c_AcademicYear !="" && c_Year=="")
- c_Year="None";
- system("cls");
- cout <<"////////////////////////////////////////////////////////////////////////"<<endl
- <<"//"<<"\t\t S T U D E N T M A N A G E M E N T"<<" \t //"<<endl
- <<"////////////////////////////////////////////////////////////////////////"<<endl;
- cout <<" \t\t Currently Loaded Academic Year: "<<c_AcademicYear<<endl;
- cout <<" \t\t Currently Loaded Divsion: "<<c_Year<<endl;
- cout <<"------------------------------------------------------------------------"<<endl;
- }
- void load_AcademicYear(string &A_Y)
- {
- mainUI();
- }
- void adminMenu()
- {
- mainUI();
- cout <<" [1] Add Academic Year"<<endl
- <<" [2] Add Student"<<endl
- <<" [3] Delete Student Info"<<endl
- <<" [4] Edit Student Info"<<endl
- <<" [5] User Panel "<<endl
- <<"------------------------------------------------------------------------"<<endl
- <<"Your Choice : ";
- int n;
- inputW_errorHandle(n,5,1);
- switch (n)
- {
- case 1:
- admin_AddAcademicYear();
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- break;
- case 5:
- break;
- }
- }
- void adminPanel()
- {
- mainUI();
- string n , p;
- cout <<"Username : ";
- cin>>n;
- cout <<"Password : ";
- cin>>p;
- if ((n=="tohamy" && p=="tohamyfcis") || (n=="moda" && p=="modafcis") || (n=="khafagy" && p=="khafagyfcis"))
- {
- cout <<"Login Successful !";
- Sleep(1000);
- adminMenu();
- }
- else
- {
- cout <<" Incorrect Login Information ! ";
- Sleep(1000);
- }
- }
- void admin_AddAcademicYear()
- {
- mainUI();
- char choice;
- string year;
- do
- {
- cout << "Please enter the academic year number you want to add : ";
- int a_y;
- inputW_errorHandle(a_y,2015,1900);
- year = to_string(a_y) +"-" +to_string(a_y+1);
- string fnamecheck = year+".txt";
- if(ifExists(fnamecheck))
- {
- cout <<"Academic Year Already Exists. Please retry !\n";
- choice = 'n';
- }
- else
- {
- cout << "Is this ok ? ["<<year<<"]";
- cin >>choice;
- }
- }
- while (choice=='n'||choice=='N');
- string temp = year;
- year = year+".txt";
- fstream file;
- file.open(year.c_str(),ios::out|ios::app);
- if (!file.is_open())
- {
- cout <<"Error Creating Academic Year !";
- Sleep(1000);
- }
- else
- {
- cout <<"Academic Year Created Successfully!";
- Sleep(1000);
- fstream file_y;
- file_y.open("Academic_Years.txt",ios::out|ios::app);
- if (!file_y.is_open())
- {
- cout <<"Error Registering Academic Year in Database !";
- remove(year.c_str());
- Sleep(1000);
- }
- else
- {
- file_y << temp<<endl;
- }
- file_y.close();
- file.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement