Monday, 28 December 2015

C++ program to demonstrate the concept of Object Oriented Programming Structure(OOPS)

// C++ program to demonstrate the concept of Object Oriented Programming Structure(OOPS)

#include<iostream>

using namespace std;

class MarkSheet
{
     int marks;

     public :

     void setMarks(int marks) // setter function
     {
          this->marks = marks;
     }

     int getMarks() // getter function
     {
          return this->marks;
     }

}; // end of class MarkSheet

int main()
{
     MarkSheet objA; // object A of class MarkSheet
     MarkSheet objB; // object B of class MarkSheet
     int temp;

     // propmts the user to enter the marks of student A
     cout<<" Enter the marks of student A : ";
     cin>>temp;
     objA.setMarks(temp); // uses the setter function to set the marks of student A

     // propmts user to enter the marks of student B
     cout<<" Enter the marks of student B : ";
     cin>>temp;
     objB.setMarks(temp); // uses the setter function to set the marks of student B

     cout<<"\n ---------- Marks of A and B are as follows ------------ \n";
     cout<<" Marks of student A : "<<objA.getMarks(); // displays the marks of student A
     cout<<"\n Marks of student B : "<<objB.getMarks(); // displays the marks of student B
     return 0;
}// end of main


Please do comment if you don't understand any part or want to know more or just want to say thanks. I love programming and love to teach my friends. Your suggestions and appreciation will make this blog much better.

------ OUTPUT ----- 

No comments:

Post a Comment