Facebook
From sara, 3 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 119
  1. #include <iostream>
  2. #include <cstring>      
  3. #include <string>
  4. #include <conio.h>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8.  
  9. class student
  10. {   private:
  11.         int id;     float e1,e2,m;   string name;    
  12.        
  13.     public:
  14.             static int k;
  15.             void setname();
  16.                     void setid();
  17.                     void setexam();
  18.                     void setaverage(float e1,float e2);
  19.                 void set()
  20.                 {   setname();
  21.                     setid();
  22.                     setexam();
  23.                     setaverage(e1,e2);
  24.                 }
  25.                
  26.                 void print();
  27.                  
  28.                 student()
  29.                 {
  30.                         m=id=0;
  31.                         name="null";
  32.                    }
  33.                      
  34.             student(student &o)
  35.             {
  36.                 name=o.name;
  37.                 id=o.id;
  38.                 e1=o.e1;
  39.                 e2=o.e2;
  40.                 m=o.m;
  41.                 }
  42.             student(int id,string n,float m)
  43.             {
  44.                m=id=0;
  45.                    name=n;
  46.                 }
  47.             //~student();
  48.        
  49.        
  50. };
  51. int student::k=1;
  52. void student::setname()
  53. {
  54.     cout<<"please enter student's name :";
  55.         cin>>name;
  56.         cout<<endl;    
  57. }
  58. void student::setid()
  59. {
  60.     cout<<"please enter student's number :";
  61.         cin>>id;
  62.         cout<<endl;            
  63. }
  64. void student::setexam()
  65. {   cout<<"please enter mark1 :";
  66.         cin>>e1;
  67.         cout<<endl;
  68.         cout<<"please enter mark2 :";
  69.         cin>>e2;
  70.         cout<<endl;            
  71. }
  72. void student::setaverage(float e1,float e2)
  73. {
  74.     m=((e1+e2)/2);     
  75. }
  76.  
  77. void  student::print()
  78. {   cout<<endl<<endl<<"student "<<k<<":"<<endl;
  79.         for(int i=0;i<30;i++)cout<<"-";    cout<<endl;
  80.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  81.         cout<<"|"<<"      name       |"<<setw(10)<<name<<"|"<<endl;
  82.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  83.         for(int i=0;i<30;i++)cout<<"-";    cout<<endl;
  84.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  85.         cout<<"|"<<"shomare daneshju |"<<setw(10)<<id<<"|"<<endl;
  86.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  87.         for(int i=0;i<30;i++)cout<<"-";    cout<<endl;
  88.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  89.         cout<<"|"<<"     moadel      |"<<setw(10)<<m<<"|"<<endl;
  90.         cout<<"|"<<setw(18)<<"|"<<setw(11)<<"|"<<endl;
  91.         for(int i=0;i<30;i++)cout<<"-";    cout<<endl;
  92. }
  93.  
  94.  
  95.  main(){
  96.     int n;
  97.         cout<<"chand nafar:";
  98.         cin>>n;
  99.         student p[n];
  100.        
  101.  
  102.         int j;
  103.         j=int('a');
  104.        
  105.         for(int i=0;i<n;++i)
  106.                 p[i].set();
  107.                
  108.    
  109.     for(int x=0;x<n;x++)
  110.           {
  111.           p[x].print();
  112.           student::k++;
  113.       }
  114.        
  115.        
  116.        
  117.  
  118.         getch();
  119.         return 0;
  120. }