65,211
社区成员
发帖
与我相关
我的任务
分享
#include"iostream"
#include"cstdlib"
#include"cmath"
using namespace std;
class Armstrong
{
public:
void show_info();
Armstrong();
Armstrong(long new_data);
private:
long data;
bool equal();
};
Armstrong::Armstrong():data(0)
{
//Body intentionally empty
}
Armstrong::Armstrong(long new_data):data(new_data)
{
//Body intentionally empty
}
bool Armstrong::equal()
{
long temp=data,sum=0;
int count=0,i;
while(temp)
{
count++;
temp/=10;
}
temp=data;
while(temp)
{
i=temp%10;
sum+=pow(i,count);
temp=temp/10;
}
if(data==sum)
return true;
else
return false;
}
void Armstrong::show_info()
{
if(equal())
cout<<"The number your enter is a Armstrong"<<endl;
else
cout<<"The number your enter is not a Armstrong"<<endl;
}
int main()
{
long a;
cout<<"Please enter the number"<<endl;
cin>>a;
Armstrong check(a);
check.show_info();
return 0;
}