source code name: oop2.cpp
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class sumdigitoop
{
int n;
public:
void get(int m)
{
n=m;
}
void sumdigit()
{
int d,sum=0;
while(n>0)
{
d=n%10;
sum=sum+d;
n=n/10;
}
cout<<"\n sum of digits: "<<sum;
}
};
void main()
{
clrscr();
cout<<"object oriented program: ";
sumdigitoop ob;
ob.get(12345);
ob.sumdigit();
getch();
}
output:
object oriented program:
sum of digits: 15
0 Comments
Post a Comment