- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
c052014多态性
Object Oriented void main(){??? int i,n; float s;???? cout 请输入学生人数:;???? cin n;??? student stu;???? for( i=1; i=n; i++ )???? { cout 请输入第 i 个学生的分数:;?????? cin s;?????? stu.scoretotalcount( s );}?? ?cout 总分: student::sum() endl;?? ?cout 平均分: student::average() endl;} Object Oriented 编程2 某商店经销一种货物。货物购进和卖出时以箱为单位,各箱的重量不一样,因此,商店需要记录目前库存的总重量。现在用C++模拟商店货物购进和卖出的情况。 Object Oriented #includeiostream.h class Goods { public : Goods ( int w) { weight = w ; total_weight += w ; }//构造函数购进货物 ~ Goods() { total_weight -= weight ; }//析造函数售出货物 int Weight() { return weight ; } ; static int TotalWeight() { return total_weight ; } //静态成员函数返回货物总重量 Goods *next ;//用于构造链表的类指针 private : int weight ; static int total_weight ; } ; int Goods::total_weight = 0 ;//静态数据成员记录货物总重量 Object Oriented void purchase( Goods * f, Goods * r, int w ) { Goods *p = new Goods(w) ; p - next = NULL ; if ( f == NULL ) f = r = p ; else { r - next = p ; r = r - next ; } } void sale( Goods * f , Goods * r ) { if ( f == NULL ) { cout No any goods!\n ; return ; } Goods *q = f ; f = f - next ; delete q ; cout saled.\n ; } front 98 170 31 ^ 50 rear f r 200 w 200 ^ p 349 total_weight Object Oriented void main() { Goods * front = NULL , * rear = NULL ; int w ; int choice ; do { cout Please choice:\n ; cout Key in 1 is purchase,\nKey in 2 is sale,\nKey in 0 is over.\n ; cin choice ; switch ( choice ) // 操作选择 { case 1 : // 键入1,购进1箱货物 { cout Input weight: ; cin w ; purchase( front, rear, w ) ; // 从表尾插入1个结点 break ; } case 2 : // 键入2,售出1箱货物 { sale( front, rear ) ; break ; } // 从表头删除1个结点 case 0 : break ; // 键入0,结束 }
您可能关注的文档
最近下载
- 职称技术工作报告范文.docx VIP
- (2021年品管圈活动成果报告书)降低ICU患者身体约束率.docx VIP
- 解读学习2025《党政机关厉行节约反对浪费条例》培训课件.pptx VIP
- 《咏物诗》-公开课件.ppt VIP
- 品管圈QCC降低ICU患者约束缺陷率.pptx VIP
- 《党政机关厉行节约反对浪费条例》(2025)附新旧对照解读课件.pptx VIP
- 安徽单招考试2025、2025分类考试真题语文数学英语试题(含答案).pdf VIP
- 保证农民工工资及时支付的措施.docx VIP
- 2024届高考语文复习:诗歌鉴赏之题材 咏物言志诗 课件(共33张PPT).pptx VIP
- 手外伤急诊手术护理配合.pptx VIP
文档评论(0)