Program for destruction in Object-Oriented Programming.
Algorithm:
step1: create a maths class
step2: declared within a maths class private int variable, constructor and a showdata function
step3: initialize a variable ‘a’ to 100 within the constructor
step4: display ‘a’ value with the help of showdata function
step4: within the main function create an instance of the maths class to 'm'
step5: call a method of showdata function using ‘m’
Program Code:
# include<iostream>
using namespace std;
class maths
{
int a;
public:
maths();
void showdata();
};
maths :: maths()
{
cout<<"\n this is a constructor";
a=100;
}
void maths :: showdata()
{
cout<<"\n the value of a="<<a;
}
void main ()
{
maths m;
m.showdata();
}
Output:
This is a constructor
The value of a=100
Thanks
Mukesh Rajput
Post A Comment:
0 comments: