第六章作业
来源:互联网 发布:不用网络的监控摄像头 编辑:程序博客网 时间:2024/06/06 21:45
第五章 函数学习要求和实验
- 实验作业
1.调试分析课本每一个例题,有可能的话更改成2-3个方法的新程序;
2.编程实现课本每一个编程习题。
3. 有n个人围成一个圆圈,从第一个人开始报数,从1到3循环,凡是报3的退出圈子,问最后退出圈子的人是原来的几号。
4.一个班有5个学生,每一个学生有几门成绩(到底是几门自已定,或3或4或5或6),定义函数来完成下面功能:
计算第2门课成的平均分;
找出有2门以上成绩不及格的学生,并输出其学号和全部课程成绩;
找出平均成绩在90以上或者全部课程在85分以上的学生。
例题6.1
/**************************** *** 例6.1 *** ****************************/ #include<iostream> using namespace std; int main() { int a =10; int *p; p=&a; cout<<"a = "<<a<<endl; cout<<"p = "<<p<<endl; cout<<"&a ="<<&a<<endl; cout<<"*p ="<<*p<<endl; cout<<"&p ="<<&p<<endl; cout<<endl; *p =15; cout<<"a = "<<a<<endl; cout<<"p = "<<p<<endl; cout<<"&a = "<<&a<<endl; cout<<"*p ="<<*p<<endl; cout<<"&p ="<<&p<<endl; return 0; }</span></span>
例二:
/************************* *** 例题6.2 *** *************************/ #include<iostream> using namespace std; int main() { int a,b; int *p=&a,*q =&b, *tp; cout<<"请输入两个数:"; cin>>a>>b; if(a<b) { tp =p; p= q; q= tp; } cout<<"初始的两个数为:"<<a<<" "<<b<<endl; cout<<"从大到小排序后的数为:"<<*p<<" "<<*q<<endl; return 0; }</span></span>
例三:
/**************************** ** 例题6.3 ** *****************************/ #include<iostream> using namespace std; int main() { int a,b,t; int *p =&a,*q=&b; cout<<"请输入a和b的值:"; cin>>a>>b; cout<<"初始的两个数分别为:"<<a<<" "<<b<<endl; if(a<b) { t =*p;*p=*q; *q=t; } cout<<"从大到小排序后的数为:"<<*p<<" "<<*q<<endl; return 0; }</span></span>例四:
/********************************* *** 例题6.4 *** *********************************/ #include<iostream> using namespace std; int main() { int a = 10, b=19,*p1,*p2; p1 =&a; p2 =&b; cout<<boolalpha<<(*p1 == *p2)<<endl; cout<<boolalpha<<(p1 == p2)<<endl; return 0; } </span></span>例五:
/******************************* ** 例题6.5 ** *******************************/ #include<iostream> #include<iomanip> using namespace std; int main() { int a[10]; for(int i =0;i<10;i++) a[i]=2*(i+1); for(i = 0;i<10;i++) cout<<setw(4)<<a[i]; cout<<endl; return 0; } </span>
例六:
</pre><pre name="code" class="cpp">/***************************** *** 例题6.6 *** *****************************/ #include<iostream> using namespace std; int main() { char a[]="Hello world", b[20], *p, *q; p= a, q = b; for( ; *p!='\0';p++,q++) *q = *p; *q ='\0'; cout<<"string1 is:"; cout<<a<<endl; cout<<"string2 is:"; cout<<b<<endl; return 0; } </span>
例九:
/************************ ** 例题6.9 ** ************************/ #include<iostream> using namespace std; int main() { char s[50]; char *p; cout<<"Please input a string:"; cin.get(s,50); p = s; for( ;*p != '\0';) p++; cout<<"the length is : "<<p-s<<endl; return 0; }</span>
例十:
/******************************* **** 例题6.10 **** *******************************/ #include<iostream> using namespace std; int main() { int i =5, *p, **pp; p =&i; pp=&p; cout<<&i<<'\t'<<i<<endl; cout<<&p<<'\t'<<p<<'\t'<<*p<<endl; cout<<&pp<<'\t'<<pp<<'\t'<<*pp<<'\t'<<**pp<<endl; return 0; }</span>例二十:
/*************************** ** 例题6.20 ** ***************************/ #include<iostream> using namespace std; void lower(char *c); int main() { char ch; cout<<"input a uppercase character:"; cin>>ch; lower(&ch); cout<<"converted character:"; cout<<ch<<endl; return 0; } void lower(char *p) { if(*p>='A'&& *p<='Z') *p += 'a'-'A'; }</span>
0 0
- 第六章作业
- 第六章作业
- 第六章实验作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业
- 第六章作业part2
- 第六章作业
- 第六章作业
- 第六章作业part1
- 第六章作业
- 第六章作业2
- 第六章作业
- Android实现仿QQ登录可编辑下拉菜单
- 黑马程序员_高新技术
- leetcode - Pascal's Triangle
- xu han shu ji suan tu xing mian ji
- phoenix入门
- 第六章作业
- CPA,CPS,CPC,PPC,UV,PV等术语
- exec系列函数执行脚本文件
- Oracle 11gR2创建数据库实例
- iOS 常用宏
- kaptcha验证码使用
- ORA-12170 TNS 连接超时!
- 同步源码
- oracle类型处理函数