c++面向对象-实例题集锦.doc

  1. 1、本文档共25页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

文档评论(0)

一叶轻舟 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档