728x90 AdSpace

Latest Article

Student Class Implementation in C++ Example Code





Online Student Class Implementation in C++ Example Code Assignment Homework task Practice Problem

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
class Student
{
private:
int Rollnumber;
double GPA;
int Credithours;
   public:  
     Student(int aRollnumber,double aGPA,int aCredithours)
     {
        Rollnumber=aRollnumber;
        GPA=aGPA;
        Credithours=aCredithours;        
     }
     ///////////////////////////////////////////////////////////
     const bool operator>(const Student& s2)
     {
           if(GPA ==s2.GPA)
           {
                if (Credithours > s2.Credithours)
     return true;
   else
     return false;    
                 
           }
           else
           {
    if (GPA > s2.GPA)
     return true;
   else
     return false;
          }
     }
     /////////////////////////////////////////////////////////////////////////
        const bool operator<(const Student& s2)
     {
            if(GPA ==s2.GPA)
           {
                if (Credithours< s2.Credithours)
     return true;
   else
     return false;    
                 
           }
           else
           {
    if (GPA < s2.GPA)
     return true;
   else
     return false;
          }
     }
     ///////////////////////////////////////////////////////
     void display()
     {
   cout << "\nRoll Number: " << Rollnumber ;
       cout << "\nGPA: " << GPA ;
     cout << "\nCredit hours: " << Credithours<<endl;
}

};
///////////////////////////////////////////////////////////////////////////////////
int main()
{
    Student st1(32323,3.3,3);
    Student st2(32323,3.3,4);
    st1.display();
    st2.display();

    if(st1>st2)
       cout<<"\n Student 1 is greater ";
    else
        cout<<"\n Student 2 is greater ";
   
   
       if(st1<st2)
       cout<<"\n Student 1 is less then";
    else
        cout<<"\n Student 2 is less then ";

  system("pause");
}

no image
  • Title : Student Class Implementation in C++ Example Code
  • Posted by :
  • Date : 03:55
  • Labels :





  • Blogger Comments
  • Facebook Comments

0 comments:

Post a Comment

Top