类与对象
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; }
相关文章推荐
- LSGO软件技术团队2015~2016学年第十三周(1123~1129)总结
- WebView 使用总结
- 韩信点兵
- MyBatis,动态传入表名,字段名的解决办法
- poi使用HSSFWorkbook 导出excel
- Web开发
- android中三种onClick事件的实现,与对比
- C# Learn About 数据库注册
- Win7系统打开默认程序出现“软件管理-打开未知文件”窗口的故障分析及解决方法
- 利用HTML制作一二级导航菜单
- LSGO软件技术团队2015~2016学年第十二周(1116~1122)总结
- 2015年下半年阅读书单
- LSGO软件技术团队2015~2016学年第十一周(1109~1115)总结
- linux基础知识总结
- citrix receiver 添加账户报错:无法使用此服务地址添加您的账户
- 2016年01月01日
- CentOS Linux修改系统时区
- Java部分总结图片版(已经加上原图链接下载!!!)
- LeetCode96 Unique Binary Search Trees
- rocketMq-demo