- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
Chapter 8 Friends , Overloaded Operators,and Arrays in Classes 1. Solutions to and Remarks on Selected Programming Problems 1. Modify Money class. No solution is provided for this exercise. 2. Implement constructors and overload , , +, and * for class Pair. //Chapter 8Programming Problem #2 //Enhance Self Test Problem 17 by completing the // overloading of operator and for class Pair // Implement: // The default constructor // A one int parameter constructor that // sets the first member to the parameter // and the second to 0. // A two int parameter constructor. // Overload * on a Pair and an int // (x, y)*c = (x*c, y*c) // Overload + on two objects of type Pair. // (a, b) + (c, d) = (a + c, b + d) #include iostream using namespace std; class Pair { public: Pair(); Pair(int first, int second); Pair(int first); int accessFirst(); int accessSecond(); // other members and friends friend Pair operator+(const Pair, const Pair); friend Pair operator*(const Pair, int); friend istream operator (istream, Pair); friend ostream operator (ostream, const Pair); private: int f; int s; }; int main() { Pair x; Pair y(2,3); Pair z(4); cout x.accessFirst() endl; cout x.accessSecond() endl; cout y.accessFirst() endl; cout y.accessSecond() endl; cout z.accessFirst() endl; cout z.accessSecond() endl; cout endl; cout x x endl y y endl z z endl endl; x = y + z; cout y + z x endl; cout y * 2 y * 2 endl; return 0; } Pair operator+(const Pair lhs, const Pair rhs) { return Pair(lhs.f + rhs.f, lhs.s + rhs.s); } Pair operator*(const Pair lhs, int rhs) { return Pair(lhs.f * rhs, lhs.s * rhs); } istream operator (istream ins, Pair second) { char ch; ins ch; // discard init ( ins second.f; ins ch; // discard comma , ins second.s; ins ch; // discard final ( return ins; } ostream operator (ostream outs, const Pair second) { outs (; outs second.f; outs ,
您可能关注的文档
最近下载
- (2024秋新版)人教PEP版三年级英语上册全册教案.doc
- ISO15189质量手册--输血科通用模版(文档-100页).docx VIP
- RBA6.0版标准资料学习课件.ppt VIP
- 2025年北森领导力测试题及答案.doc VIP
- AI政务大厅业务平台架构方案.pptx VIP
- 医疗器械临床应用管理办法.pptx VIP
- 征信简版电子版PDF个人信用报告必威体育精装版版2024年可编辑带水印模板.pdf VIP
- 人工智能对人类发展利大于弊VS弊大于利辩论赛正方辩词一辩、二辩、三辩、四辩发言稿.pptx VIP
- 人工智能对人类发展利大于弊VS弊大于利辩论赛 反方辩词一辩、二辩、三辩、四辩发言稿.docx VIP
- 北森在线测评题库及答案.doc VIP
文档评论(0)