Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.22 KB | None | 0 0
  1. #include <iostream>
  2. #include<fstream>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <Windows.h>
  6. #include<stdlib.h>
  7. #include <string>
  8. using namespace std;
  9. ////////////////////////////////////////////////////////////
  10. //                      STRUCTURES                        //
  11. ////////////////////////////////////////////////////////////
  12. struct Student
  13. {
  14.     string name;
  15.     string id;
  16.     int sectionNum;
  17.     string academic_year;
  18.     vector<double> grades;
  19.     string totalGrade;
  20.     double totalGPA;
  21. };
  22.  
  23.  
  24. ////////////////////////////////////////////////////////////
  25. //                      GLOBAL VARS                       //
  26. ////////////////////////////////////////////////////////////
  27. bool isRunning = true;
  28. string c_AcademicYear = "";
  29. string c_Year = "";
  30. ////////////////////////////////////////////////////////////
  31. //                  FUNCTION  DEFINITIONS                 //
  32. ////////////////////////////////////////////////////////////
  33. void mainUI();
  34.  
  35. template<typename T>
  36. void inputW_errorHandle(T &x,int maxnum,int minnum);
  37.  
  38. void load_AcademicYear(string &A_Y);
  39. void adminPanel();
  40. void adminMenu();
  41. void admin_AddAcademicYear();
  42. bool ifExists(string a_yname);
  43. ////////////////////////////////////////////////////////////
  44. //                      M A I N                           //
  45. ////////////////////////////////////////////////////////////
  46. int main()
  47. {
  48.     while (isRunning)
  49.     {
  50.         mainUI();
  51.         cout <<" [1] Load Academic Year"<<endl
  52.             <<" [2] Load Division"<<endl
  53.             <<" [3] Search For Student"<<endl
  54.             <<" [4] View All Students Info"<<endl
  55.             <<" [5] Admin Panel (Add,Delete,Edit)"<<endl
  56.             <<"------------------------------------------------------------------------"<<endl
  57.             <<"Your Choice : ";
  58.         int c;
  59.         inputW_errorHandle(c,5,1);
  60.         switch (c)
  61.         {
  62.             case 1:
  63.                 load_AcademicYear(c_AcademicYear);
  64.                 break;
  65.  
  66.             case 2:
  67.                 break;
  68.  
  69.             case 3:
  70.                 break;
  71.  
  72.             case 4:
  73.                 break;
  74.  
  75.             case 5:
  76.                 adminPanel();
  77.                 break;
  78.         }
  79.        
  80.     }
  81.    
  82.  
  83.  
  84.     return 0;
  85. }
  86.  
  87.  
  88. ////////////////////////////////////////////////////////////
  89. //                       FUNCTIONS                        //
  90. ////////////////////////////////////////////////////////////
  91.  
  92. template<typename T>  // This means that the function can use any datatype
  93. void inputW_errorHandle(T &x, int maxnum,int minnum)
  94. {
  95.     while(!(cin >> x) || (x>maxnum || x<minnum))
  96.     {
  97.         cin.clear();
  98.         cin.ignore(1000, '\n');
  99.         cout << "Invalid input. Please enter a number from ("<<minnum<<"-"<<maxnum<<  "). Try again: ";
  100.     }
  101. }
  102.  
  103. bool ifExists(string f_name)
  104. {
  105.     ifstream file;
  106.     file.open(f_name.c_str());
  107.  
  108.     if (file.is_open())
  109.     {
  110.         file.close();
  111.         return true;
  112.     }
  113.     else
  114.         return false;
  115.  
  116.  
  117. }
  118.  
  119. void mainUI()
  120. {
  121.     if (c_AcademicYear=="")
  122.     {
  123.         c_AcademicYear="None";
  124.         c_Year="None";
  125.     }
  126.     if (c_AcademicYear !="" && c_Year=="")
  127.         c_Year="None";
  128.  
  129.     system("cls");
  130.         cout <<"////////////////////////////////////////////////////////////////////////"<<endl
  131.             <<"//"<<"\t\t  S T U D E N T   M A N A G E M E N T"<<"   \t      //"<<endl
  132.              <<"////////////////////////////////////////////////////////////////////////"<<endl;
  133.         cout <<"  \t\t Currently Loaded Academic Year: "<<c_AcademicYear<<endl;
  134.         cout <<" \t\t Currently Loaded Divsion: "<<c_Year<<endl;
  135.         cout <<"------------------------------------------------------------------------"<<endl;
  136. }
  137.  
  138. void load_AcademicYear(string &A_Y)
  139. {
  140.     mainUI();
  141.    
  142.  
  143. }
  144.  
  145. void adminMenu()
  146. {
  147.     mainUI();
  148.     cout <<" [1] Add Academic Year"<<endl
  149.             <<" [2] Add Student"<<endl
  150.             <<" [3] Delete Student Info"<<endl
  151.             <<" [4] Edit Student Info"<<endl
  152.             <<" [5] User Panel "<<endl
  153.             <<"------------------------------------------------------------------------"<<endl
  154.             <<"Your Choice : ";
  155.     int n;
  156.     inputW_errorHandle(n,5,1);
  157.     switch (n)
  158.         {
  159.             case 1:
  160.                 admin_AddAcademicYear();
  161.                 break;
  162.  
  163.             case 2:
  164.                 break;
  165.  
  166.             case 3:
  167.                 break;
  168.  
  169.             case 4:
  170.                 break;
  171.  
  172.             case 5:
  173.                 break;
  174.         }
  175.  
  176. }
  177.  
  178. void adminPanel()
  179. {
  180.     mainUI();
  181.     string n , p;
  182.     cout <<"Username : ";
  183.     cin>>n;
  184.     cout <<"Password : ";
  185.     cin>>p;
  186.     if ((n=="tohamy" && p=="tohamyfcis") || (n=="moda" && p=="modafcis") || (n=="khafagy" && p=="khafagyfcis"))
  187.     {
  188.         cout <<"Login Successful !";
  189.         Sleep(1000);
  190.         adminMenu();
  191.     }
  192.  
  193.     else
  194.     {
  195.         cout <<" Incorrect Login Information ! ";
  196.         Sleep(1000);
  197.     }
  198.  
  199. }
  200.  
  201. void admin_AddAcademicYear()
  202. {
  203.     mainUI();
  204.     char choice;
  205.     string year;
  206. do
  207. {
  208.     cout << "Please enter the academic year number you want to add : ";
  209.     int a_y;
  210.     inputW_errorHandle(a_y,2015,1900);
  211.      year = to_string(a_y) +"-" +to_string(a_y+1);
  212.      string fnamecheck = year+".txt";
  213.      if(ifExists(fnamecheck))
  214.      {
  215.          cout <<"Academic Year Already Exists. Please retry !\n";
  216.          choice = 'n';
  217.      }
  218.      else
  219.      {
  220.     cout << "Is this ok ? ["<<year<<"]";
  221.     cin >>choice;
  222.      }
  223. }
  224. while (choice=='n'||choice=='N');
  225.     string temp = year;
  226.     year = year+".txt";
  227.     fstream file;
  228.     file.open(year.c_str(),ios::out|ios::app);
  229.  
  230.     if (!file.is_open())
  231.     {
  232.         cout <<"Error Creating Academic Year !";
  233.         Sleep(1000);
  234.     }
  235.     else
  236.     {
  237.         cout <<"Academic Year Created Successfully!";
  238.         Sleep(1000);
  239.         fstream file_y;
  240.         file_y.open("Academic_Years.txt",ios::out|ios::app);
  241.         if (!file_y.is_open())
  242.         {
  243.             cout <<"Error Registering Academic Year in Database !";
  244.             remove(year.c_str());
  245.             Sleep(1000);
  246.         }
  247.  
  248.         else
  249.         {
  250.             file_y << temp<<endl;
  251.         }
  252.         file_y.close();
  253.         file.close();
  254.     }
  255.  
  256.    
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement