您的位置:首页 > 其它

类与对象

2016-01-01 15:20 316 查看

类与对象1(类测试程序)

题目描述:

Description

*C++*下面是一个类的测试程序,编写能使用如下测试程序的类Test:

int  main()

{      int a,b;

Test  x;

while(cin>>a>>b)

{       x.intx(a,b);

x.printx();

}

return 0;

}

输入两个整数a和b,计算a-b。


Input

包含多组,每组测试有2个整数a和b。

Output

输出算式a-b。

Sample Input

300 100

100 300

Sample Output

300-100=200

100-300=-200

代码区

#include<iostream>
using namespace std;
class Text
{
int a,b;
public:
void Init(int c,int d);
void printx();
private:
int x;
};
void Text::Init(int c,int d)
{
a = c;
b = d;
x=a-b;
}
void Text::printx()
{
cout<<a<<"-"<<b<<"="<<x<<endl;
}
int  main()
{
int a,b;
Text  x;
while(cin>>a>>b)
{
x.Init(a,b);
x.printx();
if(0==a&&0==b)//输入 0 0时退出
break;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: