欢迎来到天天文库
浏览记录
ID:55163618
大小:56.00 KB
页数:8页
时间:2020-04-29
《实验六指针报告.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、中国矿业大学计算机学院实验报告课程名称:《高级语言设计语言》实验名称:实验六指针班级:计科11-2班姓名:李东学号:仪器组号:********实验日期:12.5.10实验报告要求:1.实验目的2.实验内容3.实验步骤4.运行结果5.流程图6.实验体会一、实验目的1.掌握指针变量的定义和初始化、指针的间接访问、指针的加减运算和指针表达式;2.掌握用指针处理数组和字符串的方法3.掌握用指针作为函数参数的方法4.理解引用的概念,掌握引用的应用方法。5.了解指向函数的指针变量;6.了解指针与链表关系。二、实验内容注:本章实现要求用指针或引用方
2、法处理1.分析如下程序的结果(数组与指针的关系)#includeusingnamespacestd;voidmain(){chars1[5]={‘m’,‘n’,‘p’,‘q’,‘ ’};char*ps=s1;cout<3、ntinue2.输入3个字符串,按由小到大顺序输出。(1)用字符数组方法(2)用string方法实验步骤:#include#includeusingnamespacestd;voidcampare(char*&a,char*&b){char*c;if(strcmp(a,b)>0){c=a;a=b;b=c;}}voidcop(string&a,string&b){stringc;c=a;a=b;b=c;}voidmain(){chara1[]="acdedg";chara2[]="abcded";ch4、ara3[]="dsdfae";cout<<"用字符数组方法,初始化的字符数组为:"<5、3;cout<<"用string方法"<>s1>>s2>>s3;cout<<"初始化的结果为:"<s2)cop(s1,s2);if(s1>s3)cop(s1,s3);if(s2>s3)cop(s2,s3);cout<<"用string方法,排序后的结果为:"<6、;}运行结果:3.编写一程序,输入月份,输出该月的英文名。例如,输入“3”,则输出March,要求用指针数组实现。实验步骤:#include#includeusingnamespacestd;voidmain(){stringa[12]={"January","Feburary","March","April","May","June","July","August","September","October","November","December"};intt;cout<<"请输入月份:";c7、in>>t;//cout<usingnamespacestd;intmain(){inti,k,m,n,num[50],*p;cout<<"输入n:";cin>>n;p=num;for(i=0;i8、*(p+i)!=0)k++;if(k==3){*(p+i)=0;k=0;m++;}i++;if(i==n)i=0;}while(*p==0)p++;cout<<"最后数是第"<<*p<<"个"<
3、ntinue2.输入3个字符串,按由小到大顺序输出。(1)用字符数组方法(2)用string方法实验步骤:#include#includeusingnamespacestd;voidcampare(char*&a,char*&b){char*c;if(strcmp(a,b)>0){c=a;a=b;b=c;}}voidcop(string&a,string&b){stringc;c=a;a=b;b=c;}voidmain(){chara1[]="acdedg";chara2[]="abcded";ch
4、ara3[]="dsdfae";cout<<"用字符数组方法,初始化的字符数组为:"<5、3;cout<<"用string方法"<>s1>>s2>>s3;cout<<"初始化的结果为:"<s2)cop(s1,s2);if(s1>s3)cop(s1,s3);if(s2>s3)cop(s2,s3);cout<<"用string方法,排序后的结果为:"<6、;}运行结果:3.编写一程序,输入月份,输出该月的英文名。例如,输入“3”,则输出March,要求用指针数组实现。实验步骤:#include#includeusingnamespacestd;voidmain(){stringa[12]={"January","Feburary","March","April","May","June","July","August","September","October","November","December"};intt;cout<<"请输入月份:";c7、in>>t;//cout<usingnamespacestd;intmain(){inti,k,m,n,num[50],*p;cout<<"输入n:";cin>>n;p=num;for(i=0;i8、*(p+i)!=0)k++;if(k==3){*(p+i)=0;k=0;m++;}i++;if(i==n)i=0;}while(*p==0)p++;cout<<"最后数是第"<<*p<<"个"<
5、3;cout<<"用string方法"<>s1>>s2>>s3;cout<<"初始化的结果为:"<s2)cop(s1,s2);if(s1>s3)cop(s1,s3);if(s2>s3)cop(s2,s3);cout<<"用string方法,排序后的结果为:"<6、;}运行结果:3.编写一程序,输入月份,输出该月的英文名。例如,输入“3”,则输出March,要求用指针数组实现。实验步骤:#include#includeusingnamespacestd;voidmain(){stringa[12]={"January","Feburary","March","April","May","June","July","August","September","October","November","December"};intt;cout<<"请输入月份:";c7、in>>t;//cout<usingnamespacestd;intmain(){inti,k,m,n,num[50],*p;cout<<"输入n:";cin>>n;p=num;for(i=0;i8、*(p+i)!=0)k++;if(k==3){*(p+i)=0;k=0;m++;}i++;if(i==n)i=0;}while(*p==0)p++;cout<<"最后数是第"<<*p<<"个"<
6、;}运行结果:3.编写一程序,输入月份,输出该月的英文名。例如,输入“3”,则输出March,要求用指针数组实现。实验步骤:#include#includeusingnamespacestd;voidmain(){stringa[12]={"January","Feburary","March","April","May","June","July","August","September","October","November","December"};intt;cout<<"请输入月份:";c
7、in>>t;//cout<usingnamespacestd;intmain(){inti,k,m,n,num[50],*p;cout<<"输入n:";cin>>n;p=num;for(i=0;i8、*(p+i)!=0)k++;if(k==3){*(p+i)=0;k=0;m++;}i++;if(i==n)i=0;}while(*p==0)p++;cout<<"最后数是第"<<*p<<"个"<
8、*(p+i)!=0)k++;if(k==3){*(p+i)=0;k=0;m++;}i++;if(i==n)i=0;}while(*p==0)p++;cout<<"最后数是第"<<*p<<"个"<
此文档下载收益归作者所有