SHARE
TWEET

C++ code

a guest Nov 17th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. //Base class
  5. class std_basic_info
  6. {
  7.     private:
  8.         char name[30],status[30];
  9.         int  no,subject1,subject2,subject3,subject4,subject5;
  10.         char grade;
  11.     public:
  12.         int sum;
  13.         float avg;
  14.         void getBasicInfo(void);
  15.         void putBasicInfo(void);
  16. };
  17.  
  18. //function definitions
  19. void std_basic_info::getBasicInfo(void)
  20. {
  21.     cout << "Enter student's basic information:" << endl;
  22.     cout << "Name?: ";    cin >> name;
  23.     cout << "Number?: ";    cin >> no;
  24.     cout << "Status?: ";     cin >> status;
  25.     cout << "Subject1?: ";cin >> subject1;
  26.     cout << "Subject2?: ";cin >> subject2;
  27.     cout << "Subject3?: ";cin >> subject3;
  28.     cout << "Subject4?: ";cin >> subject4;
  29.     cout << "Subject5?: ";cin >> subject5;
  30.     sum=subject1+subject2+subject3+subject4+subject5;
  31.     avg=sum/5;
  32. }
  33.  
  34. void std_basic_info::putBasicInfo(void)
  35. {
  36.     cout<<"______________________________________"<<endl;
  37.     cout<<"Name:"<<name<<"\t Number:"<<no<<"\t Status:"<<status<<endl;
  38.     cout<<"Subject1:"<<subject1<<"\t Subject2:"<<subject2<<"\t Subject3:"<<subject3<<"\t Subject4:"<<subject4<<"\t Subject5:"<<subject5<<endl;
  39.     cout<<"Sum = "<<sum<<"\t Average = "<<avg<<endl;
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.     //create object of derived class
  46.     std_basic_info std[2],temp;
  47.  
  48.     //read student basic and result information
  49.     for(int i=0;i<2;i++){
  50.         std[i].getBasicInfo();  
  51.     }
  52.  
  53.     for(int i=0;i<5;i++)
  54.     {      
  55.         for(int j=i+1;j<5;j++)
  56.         {
  57.             if(std[i].avg>std[j].avg)
  58.             {
  59.                 temp  =std[i];
  60.                 std[i]=std[j];
  61.                 std[j]=temp;
  62.             }
  63.         }
  64.     }
  65.     for(int i=0;i<2;i++){
  66.         std[i].putBasicInfo();
  67.     }
  68.     return 0;
  69. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top