C++ Program to add two numbers by defining function Outside the class

Program to add two numbers by defining function Outside the class.

C++ Program to add two numbers by defining function Outside the class.We can keep the declaration of the member function inside the class,whereas, its definition can be done outside the class.

  • Here void getdata() and void display() are the member function of class scan.
  • Both the functions are declared inside the class and their definition has given outside the class.

Program

#include<iostream.h>
#include<conio.h>
class scan
{
int x,y,z;
public:
void getdata();
void display();
};

void scan::getdata()
{
 cout<<"Enter First number:- ";
 cin>>x;
 cout<<"Enter Second number:- ";
 cin>>y;
 z=x+y;
}
void scan::display()
{
cout<<"Sum of two number is:- "<<z;
}
void main()
{
clrscr();
scan s1;
s1.getdata();
s1.display();
getch();
}

OUTPUT:-

Program to add two numbers by defining function Outside the class


Comment below if you are facing any problem


Also read

C++ program to print 3×3 matrix using class
C++ program to print alternate elements from an array
C++ program to Insert an element Into sorted array


Summary
C++ Program to add two numbers by defining function Outside the class
Article Name
C++ Program to add two numbers by defining function Outside the class
Description
We can keep the declaration of the member function inside the class,whereas, its definition can be done outside the class
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

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