proking

Result

Apr 13th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.97 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<iomanip>
  4. #include<string>
  5. using namespace std;
  6.  
  7. int retry = 0;
  8. char mainuser[20] = "Somya";
  9. char mainpass[20] = "test123";
  10.  
  11. class student
  12. {
  13.     int rollno;
  14.     char name[50];
  15.     int marks1, marks2, marks3, marks4, marks5,prac1,prac2,prac3,prac4,prac5;
  16.     double per;
  17.     char grade;
  18.     void calculate();  
  19. public:
  20.     void getdata();    
  21.     void showdata() const; 
  22.     void show_tabular() const;
  23.     int retrollno() const;
  24. };
  25.  
  26.  
  27. void student::calculate()
  28. {
  29.     if(prac1 == -1 && prac2 == -1 && prac3 == -1 && prac4 == -1 && prac5 == -1)
  30.     {
  31.         per=(marks1+marks2+marks3+marks4+marks5)/5.0;
  32.     }
  33.     else if(prac2 == -1 && prac3 == -1 && prac4 == -1 && prac5 == -1)
  34.     {
  35.         per=(marks1+marks2+marks3+marks4+marks5+prac1)/6.0;
  36.     }
  37.     else if(prac3 == -1 && prac4 == -1 && prac5 == -1)
  38.     {
  39.         per=(marks1+marks2+marks3+marks4+marks5+prac1+prac2)/7.0;
  40.     }
  41.     else if(prac4 == -1 && prac5 == -1)
  42.     {
  43.         per=(marks1+marks2+marks3+marks4+marks5+prac1+prac2+prac3)/8.0;
  44.     }
  45.     else if(prac5 == -1)
  46.     {
  47.         per=(marks1+marks2+marks3+marks4+marks5+prac1+prac2+prac3+prac4)/9.0;
  48.     }
  49.     else
  50.     {
  51.         per=(marks1+marks2+marks3+marks4+marks5+prac1+prac2+prac3+prac4+prac5)/10.0;
  52.     }
  53.     if(per>=60)
  54.         grade='A';
  55.     else if(per>=50)
  56.         grade='B';
  57.     else if(per>=33)
  58.         grade='C';
  59.     else
  60.         grade='F';
  61. }
  62.  
  63. void student::getdata()
  64. {
  65.     cout<<"\nEnter The roll number of student ";
  66.     cin>>rollno;
  67.     cout<<"\n\nEnter The Name of student ";
  68.     cin.ignore();
  69.     cin.getline(name,50);
  70.     cout<<"\nEnter The marks in Subject 1 out of 100 : ";
  71.     cin>>marks1;
  72.     cout<<"\nEnter The marks in Subject 2 out of 100 : ";
  73.     cin>>marks2;
  74.     cout<<"\nEnter The marks in Subject 3 out of 100 : ";
  75.     cin>>marks3;
  76.     cout<<"\nEnter The marks in Subject 4 out of 100 : ";
  77.     cin>>marks4;
  78.     cout<<"\nEnter The marks in Subject 5 out of 100 : ";
  79.     cin>>marks5;
  80.     cout<<"\nEnter The marks in Practical 1 out of 100 :(If no practical marks enter -1) ";
  81.     cin>>prac1;
  82.     if(prac1 == -1)
  83.     {
  84.         prac2=prac3=prac4=prac5=-1;
  85.     }
  86.     else
  87.     {
  88.     cout<<"\nEnter The marks in Practical 2 out of 100 :(If no practical marks enter -1) ";
  89.     cin>>prac2;
  90.     }
  91.     if(prac2 == -1)
  92.     {
  93.         prac3=prac4=prac5=-1;
  94.     }
  95.     else
  96.     {
  97.         cout<<"\nEnter The marks in Practical 3 out of 100 (If no practical marks enter -1): ";
  98.         cin>>prac3;
  99.     }
  100.     if(prac3==-1)
  101.     {
  102.         prac4=prac5=-1;
  103.     }
  104.     else
  105.     {
  106.         cout<<"\nEnter The marks in Practical 4 out of 100 :(If no practical marks enter -1) ";
  107.         cin>>prac4;
  108.     }
  109.     if(prac4==-1)
  110.     {
  111.         prac5=-1;
  112.     }
  113.     else
  114.     {
  115.         cout<<"\nEnter The marks in Practical 5 out of 100 :(If no practical marks enter -1) ";
  116.         cin>>prac5;
  117.     }
  118.     calculate();
  119. }
  120.  
  121. void student::showdata() const
  122. {
  123.     cout<<"\nRoll number of student : "<<rollno;
  124.     cout<<"\nName of student : "<<name;
  125.     cout<<"\nMarks in Subject 1 : "<<marks1;
  126.     cout<<"\nMarks in Subject 2 : "<<marks2;
  127.     cout<<"\nMarks in Subject 3 : "<<marks3;
  128.     cout<<"\nMarks in Subject 4 : "<<marks4;
  129.     cout<<"\nMarks in Subject 5 : "<<marks5;
  130.     if(prac1!=-1)
  131.     {
  132.         cout<<"\nMarks in Prac 1 : "<<prac1;
  133.     }
  134.     if(prac2!=-1)
  135.     {
  136.         cout<<"\nMarks in Prac 2 : "<<prac2;
  137.     }
  138.     if(prac3!=-1)
  139.     {
  140.         cout<<"\nMarks in Prac 3 : "<<prac3;
  141.     }
  142.     if(prac4!=-1)
  143.     {
  144.         cout<<"\nMarks in Prac 4 : "<<prac4;
  145.     }
  146.     if(prac5!=-1)
  147.     {
  148.         cout<<"\nMarks in Prac 5 : "<<prac5;
  149.     }
  150.     cout<<"\nPercentage of student is  :"<<per;
  151.     cout<<"\nGrade of student is :"<<grade;
  152. }
  153.  
  154. void student::show_tabular() const
  155. {
  156.     cout<<rollno<<setw(6)<<" "<<name<<setw(10)<<marks1<<setw(4)<<marks2<<setw(4)<<marks3<<setw(4)
  157.         <<marks4<<setw(4)<<marks5<<setw(4)<<prac1<<setw(8)<<per<<setw(6)<<grade<<endl;
  158. }
  159.  
  160. int  student::retrollno() const
  161. {
  162.     return rollno;
  163. }
  164.  
  165.  
  166. void write_student();  
  167. void display_all();
  168. void display_sp(int);  
  169. void modify_student(int);  
  170. void delete_student(int);  
  171. void class_result();   
  172. void result();     
  173. void intro();      
  174. void entry_menu(); 
  175.  
  176.  
  177. int main()
  178. {
  179.     char ch;
  180.     cout.setf(ios::fixed|ios::showpoint);
  181.     cout<<setprecision(2);
  182.     intro();
  183.     do
  184.     {
  185.         system("cls");
  186.         cout<<"\n\n\n\tMAIN MENU";
  187.         cout<<"\n\n\t01. RESULT MENU";
  188.         cout<<"\n\n\t02. ENTRY/EDIT MENU";
  189.         cout<<"\n\n\t03. EXIT";
  190.         cout<<"\n\n\tPlease Select Your Option (1-3) ";
  191.         cin>>ch;
  192.         switch(ch)
  193.         {
  194.             case '1': result();
  195.                 break;
  196.             case '2': entry_menu();
  197.                 break;
  198.             case '3':
  199.                 break;
  200.             default :cout<<"\a";
  201.         }
  202.     }while(ch!='3');
  203.     return 0;
  204. }
  205.  
  206.  
  207. void write_student()
  208. {
  209.     student st;
  210.     ofstream outFile;
  211.     outFile.open("student.dat",ios::binary|ios::app);
  212.     st.getdata();
  213.     outFile.write(reinterpret_cast<char *> (&st), sizeof(student));
  214.     outFile.close();
  215.         cout<<"\n\nStudent record Has Been Created ";
  216.     cin.ignore();
  217.     cin.get();
  218. }
  219.  
  220.  
  221.  
  222. void display_all()
  223. {
  224.     student st;
  225.     ifstream inFile;
  226.     inFile.open("student.dat",ios::binary);
  227.     if(!inFile)
  228.     {
  229.         cout<<"File could not be open !! Press any Key...";
  230.         cin.ignore();
  231.         cin.get();
  232.         return;
  233.     }
  234.     cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
  235.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  236.     {
  237.         st.showdata();
  238.         cout<<"\n\n====================================\n";
  239.     }
  240.     inFile.close();
  241.     cin.ignore();
  242.     cin.get();
  243. }
  244.  
  245.  
  246. void display_sp(int n)
  247. {
  248.     student st;
  249.     ifstream inFile;
  250.     inFile.open("student.dat",ios::binary);
  251.     if(!inFile)
  252.     {
  253.         cout<<"File could not be open !! Press any Key...";
  254.         cin.ignore();
  255.         cin.get();
  256.         return;
  257.     }
  258.     bool flag=false;
  259.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  260.     {
  261.         if(st.retrollno()==n)
  262.         {
  263.              st.showdata();
  264.              flag=true;
  265.         }
  266.     }
  267.     inFile.close();
  268.     if(flag==false)
  269.         cout<<"\n\nrecord not exist";
  270.     cin.ignore();
  271.     cin.get();
  272. }
  273.  
  274.  
  275. void modify_student(int n)
  276. {
  277.     bool found=false;
  278.     student st;
  279.     fstream File;
  280.     File.open("student.dat",ios::binary|ios::in|ios::out);
  281.     if(!File)
  282.     {
  283.         cout<<"File could not be open !! Press any Key...";
  284.         cin.ignore();
  285.         cin.get();
  286.         return;
  287.     }
  288.         while(!File.eof() && found==false)
  289.     {
  290.  
  291.         File.read(reinterpret_cast<char *> (&st), sizeof(student));
  292.         if(st.retrollno()==n)
  293.         {
  294.             st.showdata();
  295.             cout<<"\n\nPlease Enter The New Details of student"<<endl;
  296.             st.getdata();
  297.                 int pos=(-1)*static_cast<int>(sizeof(st));
  298.                 File.seekp(pos,ios::cur);
  299.                 File.write(reinterpret_cast<char *> (&st), sizeof(student));
  300.                 cout<<"\n\n\t Record Updated";
  301.                 found=true;
  302.         }
  303.     }
  304.     File.close();
  305.     if(found==false)
  306.         cout<<"\n\n Record Not Found ";
  307.     cin.ignore();
  308.     cin.get();
  309. }
  310.  
  311.  
  312. void delete_student(int n)
  313. {
  314.     student st;
  315.     ifstream inFile;
  316.     inFile.open("student.dat",ios::binary);
  317.     if(!inFile)
  318.     {
  319.         cout<<"File could not be open !! Press any Key...";
  320.         cin.ignore();
  321.         cin.get();
  322.         return;
  323.     }
  324.     ofstream outFile;
  325.     outFile.open("Temp.dat",ios::out);
  326.     inFile.seekg(0,ios::beg);
  327.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  328.     {
  329.         if(st.retrollno()!=n)
  330.         {
  331.             outFile.write(reinterpret_cast<char *> (&st), sizeof(student));
  332.         }
  333.     }
  334.     outFile.close();
  335.     inFile.close();
  336.     remove("student.dat");
  337.     rename("Temp.dat","student.dat");
  338.     cout<<"\n\n\tRecord Deleted ..";
  339.     cin.ignore();
  340.     cin.get();
  341. }
  342.  
  343.  
  344. void class_result()
  345. {
  346.     student st;
  347.     ifstream inFile;
  348.     inFile.open("student.dat",ios::binary);
  349.     if(!inFile)
  350.     {
  351.         cout<<"File could not be open !! Press any Key...";
  352.         cin.ignore();
  353.         cin.get();
  354.         return;
  355.     }
  356.     //cout<<rollno<<setw(6)<<" "<<name<<setw(10)<<marks1<<setw(4)<<marks2<<setw(4)<<marks3<<setw(4)
  357.     //  <<marks4<<setw(4)<<marks5<<setw(4)<<prac1<<setw(8)<<per<<setw(6)<<grade<<endl;
  358.     cout<<"\n\n\t\tALL STUDENTS RESULT \n\n";
  359.     cout<<"==========================================================\n";
  360.     cout<<"R.No"<<setw(6)<<"Name"<<setw(10)<<"S1"<<setw(4)<<"S2"<<setw(4)<<"S3"<<setw(4)<<"S4"<<setw(4)<<"S5"<<setw(4)<<"P1"<<setw(8)<<" %age"<<setw(10)<<"Grade"<<endl;
  361.     cout<<"==========================================================\n";
  362.     while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
  363.     {
  364.         st.show_tabular();
  365.     }
  366.     cin.ignore();
  367.     cin.get();
  368.     inFile.close();
  369. }
  370.  
  371.  
  372. void result()
  373. {
  374.     char ch;
  375.     int rno;
  376.     system("cls");
  377.     cout<<"\n\n\n\tRESULT MENU";
  378.     cout<<"\n\n\n\t1. Class Result";
  379.     cout<<"\n\n\t2. Student Report Card";
  380.     cout<<"\n\n\t3. Back to Main Menu";
  381.     cout<<"\n\n\n\tEnter Choice (1/2/3)? ";
  382.     cin>>ch;
  383.     system("cls");
  384.     switch(ch)
  385.     {
  386.     case '1' :  class_result(); break;
  387.     case '2' :  cout<<"\n\n\tEnter Roll Number Of Student : "; cin>>rno;
  388.                 display_sp(rno); break;
  389.     case '3' :  break;
  390.     default:    cout<<"\a";
  391.     }
  392. }
  393.  
  394.  
  395. void intro()
  396. {
  397.     char user[20] = "test",pass[20] ="test";
  398.     cout<<"\n\n\n\t\t  STUDENT";
  399.     cout<<"\n\n\t\tREPORT CARD";
  400.     cout<<"\n\n\n\t\t  STUDENT";
  401.     cout<<"\n\n\t\tREPORT CARD";
  402.     if(retry == 1)
  403.     {
  404.         cout<<"\n\t\tPassword is wrong";
  405.     }
  406.     else if(retry == 2)
  407.     {
  408.         cout<<"\n\t\tInvaild Username";
  409.     }
  410.     cout<<"\n\n\t\tUserName: ";
  411.     gets(user);
  412.     cout<<"\n\n\t\tPassword: ";
  413.     gets(pass);
  414.     if(strcmp(user,mainuser) == 0)
  415.     {
  416.         if(strcmp(pass,mainpass) == 0)
  417.         {
  418.             system("cls");
  419.             cout<<"\n\n\n\t\tLogin SuccessFul...";
  420.             cout<<"\n\n\n\t\t  STUDENT";
  421.             cout<<"\n\n\t\tREPORT CARD";
  422.             cout<<"\n\n\n\t\t  STUDENT";
  423.             cout<<"\n\n\t\tREPORT CARD";
  424.             cin.get();
  425.         }
  426.         else
  427.         {
  428.             system("cls");
  429.             retry = 1;
  430.             intro();
  431.         }
  432.     }
  433.     else
  434.     {
  435.         system("cls");
  436.         retry = 2;
  437.         intro();
  438.     }
  439. }
  440.  
  441.  
  442.  
  443. void entry_menu()
  444. {
  445.     char ch;
  446.     int num;
  447.     system("cls");
  448.     cout<<"\n\n\n\tENTRY MENU";
  449.     cout<<"\n\n\t1.CREATE STUDENT RECORD";
  450.     cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORDS";
  451.     cout<<"\n\n\t3.SEARCH STUDENT RECORD ";
  452.     cout<<"\n\n\t4.MODIFY STUDENT RECORD";
  453.     cout<<"\n\n\t5.DELETE STUDENT RECORD";
  454.     cout<<"\n\n\t6.BACK TO MAIN MENU";
  455.     cout<<"\n\n\tPlease Enter Your Choice (1-6) ";
  456.     cin>>ch;
  457.     system("cls");
  458.     switch(ch)
  459.     {
  460.     case '1':   write_student(); break;
  461.     case '2':   display_all(); break;
  462.     case '3':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  463.             display_sp(num); break;
  464.     case '4':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  465.             modify_student(num);break;
  466.     case '5':   cout<<"\n\n\tPlease Enter The roll number "; cin>>num;
  467.             delete_student(num);break;
  468.     case '6':   break;
  469.     default:    cout<<"\a"; entry_menu();
  470.     }
  471. }
Advertisement
Add Comment
Please, Sign In to add comment