



全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Henan University of Technology Experiments ReportThe 7th experiment TemplateLab ExercisesClass: Name: Date: Score: Lab Exercise Overloading printArrayI Lab ObjectivesIn this lab, you will practice:1) Overloading a function template for printing an array.2) Using function templates to create function-template specializations.II Description of the Problem Overload function template printArray of Fig. 14.1 so that it takes two additional integer arguments, namely int lowSubscript and int highSubscript. A call to this function will print only the designated portion of the array. Validate lowSubscript and highSubscript; if either is out of range or if highSubscript is less than orequal to lowSubscript, the overloaded printArray function should return 0; otherwise, printArray should return the number of elements printed. Then modify main to demonstrate both versions of printArray on arraysa, b and c (lines 2325 of Fig. 14.1). Be sure to test all capabilities of both versions of printArray.III Sample OutputIV Problem-Solving Tips1. To overload the printArray function template, declare another function template, also named printArray, that takes two additional int parameters, lowSubscript and highSubscript.2. When iterating over the range from lowSubscript to highSubscript, make sure to include both values within the range, to avoid an off-by-one error.V Your Solution/ Lab Exercise: TemplateOverload.cpp/ Using template functions#include using std:cout;using std:endl;templatevoid printArray( const T *array, int count )for ( int i = 0; i count; i+ )cout array i ;cout endl;templateint printArray( const T *array, int size, int lowSubscript, int highSubscript )if (lowSubscript =size )return 0;int count = 0;for ( int i = 1; i 3; i+ )count+;cout array i ; cout n;return count; int main() const int ACOUNT = 5; const int BCOUNT = 7; const int CCOUNT = 6; int a ACOUNT = 1, 2, 3, 4, 5 ; double b BCOUNT = 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 ; char c CCOUNT = HELLO; int elements; cout nUsing original printArray functionn; printArray( a, ACOUNT ); cout Array a contains:n; elements =printArray( a,5,0,ACOUNT - 1 ); cout elements elements were outputn; cout Array a from positions 1 to 3 is:n; elements =printArray( a,5,1,3 ); cout elements elements were outputn; cout Array a output with invalid subscripts:n; elements =printArray( a,5,-1,10 ); cout elements elements were outputnn; cout nUsing original printArray functionn; printArray( b, BCOUNT ); cout Array b contains:n; elements =printArray( b,7,0,BCOUNT - 1 ); cout elements elements were outputn; cout Array b from positions 1 to 3 is:n; elements =printArray( b,7,1,3 ); cout elements elements were outputn; cout Array b output with invalid subscripts:n; elements =printArray( b,7,-1,10 ); cout elements elements were outputnn; cout nUsing original printArray functionn; printArray( c, CCOUNT ); cout Array c contains:n; elements =printArray( c,6,0,CCOUNT - 2 ); cout elements elements were outputn; cout Array c from positions 1 to 3 is:n; elements =printArray( c,6,1,3 ); cout element
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 小肠胃肠间质瘤护理查房
- 2025年温州永嘉县乌牛街道社区卫生服务中心招聘劳务派遣人员1人考前自测高频考点模拟试题附答案详解
- 2025昆明市呈贡区卫生健康系统编外合同制专业技术人员招聘(7人)模拟试卷及一套参考答案详解
- 2025年宁波市卫生健康委部分直属事业单位公开招聘高层次人才69人(第二批)模拟试卷及答案详解(网校专用)
- 2025贵州银行纪检人员招聘11人模拟试卷完整参考答案详解
- 浙江国企招聘2025绍兴凯泰特种纤维科技有限公司招聘3人笔试历年参考题库附带答案详解
- 2025黑龙江黑河北安融媒体中心招聘12人笔试历年参考题库附带答案详解
- 2025青海品控军粮供应链有限公司招聘笔试历年参考题库附带答案详解
- 2025银联商务支付股份有限公司福建分公司多地市招聘笔试历年参考题库附带答案详解
- 2025重庆巫山城市建设(集团)社会招聘4人笔试历年参考题库附带答案详解
- 2025-2026学年人教版(2024)九年级物理全册第十四章 内能的利用(单元同步检测练习)(含答案)
- 第1课时 10的加、减法(教学设计)-2024-2025学年一年级上册数学人教版
- 2025至2030中国聚烯烃行业项目调研及市场前景预测评估报告
- 夜间红外成像算法优化-洞察及研究
- 2025四川达州宣汉县国有资产管理服务中心县属国有企业招聘劳动合同职工26人笔试历年参考题库附带答案详解
- 外国戏剧史课件
- (正式版)DB15∕T 4179-2025 《输氢管道工程施工规范》
- DB61T 1188-2018 足部修护技术规范
- 小区内垃圾清运合同范本
- 教师培训结核病防治知识课件
- GB/T 4129-2025声学用于声功率级测定的标准声源的性能与校准要求
评论
0/150
提交评论