Guest User

OOP Project

a guest
May 14th, 2018
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <windows.h>
  4. #include <conio.h>
  5. #include "header.h"
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     system("color 0a");
  11.     int i,c=0,attempt = 3,max = 10,auth = 1;
  12.     string uname,pass,a,b;
  13.     string str;
  14.     ifstream Uname,Pass;
  15.     ofstream u,p;
  16.     Manage *ptr,*temp;
  17.     ptr = new Manage [max];
  18.     temp = ptr;
  19.     au();
  20.     ifstream ufile("u.txt"),pfile("p.txt");
  21.     if(!ufile.good() || !pfile.good())
  22.     {
  23.         ufile.close();
  24.         pfile.close();
  25.         string admin = "admin";
  26.         u.open("u.txt");
  27.         p.open("p.txt");
  28.         admin = encrypt(admin);
  29.         u << admin;
  30.         p << admin;
  31.         u.close();
  32.         p.close();
  33.     }
  34.     Uname.open("u.txt");
  35.     Pass.open("p.txt");
  36.     Uname >> a;
  37.     Pass >> b;
  38.     a = decrypt(a);
  39.     b = decrypt(b);
  40.     Uname.close();
  41.     Pass.close();
  42.     do
  43.     {
  44.         ptr = temp;
  45.         while(auth == 0)
  46.         {
  47.             char ch;
  48.             pass = "";
  49.             if(attempt == 3)
  50.             {
  51.                 cout << "Default username password is admin : admin" << endl;
  52.             }
  53.             cout << "Enter Username : ";
  54.             cin >> uname;
  55.             cout << "Enter Password : ";
  56.             ch = _getch();
  57.             while(ch != 13)
  58.             {
  59.               pass.push_back(ch);
  60.               cout << '*';
  61.               ch = _getch();
  62.             }
  63.             cout << endl;
  64.             if(uname == a && pass == b)
  65.             {
  66.                 cout << "Login successful ! ";
  67.                 cout << "\nLoading =";
  68.                 for(int i=0;i<30;i++)
  69.                 {
  70.                     cout << "-" ;
  71.                     Sleep(100);
  72.                 }
  73.                 cout << "\nSuccessfully loaded ! " << endl;
  74.                 auth++;
  75.                 system("pause");
  76.                 system("cls");
  77.             }
  78.             else
  79.             {
  80.                 if(attempt == 0)
  81.                 {
  82.                     goto end;
  83.                 }
  84.                 cout << "Invalid username or password ! " << attempt << " attempts left ! " << endl;
  85.                 attempt--;
  86.             }
  87.         }
  88.         system("cls");
  89.         au();
  90.         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";
  91.         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;
  92.         while(!(cin >> c))
  93.         {
  94.             cin.clear();
  95.             cin.ignore();
  96.             cout << "Invalid input ! Try again : ";
  97.         }
  98.         if(c==1)
  99.         {
  100.             ptr->Manage::setData();
  101.         }
  102.         else if(c==2)
  103.         {
  104.             ptr->Acadamic::setData();
  105.         }
  106.         else if(c==3)
  107.         {
  108.             ptr->nonAcadamic::setData();
  109.         }
  110.         else if (c == 4)
  111.         {
  112.             ptr->Student::getData();
  113.         }
  114.         else if(c==5)
  115.         {
  116.             ptr->Acadamic::getData();
  117.         }
  118.         else if(c==6)
  119.         {
  120.             ptr->nonAcadamic::getData();
  121.         }
  122.         else if(c==7)
  123.         {
  124.             ptr->del();
  125.         }
  126.         else if( c == 8 )
  127.         {
  128.             ptr->Register();
  129.         }
  130.         else if ( c== 9)
  131.         {
  132.             ptr->edit();
  133.         }
  134.         else if(c == 10)
  135.         {
  136.             ptr->append();
  137.         }
  138.         else if (c == 11)
  139.         {
  140.             ptr->append();
  141.         }
  142.         else if (c == 12)
  143.         {
  144.             ptr->save();
  145.         }
  146.         else if (c == 13)
  147.         {
  148.             auth = 0;
  149.             while(auth == 0)
  150.             {
  151.                 char ch;
  152.                 pass = "";
  153.                 cout << "Enter current username : ";
  154.                 cin >> uname;
  155.                 cout << "Enter current password : ";
  156.                 ch = _getch();
  157.                 while(ch != 13)
  158.                 {
  159.                   pass.push_back(ch);
  160.                   cout << '*';
  161.                   ch = _getch();
  162.                 }
  163.                 if(uname == a && pass == b)
  164.                 {
  165.                     pass = "";
  166.                     cout << endl << "Enter new username : ";
  167.                     cin >> uname;
  168.                     cout << "Enter new password : ";
  169.                     ch = _getch();
  170.                     while(ch != 13)
  171.                     {
  172.                       pass.push_back(ch);
  173.                       cout << '*';
  174.                       ch = _getch();
  175.                     }
  176.                     u.open("u.txt");
  177.                     p.open("p.txt");
  178.                     uname = encrypt(uname);
  179.                     pass = encrypt(pass);
  180.                     u << uname;
  181.                     p << pass;
  182.                     u.close();
  183.                     p.close();
  184.                     auth++;
  185.                     cout << endl << "Username and password updated ! ";
  186.                 }
  187.                 else
  188.                 {
  189.                     if(attempt == 0)
  190.                     {
  191.                         goto end;
  192.                     }
  193.                     cout << "Invalid username or password ! " << attempt << " attempts left ! " << endl;
  194.                     attempt--;
  195.                 }
  196.             }
  197.         }
  198.         system("pause");
  199.         system("cls");
  200.     }
  201.     while(c != 0);
  202.     if(c == 0)
  203.     {
  204.         abc:
  205.         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 !";
  206.         cin >> c;
  207.         if(c == 1)
  208.         {
  209.             ptr->save();
  210.         }
  211.         else if(c == 2)
  212.         {
  213.             ptr->append();
  214.         }
  215.         else if(c == 0)
  216.         {
  217.             system("cls");
  218.             cout << "Thanks for using our software ! Bye !" << endl;
  219.         }
  220.         else
  221.         {
  222.             cout << "Enter Again ! ";
  223.             system("pause");
  224.             goto abc;
  225.         }
  226.     }
  227.     end:
  228.         if(attempt == 0)
  229.         {
  230.             cout << "Login Failed ! Exiting ";
  231.         }
  232. }
  233. =================================================================================
  234. ///////////////////////////////////// HEADER.H ///////////////////////////////////
  235. ---------------------------------------------------------------------------------
  236. _________________________________________________________________________________
  237.  
  238. #include <iostream>
  239. #include <string>
  240. #include <iomanip>
  241. using namespace std;
  242. int total = 0;
  243. class Manage;
  244. class Student
  245. {
  246.     protected:
  247.         int cs,num;
  248.         string name,no,dept;
  249.     public:
  250.         int id;
  251.         Student()
  252.         {
  253.             cs = 1;
  254.         }
  255.        
  256.         void getData()
  257.         {
  258.             system("cls");
  259.             Student *ptr;
  260.             ptr = this;
  261.             for(int i=0;i<=total;i++)
  262.             {
  263.                 if(ptr->id!=0)
  264.                 {
  265.                     ptr->getID();
  266.                     ptr->getName();
  267.                     ptr->getNo();
  268.                     ptr->getDept();
  269.                 }
  270.                 ptr++;
  271.             }
  272.         }
  273.         void getID()
  274.         {
  275.             cout << "ID : " << this->id << endl;
  276.         }
  277.         void getName()
  278.         {
  279.             cout << "Name : " << this->name << endl;
  280.         }
  281.         void getNo()
  282.         {
  283.             cout << "Contact no. : " << this->no << endl;
  284.         }
  285.         void getDept()
  286.         {
  287.             cout << "Department : " << this->dept << endl;
  288.         }
  289.         /////////////////////check if id is ZERO/////////////////////////////////
  290.         int checkid()
  291.         {
  292.             if(id == 0)
  293.             {
  294.                 return 0;
  295.             }
  296.             else
  297.             {
  298.                 return 1;
  299.             }
  300.         }
  301.         /////////////////////////////Input validation check////////////////////////////////
  302.     int check(int x = 0)
  303.     {
  304.         while(!(cin >> x) || x < 0)
  305.         {
  306.             cin.clear();
  307.             cin.ignore();
  308.             cout << "Invalid input ! Try again : ";
  309.         }
  310.         return x;
  311.     }
  312. };
  313. /////////      ACADAMIC         /////////
  314. struct Subjects
  315. {
  316.     int name,quiz,as,proj,exams;
  317. };
  318. class Acadamic : public virtual Student
  319. {
  320.     protected:
  321.         Subjects sub[6];
  322.         float cgpa,gpa[8];
  323.     public:
  324.         void setData()
  325.         {
  326.             system("cls");
  327.             Acadamic *ptr;
  328.             ptr = this;
  329.             ptr->setSub();
  330.             ptr->calGpa();
  331.         }
  332.         void setSub()
  333.         {
  334.             cout << "Total marks are 100 " << endl;
  335.             for(int i=0;i<6;i++)
  336.             {
  337.                 cout << "Enter name of subject : ";
  338.                 cin >> sub[i].name;
  339.                 cout << "Enter marks of quizes : ";
  340.                 sub[i].quiz = Acadamic::check() ;
  341.                 cout << "Enter marks of assignments : ";
  342.                 sub[i].as = Acadamic::check() ;
  343.                 cout << "Enter marks of project : ";
  344.                 sub[i].proj = Acadamic::check() ;
  345.                 cout << "Enter marks of exams : ";
  346.                 sub[i].exams = Acadamic::check() ;
  347.             }
  348.         }
  349.         void calGpa()
  350.         {
  351.             gpa[cs] = 0;
  352.             for(int i=0;i<6;i++)
  353.             {
  354.                 gpa[cs] = gpa [cs] + sub[i].quiz + sub[i].as + sub[i].proj + sub[i].exams;
  355.             }
  356.             gpa[cs] = gpa[cs] / 100;
  357.             this->calCgpa();
  358.         }
  359.         void calCgpa()
  360.         {
  361.             cgpa = 0.0;
  362.             for(int i=0;i<cs;i++)
  363.             {
  364.                 cgpa = cgpa + gpa[i];
  365.             }
  366.             cgpa = cgpa / cs;
  367.         }
  368.         //////////////////getData///////////////////////////////
  369.         void getData()
  370.         {
  371.             Acadamic *ptr;
  372.             ptr = this;
  373.             header();
  374.             for(int i=0;i<total;i++)
  375.             {
  376.                 if(ptr->id!=0)
  377.                 {
  378.                     getNum();
  379.                     ptr->getID();
  380.                     ptr->getName();
  381.                     ptr->getNo();
  382.                     ptr->getCS();
  383.                     ptr->getCGPA();            
  384.                     ptr->getGPA();
  385.                     cout << endl <<  "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  386.                 }
  387.                 ptr++;
  388.             }
  389.         }
  390.         void getNum()
  391.         {
  392.             num++;
  393.             cout << " " << left << setw(5) << num << left << setw(2) << "|";
  394.         }
  395.         void getID()
  396.         {
  397.             cout << left << setw(7) << id << left << setw(2) << "|";
  398.         }
  399.         void getName()
  400.         {
  401.             cout << left << setw(19) << name << left << setw(2) << "|";
  402.         }
  403.             void getNo()
  404.         {
  405.             cout << left << setw(15) << no << left << setw(5) << "|";
  406.         }
  407.         void getCS()
  408.         {
  409.             cout << left << setw(6) << cs << left << setw(2) << "|";
  410.         }
  411.         void getCGPA()
  412.         {
  413.             cout << fixed << setprecision(2)  << left << setw(5) << cgpa << left << setw(2) << "|";
  414.         }
  415.         void getGPA()
  416.         {
  417.             for(int j=0;j<cs;j++)
  418.             {
  419.                 cout << left << setw(7) << gpa[j]<< left << setw(2) << "|";
  420.             }
  421.         }
  422.         ////////////Header//////////////
  423.         void header()
  424.         {
  425.             system("cls");
  426.             num = 0;
  427.             cout << "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  428.             cout << " " << left << setw(5) << "No." << left << setw(4) << "|";
  429.             cout << left << setw(5) << "ID" << left << setw(9) << "|";
  430.             cout << left << setw(12) << "Name" << left << setw(5) << "|";
  431.             cout << left << setw(12) << "Contact"<< left << setw(2) << "|";
  432.             cout << left << setw(9) << "Semester"<< left << setw(2) << "|";
  433.             cout << left << setw(5) << "CGPA" << left << setw(2) << "|";
  434.             for(int i=0;i<8;i++)
  435.             {
  436.                 cout << left << setw(0) << "GPA("<<setw(0)<<i+1<<setw(2)<< ")" << left << setw(2) << "|";
  437.             }
  438.             cout << endl <<  "------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  439.         }
  440.         //////////get single student data//////////
  441.         void get()
  442.         {
  443.             Acadamic *ptr;
  444.             ptr = this;
  445.             getNum();
  446.             ptr->getID();
  447.             ptr->getName();
  448.             ptr->getNo();
  449.             ptr->getCS();
  450.             ptr->getCGPA();            
  451.             ptr->getGPA();
  452.             cout << endl <<  "---------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
  453.         }
  454.     int check(int x = 0)
  455.     {
  456.         while(!(cin >> x) || x < 0 || x > 100)
  457.         {
  458.             cin.clear();
  459.             cin.ignore();
  460.             cout << "Invalid input ! Try again : ";
  461.         }
  462.         return x;
  463.     }
  464. };
  465. /////////      NON-ACADAMIC         /////////
  466. class nonAcadamic : public virtual Student
  467. {
  468.     protected:
  469.         string name,pos,role;
  470.     public:
  471.         void setData()
  472.         {
  473.             nonAcadamic *ptr;
  474.             ptr = this;
  475.             ptr->setName();
  476.             ptr->setPos();
  477.             ptr->setRole();
  478.         }
  479.         void setName()
  480.         {
  481.             cout << "Enter name of event : ";
  482.             cin >> name;
  483.         }
  484.         void setPos()
  485.         {
  486.             cout << "Enter position : ";
  487.             cin >> pos;
  488.         }
  489.         void setRole()
  490.         {
  491.             cout << "Enter role : ";
  492.             cin >> role;
  493.         }
  494.        
  495.         void getData()
  496.         {
  497.             nonAcadamic *ptr;
  498.             ptr = this;
  499.             for(int i=0;i<total;i++)
  500.             {
  501.                 if(ptr->id!=0)
  502.                 {
  503.                     ptr->getName();
  504.                     ptr->getPos();
  505.                     ptr->getRole();
  506.                 }
  507.                 ptr++;
  508.             }
  509.         }
  510.         void getName()
  511.         {
  512.             cout << "Name of event : " << this->name << endl;
  513.         }
  514.         void getPos()
  515.         {
  516.             cout << "Position : " << this->pos << endl;
  517.         }
  518.         void getRole()
  519.         {
  520.             cout << "Role : " << this->role << endl << endl;
  521.         }
  522. };
  523. /////////      Manage         /////////
  524. class Manage : public nonAcadamic, public Acadamic
  525. {
  526.     protected:
  527.        
  528.     public:
  529.         ////////////////setData//////////
  530.         /////////////setData////////////////////
  531.         void setData()
  532.         {
  533.             system("cls");
  534.             Manage *ptr;
  535.             ptr = this;
  536.             int x=0;
  537.             while (x == 0)
  538.             {
  539.                 system("cls"); 
  540.                 if(ptr->id == 0)
  541.                 {
  542.                     ptr->setID();
  543.                     ptr->setName();
  544.                     ptr->setNo();
  545.                     ptr->setDept();
  546.                     total++;
  547.                     x++;
  548.                 }
  549.                 ptr++;
  550.             }
  551.         }
  552.         void setID()
  553.         {
  554.             cout << "Enter ID : ";
  555.             id = check();
  556.         }
  557.         void setName()
  558.         {
  559.             cout << "Enter name : ";
  560.             cin.ignore();
  561.             getline(cin,name);
  562.         }
  563.         void setNo()
  564.         {
  565.             cout << "Enter contact no. : ";
  566.             cin >> no;
  567.         }
  568.         void setDept()
  569.         {
  570.             cout << "Enter department : ";
  571.             cin >> dept;
  572.         }
  573.         //////////////Search///////////
  574.         void search()
  575.         {
  576.             float Gpa;
  577.             string Name;
  578.             int ser,Id,count=0;
  579.             Manage *ptr;
  580.             ptr = this;
  581.             search:
  582.             system("cls");
  583.             cout << "Enter\n1 to Search by GPA\n2 to Search by Name\n3 to Search all who are above 3.5 GPA\n";
  584.             cout << "4 to Search all who are under serious warning (i.e. CGPA below 1.8)\n5 to Search all who are under warning ";
  585.             cout << "(i.e. CGPA below 2.0 and above 1.8)\n6 to Search by ID " << endl;
  586.             cin >> ser;
  587.             if(ser==1)
  588.             {
  589.                 cout << "Enter GPA to search : ";
  590.                 cin >> Gpa;
  591.             }
  592.             else if (ser==2)
  593.             {
  594.                 cout << "Enter name to search : ";
  595.                 cin >> Name;
  596.             }
  597.             else if(ser==6)
  598.             {
  599.                 cout << "Enter ID to search : ";
  600.                 cin >> Id;
  601.             }
  602.             else if (ser < 1 || ser > 6)
  603.             {
  604.                 cout << "Wrong choice ! " << endl;
  605.                 system("pause");
  606.                 goto search;
  607.             }
  608.             header();
  609.             for(int j=0;j<total;j++)
  610.             {
  611.                 if(ser == 1)
  612.                 {
  613.                     for(int i=0;i<ptr->cs;i++)
  614.                     {
  615.                         if(Gpa == ptr->gpa[i])
  616.                         {
  617.                             ptr->get();
  618.                             count++;
  619.                         }
  620.                     }
  621.                 }
  622.                 else if(ser == 2)
  623.                 {
  624.                     if(Name == ptr->name)
  625.                     {
  626.                         ptr->get();
  627.                         count++;
  628.                     }
  629.                 }
  630.                 else if(ser == 3)
  631.                 {
  632.                     for(int i=0;i<ptr->cs;i++)
  633.                     {
  634.                         if(ptr->gpa[i] > 3.5)
  635.                         {
  636.                             ptr->get();
  637.                             count++;                       
  638.                         }
  639.                     }
  640.                 }
  641.                 else if(ser == 4)
  642.                 {
  643.                     for(int i=0;i<ptr->cs;i++)
  644.                     {
  645.                         if(ptr->gpa[i] < 1.8)
  646.                         {
  647.                             ptr->get();
  648.                             count++;                       
  649.                         }
  650.                     }
  651.                 }
  652.                 else if(ser == 5)
  653.                 {
  654.                     for(int i=0;i<ptr->cs;i++)
  655.                     {
  656.                         if(ptr->gpa[i] < 2.0 && ptr->gpa[i] > 1.8)
  657.                         {
  658.                             ptr->get();
  659.                             count++;
  660.                         }
  661.                     }
  662.                 }
  663.                 else if(ser == 6)
  664.                 {
  665.                     if(Id == ptr->id)
  666.                     {
  667.                         ptr->get();
  668.                         count++;
  669.                     }
  670.                 }
  671.                 ptr++;
  672.             }
  673.             if(count == 0)
  674.             {
  675.                 cout << "Error 404 ! Not found !";
  676.             }
  677.         }
  678.         void dell()
  679.         {
  680.             Manage *ptr;
  681.             ptr = this;
  682.             ptr->id=0;
  683.             ptr->cgpa=0;
  684.             for(int i=0;i<ptr->cs;i++)
  685.             {
  686.                 ptr->gpa[i] = 0.0;
  687.             }
  688.             ptr->cs=0;
  689.             ptr->name = "Delete";
  690.             ptr->no = "090078601";
  691.         }
  692.         void del()
  693.         {
  694.             Manage *ptr;
  695.             ptr = this;
  696.             int Id,count,ser;
  697.             string Name;
  698.             edit:
  699.             system("cls");
  700.             cout << "Enter 1 to delete by name,2 to edit by ID : " << endl;
  701.             cin >> ser;
  702.             if(ser==1)
  703.             {
  704.                 cout << "Enter student name to delete : ";
  705.                 cin >> Name;
  706.             }
  707.             else if (ser==2)
  708.             {
  709.                 cout << "Enter student ID to delete : ";
  710.                 cin >> Id;
  711.             }
  712.             else
  713.             {
  714.                 cout << "Wrong choice ! " << endl;
  715.                 system("pause");
  716.                 goto edit;
  717.             }
  718.             for(int i=0;i<total;i++)
  719.             {
  720.                 if(Id == ptr->id)
  721.                 {
  722.                     ptr->dell();
  723.                     cout << "Deleted !" << endl;
  724.                     count++;
  725.                 }
  726.                 else if(Name == ptr->name)
  727.                 {
  728.                     ptr->dell();
  729.                     cout << "Deleted !" << endl;
  730.                     count++;
  731.                 }
  732.                 ptr++;
  733.             }
  734.             if(count == 0)
  735.             {
  736.                 cout << "Student not found ! " << endl;
  737.             }
  738.         }
  739.         void Register()
  740.         {
  741.             system("cls");
  742.             char c;
  743.             cout << "Do you want to register for next course ? (Enter y or n):";
  744.             cin >> c;
  745.             if(c == 'y')
  746.             {
  747.                 if(this->gpa[cs] > 2.0)
  748.                 {
  749.                     this->cs++;
  750.                 }
  751.                 else
  752.                 {
  753.                     cout << "You can not register for this course ! ";
  754.                 }
  755.             }
  756.             else if(c == 'n')
  757.             {
  758.                
  759.             }
  760.             else
  761.             {
  762.                 cout << "Invalid choice ! ";
  763.                 system("pause");
  764.                 this->Register();
  765.             }
  766.         }
  767.         void edit()
  768.         {
  769.             Manage *ptr;
  770.             ptr = this;
  771.             int Id,count,ser;
  772.             string Name;
  773.             edit:
  774.             system("cls");
  775.             cout << "Enter 1 to edit by name,2 to edit by ID : " << endl;
  776.             cin >> ser;
  777.             if(ser==1)
  778.             {
  779.                 cout << "Enter student name to edit : ";
  780.                 cin >> Name;
  781.             }
  782.             else if (ser==2)
  783.             {
  784.                 cout << "Enter student ID to edit : ";
  785.                 cin >> Id;
  786.             }
  787.             else
  788.             {
  789.                 cout << "Wrong choice ! " << endl;
  790.                 system("pause");
  791.                 goto edit;
  792.             }
  793.             for(int i=0;i<total;i++)
  794.             {
  795.                 if(Id == ptr->id)
  796.                 {
  797.                     ptr->Manage::setData();
  798.                     count++;
  799.                 }
  800.                 else if(Name == ptr->name)
  801.                 {
  802.                     ptr->Manage::setData();
  803.                     count++;
  804.                 }
  805.                 ptr++;
  806.             }
  807.             if(count == 0)
  808.             {
  809.                 cout << "Student not found ! " << endl;
  810.             }
  811.         }
  812.        
  813. /////////////////////////////////////////////// File Handling /////////////////////////////////////////////////////////////////////////////////
  814.         //////////////////Append/////////////////////////
  815.         void append()
  816.         {
  817.             Manage *ptr;
  818.             ptr = this;
  819.             ofstream Id,Name,dept,Gpa,Cgpa,No,Cs,Subj;
  820.             Id.open("id.txt",fstream::app);
  821.             Name.open("name.txt",fstream::app);
  822.             dept.open("dept.txt",fstream::app);
  823.             Gpa.open("gpa.txt",fstream::app);
  824.             Cgpa.open("cgpa.txt",fstream::app);
  825.             No.open("no.txt",fstream::app);
  826.             Cs.open("cs.txt",fstream::app);
  827.             Subj.open("subj.txt",fstream::app);
  828.             for(int i=0;i<total;i++)
  829.             {
  830.                 if(ptr->id != 0)
  831.                 {
  832.                     Cs << ptr->cs << endl;
  833.                     Id << ptr->id << endl;
  834.                     Name << ptr->name << endl;
  835.                     for(int j=0;j<ptr->cs;j++)
  836.                     {
  837.                         Gpa << ptr->gpa[j] <<"\t";
  838.                     }
  839.                     Gpa << endl;
  840.                     Name << ptr->dept << endl;
  841.                     for(int j=0;j<ptr->cs;j++)
  842.                     {
  843.                         Subj << ptr->sub[j].as << endl;
  844.                         Subj << ptr->sub[j].exams << endl;
  845.                         Subj << ptr->sub[j].name << endl;
  846.                         Subj << ptr->sub[j].proj << endl;
  847.                         Subj << ptr->sub[j].quiz << endl;
  848.                     }
  849.                     Cgpa << ptr->cgpa << endl;
  850.                     No << ptr->no << endl;
  851.                 }
  852.                 ptr++;
  853.             }
  854.             Id.close();
  855.             Name.close();
  856.             dept.close();
  857.             Gpa.close();
  858.             Cgpa.close();
  859.             No.close();
  860.             Cs.close();
  861.             cout << "Successfully appended data in txt file ! ";
  862.         }
  863.         /////////////////Save/////////////////////
  864.         void save()
  865.         {
  866.             Manage *ptr;
  867.             ptr = this;
  868.             ofstream Id,Name,Dept,Gpa,Cgpa,No,Cs,Subj;
  869.             Id.open("id.txt");
  870.             Name.open("name.txt");
  871.             Dept.open("dept.txt");
  872.             Gpa.open("gpa.txt");
  873.             Cgpa.open("cgpa.txt");
  874.             No.open("no.txt");
  875.             Subj.open("subj.txt");
  876.             Cs.open("cs.txt");      //  n
  877.             for(int i=0;i<total;i++)
  878.             {
  879.                 if(ptr->id != 0)
  880.                 {  
  881.                     Cs << ptr->cs << endl;
  882.                     Id << ptr->id << endl;
  883.                     Name << ptr->name << endl;
  884.                     for(int j=0;j<ptr->cs;j++)
  885.                     {
  886.                         Gpa << ptr->gpa[j] <<"\t";
  887.                     }
  888.                     Gpa << endl;
  889.                     Dept << ptr->dept << endl;
  890.                     for(int j=0;j<ptr->cs;j++)
  891.                     {
  892.                         Subj << ptr->sub[j].as << endl;
  893.                         Subj << ptr->sub[j].exams << endl;
  894.                         Subj << ptr->sub[j].name << endl;
  895.                         Subj << ptr->sub[j].proj << endl;
  896.                         Subj << ptr->sub[j].quiz << endl;
  897.                     }
  898.                     Cgpa << ptr->cgpa << endl;
  899.                     No << ptr->no << endl;
  900.                 }
  901.                 ptr++;
  902.             }
  903.             Id.close();
  904.             Name.close();
  905.             Subj.close();
  906.             Gpa.close();
  907.             Cgpa.close();
  908.             No.close();
  909.             Cs.close();
  910.             cout << "Successfully saved data in txt file ! ";
  911.         }
  912.         /////////////////load from file/////////////////////////
  913.         void load()
  914.         {
  915.             Manage *ptr;
  916.             ptr = this;
  917.             ifstream Id,Name,Sem,Gpa,Cgpa,No,N,Subj;
  918.             Id.open("id.txt");
  919.             Name.open("name.txt");
  920.             Sem.open("sem.txt");
  921.             Gpa.open("gpa.txt");
  922.             Cgpa.open("cgpa.txt");
  923.             No.open("no.txt");
  924.             Subj.open("subj.txt");
  925.             N.open("cs.txt");
  926.             if(Id.is_open())
  927.             {
  928.                 while(!Id.eof())
  929.                 {
  930.                     if(ptr->id == 0)
  931.                     {
  932.                        
  933.                         Id >> ptr->id;
  934.                         if(ptr->id == 0)
  935.                         {
  936.                             break;
  937.                         }
  938.                         N >> ptr->cs;
  939.                         getline(Name,ptr->name);
  940.                         for(int j=0;j<ptr->cs;j++)
  941.                         {
  942.                             Gpa >> ptr->gpa[j];
  943.                         }
  944.                         Name >> ptr->dept;
  945.                         for(int j=0;j<ptr->cs;j++)
  946.                         {
  947.                             Subj >> ptr->sub[j].as;
  948.                             Subj >> ptr->sub[j].exams;
  949.                             Subj >> ptr->sub[j].name;
  950.                             Subj >> ptr->sub[j].proj;
  951.                             Subj >> ptr->sub[j].quiz;
  952.                         }
  953.                         Cgpa >> ptr->cgpa;
  954.                         No >> ptr->no;
  955.                         total++;
  956.                     }
  957.                     ptr++;
  958.                 }
  959.             }
  960.             cout << "Successfully loaded data from txt file ! ";
  961.             Id.close();
  962.             Name.close();
  963.             Sem.close();
  964.             Gpa.close();
  965.             Cgpa.close();
  966.             No.close();
  967.             N.close();
  968.         }
  969. };
  970. //////////  FUNCTIONS ////////////
  971. void au()
  972. {
  973.     cout << "\t\t           _        _    _       _                    _ _         " << endl;
  974.     cout << "\t\t     /\\   (_)      | |  | |     (_)                  (_) |        " << endl;
  975.     cout << "\t\t    /  \\   _ _ __  | |  | |_ __  ___   _____ _ __ ___ _| |_ _   _ " << endl;
  976.     cout << "\t\t   / /\\ \\ | | '__| | |  | | '_ \\| \\ \\ / / _ \\ '__/ __| | __| | | |" << endl;
  977.     cout << "\t\t  / ____ \\| | |    | |__| | | | | |\\ V /  __/ |  \\__ \\ | |_| |_| |" << endl;
  978.     cout << "\t\t /_/    \\_\\_|_|     \\____/|_| |_|_| \\_/ \\___|_|  |___/_|\\__|\\__, |" << endl;
  979.     cout << "\t\t                                                             __/ |" << endl;
  980.     cout << "\t\t                                                            |___/ " << endl;
  981.     cout << endl << "\t\t    Welcome to Air University Students Managment System v1.0" << endl;
  982.     cout <<         "\t\t    ________________________________________________________" << endl;
  983. }
  984. string encrypt (string a)
  985. {
  986.     for(int i=0;i<a.length();i++)
  987.     {
  988.         a.at(i) = a.at(i) + i - 64;
  989.     }
  990.     return a;
  991. }
  992. string decrypt (string a)
  993. {
  994.     for(int i=0;i<a.length();i++)
  995.     {
  996.         a.at(i) = a.at(i) - i + 64;
  997.     }
  998.     return a;
  999. }
Add Comment
Please, Sign In to add comment