How to Make a Class in C++

Class is very important term in Object Oriented Programming .Class is abstract data type which mean it defined by user . In this problem a class with the name LEP and it contain two variables. In main function we just make a object.

 Source Code 

#include<iostream>
using namespace std;

  class  LEP
  {
   int num1,num2;
  public:
   void set_values(int ,int );
  int add()
  {
   return (num1+num2);
  } 
  
  };
  void LEP::set_values(int a,int b)
  {
   num1=a;
   num2=b;
  }
 int main ()
 {
  LEP L;
  int a,b;
  cout<<" Enter Your Number Here .....! : \n ";
  cin>>a;
  cout<<" Enter Your Number Here .....! : \n ";
  cin>>b;
  L.set_values(a,b);
  cout<<" This is the Sum of Two Numbers :" << L.add();
 }

Output of the Program


C++ Programming


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment