小伙伴们, 还在为不知道怎么下手而头疼吗, 我们程序竞赛协会来帮你们啦~\(≧▽≦)/~啦啦啦。
另外, 如果有对编程含有浓厚兴趣的同学, 我们随时欢迎你们的加入哟~~。
以下代码仅供参考, 如果你直接copy导致课设不及格, 我们可不服责任哟!!!(如果有问题的话, 可以在下面留言哦, 话说up主编程水平就这样, 有错轻喷啊)
策划:谭兆飞
编程:管怀文
协助:一号人员要求给她打码╮(╯_╰)╭,干脆二号也打码好了o(╯□╰)o(其实只是提供了题目啦~)
面向对象部分_201
#include <iostream>
#include <iomanip>
using namespace std;
class PALIN
{
private:
int low, up;
int a[100];
int Count;
public:
PALIN(int, int);
int palin(int);
void fun();
void show();
};
PALIN::PALIN(int t1, int t2)
{
Count = 0;
low = t1;
up = t2;
}
int PALIN::palin(int x)
{
int f[10], i;
for (i = 0; x > 0; i++)
{
f[i] = x % 10;
x /= 10;
}
for (int j = 0; j <= i / 2; j++)
{
if (f[j] != f[i - j - 1])
{
return 0;
}
}
return 1;
}
void PALIN::fun()
{
for (int i = low; i <= up; i++)
{
if (palin(i * i))
{
a[Count++] = i;
}
}
}
void PALIN::show()
{
cout << "count=" << Count << endl
<< left << setw(10) << "x" << "x * x" << endl;
for (int i = 0; i < Count; i++)
{
cout << left << setw(10) << a[i] << a[i] * a[i] << endl;
}
}
int main()
{
PALIN p(100, 1000);
p.fun();
p.show();
return 0;
}