文章
84
粉丝
408
获赞
33
访问
877.1k
#include<iostream>
#include<vector>
using namespace std;
class number{
private:
int num;
int rev_num;
public:
number(){}
number(int x);
~number(){}
void setvalue(int x);
void display();
};
number::number(int x)
{
num = x;
rev_num = 0;
int tmp;
while (x > 0) {
tmp = x%10;
rev_num *= 10;
rev_num += tmp;
x /= 10;
}
}
void number::setvalue(int x)
{
num = x;
rev_num = 0;
int tmp;
while (x > 0) {
tmp = x%10;
rev_num *= 10;
rev_num += tmp;
x /= 10;
}
}
void number::display()
{
cout << num << " " << rev_num << endl;
}
int main()
{
int num;
vector<number> vnum;
for (int i = 1; i <= 10; i++) {
cin >> num;
if (num == 0)
break;
number a(num);
vnum.push_back(a);
}
for (int i = 0; i < vnum.size(); i++)
vnum[i].display();
return 0;
}
登录后发布评论
销毁类的意思是不是要写一个析构函数啊