Experiments for OOP lab

 #include<bits/stdc++.h>

using namespace std;

/**********************Experiment no. 1*********************/

/*

 * Aim: To show the concept of classes and objects

 */


class Demo{

  int roll;

  char name[10];

  void entry(){

      cout<<"Enter Roll No. and Name\t";

      cin>>roll>>name;

  }

  public:

  void show(){

      entry();

      cout<<"\nroll\t"<<roll<<"\nname\t"<<name;

  }

};

/**********************Experiment no.2*********************/

/*

Aim: Defining member function outside the class 

*/

/*

Prototype className:: function(arguments){

    //Body

}

*/

class Demo1{

 int num;

 public:

 void entry(){

     cout<<"\nEnter any no.";

     cin>>num;

 }

 void check();

};

void Demo1::check(){

    if(num%2==0){

        cout<<"\nNo is even";

    }

    else{

        cout<<"\nNo is odd";

    }

}

int main() {

//   Demo obj;

//   obj.show();

Demo1 obj1;

obj1.entry();

obj1.check();

    return 0;

}

Comments

Popular Posts