Advertisement
Diamondtroller

source

Sep 7th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.14 KB | None | 0 0
  1. //***************************************************************
  2. //                   HEADER FILE USED IN PROJECT
  3. //****************************************************************
  4.  
  5. #include<iostream>
  6. #include<fstream>
  7. #include<iomanip>
  8. using namespace std;
  9.  
  10.  
  11. //***************************************************************
  12. //                   CLASS USED IN PROJECT
  13. //****************************************************************
  14. class login
  15. {
  16. public:
  17.     string username,password;
  18.     login ()
  19.     {
  20.         username= " \0";
  21.         password= " \0";
  22.     };
  23.     bool IslogIn();
  24. };
  25. bool login ::IslogIn()
  26. {
  27.     string ch_username= "BAKHIT", ch_password = "test123";
  28.  
  29.     cout << "Enter your user name  ::\n";
  30.     cin >> username;
  31.  
  32.     cout << "Enter the Password :: \n";
  33.     cin >> password;
  34.  
  35.     if (username == ch_username && password == ch_password)
  36.     {
  37.         return true;
  38.     }
  39.     else
  40.     {
  41.         return false;
  42.     }
  43. }
  44.  
  45. int main()
  46. {
  47.     login l1;
  48.     bool status = l1.IslogIn();
  49.     if (!status)
  50.     {
  51.         cout << " Failed login,register first at www.iukl.edu.my/student portal\n";
  52.         return 1;
  53.     }
  54.     else
  55.     {
  56.         cout << "Welcome " << l1.username << " !\n" ;
  57.  
  58.     }
  59.    int intro();
  60.    int result();
  61.    int entry_menu();
  62.    char ch;
  63.     cout.setf(ios::fixed|ios::showpoint);
  64.     cout<<setprecision(2); // program outputs decimal number to two decimal places
  65.     intro();
  66.     do
  67.     {
  68.  
  69.         cout<<"\n\n\n\tMAIN MENU";
  70.         cout<<"\n\n\t01. RESULT MENU";
  71.         cout<<"\n\n\t02. ENTRY/EDIT MENU";
  72.         cout<<"\n\n\t03. EXIT";
  73.         cout<<"\n\n\tPlease Select Your Option (1-3) ";
  74.         cin>>ch;
  75.         switch(ch)
  76.         {
  77.             case '1': result();
  78.                 break;
  79.             case '2': entry_menu();
  80.                 break;
  81.             case '3':
  82.                 break;
  83.             default :cout<<"\a";
  84.         }
  85.     }while(ch!='3');
  86.     return 0;
  87. }
  88.  
  89.  
  90.  
  91. class student
  92. {
  93.     int SANAULLAH;
  94.     char name[50];
  95.     int RC_marks,SA_marks, GEO_marks, Math2_marks, CS_marks;
  96.     double Av;
  97.     char grade;
  98.     void calculate();   //function to calculate grade
  99. public:
  100.     void getdata();     //function to accept data from user
  101.     void showdata() const;  //function to show data on screen
  102.     void show_tabular() const;
  103.     int retrollno() const;
  104. }; //class ends here
  105.  
  106.  
  107. void student::calculate()
  108. {
  109.     Av=(RC_marks, SA_marks, GEO_marks, Math2_marks, CS_marks)/5.0;
  110.     if(Av>=60)
  111.         grade='A';
  112.     else if(Av>=50)
  113.         grade='B';
  114.     else if(Av>=33)
  115.         grade='C';
  116.     else
  117.         grade='F';
  118. }
  119.  
  120. void student::getdata()
  121. {
  122.     cout<<"\nEnter The roll number of student ";
  123.     cin>>SANAULLAH;
  124.     cout<<"\n\nEnter The Name of student ";
  125.     cin.ignore();
  126.     cin.getline(name,50);
  127.     cout<<"\nEnter The marks in Reinforced Concrete  out of 100 : ";
  128.     cin>>RC_marks;
  129.     cout<<"\nEnter The marks in Structural Analysis out of 100 : ";
  130.     cin>>SA_marks;
  131.     cout<<"\nEnter The marks in maths 2 out of 100 : ";
  132.     cin>>Math2_marks;
  133.     cout<<"\nEnter The marks in Geology out of 100 : ";
  134.     cin>>GEO_marks;
  135.     cout<<"\nEnter The marks in computer science out of 100 : ";
  136.     cin>>CS_marks;
  137.     calculate();
  138. }
  139.  
  140. void student::showdata() const
  141. {
  142.     cout<<"\nRoll number of student : "<<SANAULLAH;
  143.     cout<<"\nName of student : "<<name;
  144.     cout<<"\nMarks in Reinforced Concrete : "<<RC_marks;
  145.     cout<<"\nMarks in Geology : "<<GEO_marks;
  146.     cout<<"\nMarks in Maths 2: "<<Math2_marks;
  147.     cout<<"\nMarks in Structural Analysis  : "<<SA_marks;
  148.     cout<<"\nMarks in Computer Science :"<<CS_marks;
  149.     cout<<"\nPercentage of student is  :"<<Av;
  150.     cout<<"\nGrade of student is :"<<grade;
  151.  
  152. }
  153.  
  154. void student::show_tabular() const
  155. {
  156.     cout<<SANAULLAH<<setw(6)<<" "<<name<<setw(10)<<RC_marks<<setw(4)<<GEO_marks<<setw(4)<<Math2_marks<<setw(4)
  157.         <<SA_marks<<setw(4)<<CS_marks<<setw(8)<<Av<<setw(6)<<grade<<endl;
  158. }
  159.  
  160. int  student::retrollno() const
  161. {
  162.     return SANAULLAH;
  163. }
  164.  
  165.  
  166. //***************************************************************
  167. //      function declaration
  168. //****************************************************************
  169.  
  170. void write_student();   //write the record in binary file
  171. void display_all(); //read all records from binary file
  172. void display_sp(int);   //accept rollno and read record from binary file
  173. void modify_student(int);   //accept rollno and update record of binary file
  174. void delete_student(int);   //accept rollno and delete selected records from binary file
  175. void class_result();    //display all records in tabular format from binary file
  176. void result();      //display result menu
  177. void intro();       //display welcome screen
  178. void entry_menu();  //display entry menu on screen
  179.  
  180.  
  181. //***************************************************************
  182. //      THE MAIN FUNCTION OF PROGRAM
  183. //****************************************************************
  184.  
  185.  
  186. //***************************************************************
  187. //      function to write in file
  188. //****************************************************************
  189.  
  190. void write_student()
  191. {
  192.     student st;
  193.     ofstream outFile;
  194.     outFile.open("student.dat",ios::binary|ios::app);
  195.     st.getdata();
  196.     outFile.write(reinterpret_cast<char *> (&st), sizeof(student));
  197.     outFile.close();
  198.         cout<<"\n\nStudent record Has Been Created ";
  199.     cin.ignore();
  200.     cin.get();
  201. }
  202.  
  203. //***************************************************************
  204. //      function to read all records from file
  205. //****************************************************************
  206.  
  207. void display_all()
  208. {
  209.     student st;
  210.     ifstream inFile;
  211.     inFile.open("student.dat",ios::binary);
  212.     if(!inFile)
  213.     {
  214.         cout<<"File could not be open !! Press any Key...";
  215.         cin.ignore();
  216.         cin.get();
  217.         return;
  218.     }
  219.     cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
  220.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  221.     {
  222.         st.showdata();
  223.         cout<<"\n\n====================================\n";
  224.     }
  225.     inFile.close();
  226.     cin.ignore();
  227.     cin.get();
  228. }
  229.  
  230. //***************************************************************
  231. //      function to read specific record from file
  232. //****************************************************************
  233.  
  234. void display_sp(int n)
  235. {
  236.     student st;
  237.     ifstream inFile;
  238.     inFile.open("student.dat",ios::binary);
  239.     if(!inFile)
  240.     {
  241.         cout<<"File could not be open !! Press any Key...";
  242.         cin.ignore();
  243.         cin.get();
  244.         return;
  245.     }
  246.     bool flag=false;
  247.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  248.     {
  249.         if(st.retrollno()==n)
  250.         {
  251.              st.showdata();
  252.              flag=true;
  253.         }
  254.     }
  255.     inFile.close();
  256.     if(flag==false)
  257.         cout<<"\n\nrecord not exist";
  258.     cin.ignore();
  259.     cin.get();
  260. }
  261.  
  262. //***************************************************************
  263. //      function to modify record of file
  264. //****************************************************************
  265.  
  266. void modify_student(int n)
  267. {
  268.     bool found=false;
  269.     student st;
  270.     fstream File;
  271.     File.open("student.dat",ios::binary|ios::in|ios::out);
  272.     if(!File)
  273.     {
  274.         cout<<"File could not be open !! Press any Key...";
  275.         cin.ignore();
  276.         cin.get();
  277.         return;
  278.     }
  279.         while(!File.eof() && found==false)
  280.     {
  281.  
  282.         File.read(reinterpret_cast<char *> (&st), sizeof(student));
  283.         if(st.retrollno()==n)
  284.         {
  285.             st.showdata();
  286.             cout<<"\n\nPlease Enter The New Details of student"<<endl;
  287.             st.getdata();
  288.                 int pos=(-1)*static_cast<int>(sizeof(st));
  289.                 File.seekp(pos,ios::cur);
  290.                 File.write(reinterpret_cast<char *> (&st), sizeof(student));
  291.                 cout<<"\n\n\t Record Updated";
  292.                 found=true;
  293.         }
  294.     }
  295.     File.close();
  296.     if(found==false)
  297.         cout<<"\n\n Record Not Found ";
  298.     cin.ignore();
  299.     cin.get();
  300. }
  301.  
  302. //***************************************************************
  303. //      function to delete record of file
  304. //****************************************************************
  305.  
  306. void delete_student(int n)
  307. {
  308.     student st;
  309.     ifstream inFile;
  310.     inFile.open("student.dat",ios::binary);
  311.     if(!inFile)
  312.     {
  313.         cout<<"File could not be open !! Press any Key...";
  314.         cin.ignore();
  315.         cin.get();
  316.         return;
  317.     }
  318.     ofstream outFile;
  319.     outFile.open("Temp.dat",ios::out);
  320.     inFile.seekg(0,ios::beg);
  321.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  322.     {
  323.         if(st.retrollno()!=n)
  324.         {
  325.             outFile.write(reinterpret_cast<char *> (&st), sizeof(student));
  326.         }
  327.     }
  328.     outFile.close();
  329.     inFile.close();
  330.     remove("student.dat");
  331.     rename("Temp.dat","student.dat");
  332.     cout<<"\n\n\tRecord Deleted ..";
  333.     cin.ignore();
  334.     cin.get();
  335. }
  336.  
  337. //***************************************************************
  338. //      function to display all students grade report
  339. //****************************************************************
  340.  
  341. void class_result()
  342. {
  343.     student st;
  344.     ifstream inFile;
  345.     inFile.open("student.dat",ios::binary);
  346.     if(!inFile)
  347.     {
  348.         cout<<"File could not be open !! Press any Key...";
  349.         cin.ignore();
  350.         cin.get();
  351.         return;
  352.     }
  353.     cout<<"\n\n\t\tALL STUDENTS RESULT \n\n";
  354.     cout<<"==========================================================\n";
  355.     cout<<"R.No       Name        P   C   M   E   CS   %age   Grade"<<endl;
  356.     cout<<"==========================================================\n";
  357.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  358.     {
  359.         st.show_tabular();
  360.     }
  361.     cin.ignore();
  362.     cin.get();
  363.     inFile.close();
  364. }
  365.  
  366. //***************************************************************
  367. //      function to display result menu
  368. //****************************************************************
  369.  
  370. void result()
  371. {
  372.     char ch;
  373.     int rno;
  374.  
  375.     cout<<"\n\n\n\tRESULT MENU";
  376.     cout<<"\n\n\n\t1. Class Result";
  377.     cout<<"\n\n\t2. Student Report Card";
  378.     cout<<"\n\n\t3. Back to Main Menu";
  379.     cout<<"\n\n\n\tEnter Choice (1/2/3)? ";
  380.     cin>>ch;
  381.  
  382.     switch(ch)
  383.     {
  384.     case '1' :  class_result(); break;
  385.     case '2' :  cout<<"\n\n\tEnter Roll Number Of Student : "; cin>>rno;
  386.                 display_sp(rno); break;
  387.     case '3' :  break;
  388.     default:    cout<<"\a";
  389.     }
  390. }
  391.  
  392. //***************************************************************
  393. //      INTRODUCTION FUNCTION
  394. //****************************************************************
  395.  
  396. void intro()
  397. {
  398.     cout<<"\n\n\n\t\t  STUDENT";
  399.     cout<<"\n\n\t\tResult management";
  400.     cout<<"\n\n\t\t  computer programing PROJECT (June 2017 semester)";
  401.     cout<<"\n\n\n\tMADE BY : BAKHIT BAHAR";
  402.     cout<<"\n\tSCHOOL : INFRASTRUCTURE UNIVERSITY KUALA LUMPUR";
  403.     cin.get();
  404. }
  405.  
  406. //***************************************************************
  407. //      ENTRY / EDIT MENU FUNCTION
  408. //****************************************************************
  409.  
  410. void entry_menu()
  411. {
  412.     char ch;
  413.     int num;
  414.  
  415.     cout<<"\n\n\n\tENTRY MENU";
  416.     cout<<"\n\n\t1.CREATE STUDENT RECORD";
  417.     cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORDS";
  418.     cout<<"\n\n\t3.SEARCH STUDENT RECORD ";
  419.     cout<<"\n\n\t4.MODIFY STUDENT RECORD";
  420.     cout<<"\n\n\t5.DELETE STUDENT RECORD";
  421.     cout<<"\n\n\t6.BACK TO MAIN MENU";
  422.     cout<<"\n\n\tPlease Enter Your Choice (1-6) ";
  423.     cin>>ch;
  424.  
  425.     switch(ch)
  426.     {
  427.     case '1':   write_student(); break;
  428.     case '2':   display_all(); break;
  429.     case '3':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  430.             display_sp(num); break;
  431.     case '4':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  432.             modify_student(num);break;
  433.     case '5':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  434.             delete_student(num);break;
  435.     case '6':   break;
  436.     default:    cout<<"\a"; entry_menu();
  437.     }
  438. }
  439.  
  440. //***************************************************************
  441. //              END OF PROJECT
  442. //***************************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement