The simple example of CLASS in C++, To find the reverse of a number using the class:
Program Code:
#include <iostream>
using namespace std;
class reverse
{
int a,rev,rem;
public:
void result();
};
void reverse :: result ()
{
rev=0;
cout<<"Enter any number: ";
cin>>a;
while(a!=0)
{
rem=a%10;
rev=rev*10+rem;
a=a/10;
}
cout<<endl<<"Reverse of the number is = "<<rev;
}
int main()
{
reverse r;
r.result();
}
using namespace std;
class reverse
{
int a,rev,rem;
public:
void result();
};
void reverse :: result ()
{
rev=0;
cout<<"Enter any number: ";
cin>>a;
while(a!=0)
{
rem=a%10;
rev=rev*10+rem;
a=a/10;
}
cout<<endl<<"Reverse of the number is = "<<rev;
}
int main()
{
reverse r;
r.result();
}
The output of the program is tested on www.jdoodle.com
Output:
Enter any number: 13211
Reverse of the number is = 11231
Reverse of the number is = 11231
Thanks
Mukesh Rajput
Mukesh Rajput
Post A Comment:
0 comments: