- 1、本文档共25页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
-_
C++面向对象实例:
HYPERLINK /zhezh/p/3773356.html C++面向对象类的实例题目二
题目描述:
编写一个程序,设计一个产品类Product,其定义如下:
[cpp] HYPERLINK /zhezh/p/3773356.html \o view plain view plain HYPERLINK /zhezh/p/3773356.html \o copy copy HYPERLINK /zhezh/p/3773356.html \o print print HYPERLINK /zhezh/p/3773356.html \o ? ?
class?Product??
{??
????public:??
????????Product(char?*n,int?p,int?q);???//构造函数??
????????~Product();?????????????????????//析构函数??
????????void?buy(int?money);????????????//购买产品??
????????void?get()?const;???????????????//显示剩余产品数量???
????private:??
????????char?*?name;????//产品名称??
????????int?price;??????//产品单价??
????????int?quantity;???//剩余产品数量??
};???
并用数据进行测试。
code:
[cpp] HYPERLINK /zhezh/p/3773356.html \o view plain view plain HYPERLINK /zhezh/p/3773356.html \o copy copy HYPERLINK /zhezh/p/3773356.html \o print print HYPERLINK /zhezh/p/3773356.html \o ? ?
#includeiostream??
#includecstring??
using?namespace?std;??
class?Product??
{??
????????char?*name;??
????????int?price;??
????????int?quantity;??
????public:??
????????Product(char?*n,int?p,int?q);??
????????~Product();??
????????void?buy(int?money);??
????????void?get()const;??
};??
Product::Product(char?*n,int?p,int?q)??
{??
????name?=?n;??
????price?=?p;??
????quantity?=?q;??
}??
Product::~Product()??
{??
}??
void?Product::buy(int?money)??
{??
????int?r,n;??
????n?=?money/price;??
????r?=?money%price;??
????if(n??quantity)??
????{??
????????cout数量不够endl;??
????}??
????else??
????{??
????????quantity?-=?n;??
????????cout名称:name,单价:price元endl;??
????????cout顾客使用money元,购买n台,剩余r元endl;???
????}??
}??
void?Product::get()const??
{??
????cout产品:name,单价:price,剩余:quantity台endl;???
}??
int?main()??
{??
????Product?p(Iphone6,100,20);??
????p.buy(10);??
????p.get();??
????cout\n==========================\nendl;???
????p.buy(1000);??
????p.get();??
????return?0;???
}??
输出:
HYPERLINK /zhezh/p/3773355.html C++面向对象类的实例题目三
编写一个程序,设计一个满足如下要求的CData类。
(1)用下面的格式输出日期:日/月/年
(2)输出在当前日期上加一天后的日期
(3)设置日期
code:
[cpp] HYPERLINK /zhezh/p/377335
您可能关注的文档
- 02323.操作系统概论2014年10月份试题-真题及答案~.doc
- 5680t-GPO'N开局教学课件.doc
- 06092.工作分析自学考试.预习复习资料.doc
- 06092.工作分析最新预习复习资料.doc
- 06093.人力资源开发与~治理-自考-真题考点.doc
- 20000.525全国物管治理示范住宅小区标准及评分细则.doc
- 20000.m3d城市污水处理厂综合设计(含11个CAD作图图纸~)-优秀毕业设计资料规划方案设计.doc
- 20150727-'移动电子商务企业人才需求调查分析研究报告.doc
- 25030203数'字电子技术教学课件大纲-自动化专业.doc
- 2017-石油化工建设工程计划项目方案交工技术文件规定.doc
文档评论(0)