您的位置:首页 > 编程语言 > C语言/C++

C++:类与对象1(类测试程序)

2016-01-08 14:08 357 查看

C++:类与对象1(类测试程序)

题目描述:

Description

下面是一个类的测试程序,编写能使用如下测试程序的类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 Test
{
int a,b;
public:
void intx(int a,int b)
{
this->a=a;
this->b=b;

}
void printx()
{
cout<<a<<"-"<<b<<"="<<a-b<<endl;
}
};
int  main()

{
int a,b;

Test  x;

while (cin>>a>>b)

{
x.intx(a,b);

x.printx();

}

return 0;

}


若有更好的方法,请留下的你的建议。欢迎评论!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: