Structure of the Problem Requirements
In this problem we will learn 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 we make a class with the name LEP and it contain two variables and a add function . In main function we just make it object and produce the output. Here is the Source code of the problem which help you in better understanding .
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
Class in C++ |
Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.
0 comments:
Post a Comment