c++ to calculate the sum of 2 interger no. by using constructor concept

//wap to calculate the sum of 2 interger no. by using constructor concept
#include<iostream>
using namespace std;
class sum
{
int a,b,s;
public:
sum(int ,int );
void display();
};
sum::sum(int x ,int y)
{
a=x;
b=y;
s=a+b;
}
void sum::display()
{
cout<<“The sum is : “<<s<<“n”;
}

int main()
{
sum ad=sum(10,20);
ad.display();
return (0);
}

OUT- The sum is : 30
//Add two number using constructor without display function.
#include<iostream>
using namespace std;
//class containing methods and variables.
class add
{
    int num1,num2,sum;
    public :
    add(int x,int y);
    
  
};
//defining methods using scope resolution opertor.
add::add(int x,int y)
{
num1=x;
num2=y;
    sum=x+y;
    cout<<“The sum is : “<<sum<<“n”;
}
int main()
{
    add b=add(10,20);
    
}
    OUT- The sum is : 30

Leave a Comment

Your email address will not be published. Required fields are marked *

Hire a server Expert to resolve the issue Now.

Hire a server Expert to resolve the issue Now.

Resolve this issue in just 5$ from https://serverexpert.io

 

You have Successfully Subscribed!

Open chat