C++实验2报告-面向对象程序设计.docx
《C++实验2报告-面向对象程序设计.docx》由会员分享,可在线阅读,更多相关《C++实验2报告-面向对象程序设计.docx(7页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、C+实验2报告-面向对象程序设计 Lab Exercises Class: Name: StuID: Date: 2022-12-5 Score: Lab Exercise 1 String Concatenation I Lab Objectives In this lab, you will practice: 1) Overloading the + operator to allow String objects to be concatenated. 2) Writing function prototypes for overloaded operators. 3) Using o
2、verloaded operators. II Description of the Problem String concatenation(连接)requires two operandsthe two strings that are to be concatenated. In the text, we showed how to implement an overloaded concatenation operator that concatenates the second String object to the right of the first String object
3、, thus modifying the first String object. In some applications, it is desirable to produce a concatenated String object without modifying the String arguments. Implement operator+ to allow operations such as string1 = string2 + string3; in which neither operand is modified. III Sample Output IV Prob
4、lem-Solving Tips 1. The overloaded + operator should be a member function of class String and should take one parameter, a const reference to a String. 2. The + operator function should use return type String. 3. The strcat function can be used to concatenate pointer-based strings. V Your Solution #
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C+ 实验 报告 面向 对象 程序设计
限制150内