C++程序设计实验报告-数组、指针与字符串

上传人:豆浆 文档编号:24901321 上传时间:2017-12-08 格式:PDF 页数:8 大小:255.95KB
返回 下载 相关 举报
C++程序设计实验报告-数组、指针与字符串_第1页
第1页 / 共8页
C++程序设计实验报告-数组、指针与字符串_第2页
第2页 / 共8页
C++程序设计实验报告-数组、指针与字符串_第3页
第3页 / 共8页
C++程序设计实验报告-数组、指针与字符串_第4页
第4页 / 共8页
C++程序设计实验报告-数组、指针与字符串_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《C++程序设计实验报告-数组、指针与字符串》由会员分享,可在线阅读,更多相关《C++程序设计实验报告-数组、指针与字符串(8页珍藏版)》请在金锄头文库上搜索。

1、C程序设计实验报告Exercise 6 数组、指针与字符串1实验目的(1)学习使用数组(2)学习字符串数据的组织和处理。(3)学习标准C+库的使用。(4)掌握指针的使用方法。(5)练习通过Debug观察指针的内容及其所指的对象的内容(6)联系通过动态内存分配实现动态数组,并体会指针在其中的作用。(7)分别使用字符数组和标准C+库练习处理字符串的方法。2实验要求(1)编写并测试3*3矩阵转置函数,使用数组保存3*3矩阵。源程序代码:#includeusingnamespacestd;voidzhuanzhi(intb33)inti,j,t;for(i=0;iaij;zhuanzhi(a);cou

2、tusingnamespacestd;voidzhuanzhi(intb33) inti,j,t;for(i=0;iaij;zhuanzhi(a);coutusingnamespacestd;intmain() charstr1100,str2100,str200;inti,j;coutstr1;coutstr2;for(i=0;str1i!=0;i+)stri=str1i;for(j=0;str2j!=0;j+,i+)stri=str2j;stri=0;cout#includeusingnamespacestd;intmain() stringstr1,str2,str;coutstr1;c

3、outstr2;str=str1+str2;coutusingnamespacestd;classEmployeeprivate:char*name,*address,*city,*postCode;public:Employee(char*_name,char*_address,char*_city,char*_postCode) name=_name;address=_address;city=_city;postCode=_postCode;voidchange_name(char*_name) name=_name;voiddisplay() coutdisplay();coutcha

4、nge_name(haozhi);e-display();deletee;return0;运行结果:(6)定义包含5个元素的对象数组,每个元素都是Employee类型的对象。源程序代码:#includeusingnamespacestd;classEmployeeprivate:char*name,*address,*city,*postCode;public:Employee(char*_name,char*_address,char*_city,char*_postCode) name=_name;address=_address;city=_city;postCode=_postCode

5、;voidchange_name(char*_name) name=_name;voiddisplay() coutname :nameendl;coutaddress :addressendl;coutcity :cityendl;coutpostcode:postCodeendl;intmain() Employeee5= Employee(jiyu,shenyang,liaoning,100001),Employee(haozhi,shenyang,liaoning,100001),Employee(yangzhong,shenyang,liaoning,100001),Employee(zhuoma,shenyang,liaoning,100001),Employee(wangkai,shenyang,liaoning,100001);for(inti=0;i5;i+) ei.display();coutendl;return0;运行结果:3 总结体会数组和指针是程序中非常重要的部分,要区分好各维数组的初始化和指针的传递方式;使用数组名传递数据时,传递的也是地址;还要熟练掌握指针的运算;使用动态内存分配具有很大的好处,可以减小内存开辟,提高运算速度。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 其它文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号