西安石油大学面向对象程序设计功能与改错

上传人:ni****g 文档编号:542571070 上传时间:2023-12-24 格式:DOC 页数:16 大小:59KB
返回 下载 相关 举报
西安石油大学面向对象程序设计功能与改错_第1页
第1页 / 共16页
西安石油大学面向对象程序设计功能与改错_第2页
第2页 / 共16页
西安石油大学面向对象程序设计功能与改错_第3页
第3页 / 共16页
西安石油大学面向对象程序设计功能与改错_第4页
第4页 / 共16页
西安石油大学面向对象程序设计功能与改错_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《西安石油大学面向对象程序设计功能与改错》由会员分享,可在线阅读,更多相关《西安石油大学面向对象程序设计功能与改错(16页珍藏版)》请在金锄头文库上搜索。

1、word面向对象程序设计期末综合练习五功能与改错指出程序或函数的功能1. #include void main() int i,s=0; for(i=2;i=30;i+=2) s+=i*i; couts=sendl; 2. #include #include #includevoid main()int i=10,a;while(i0) a=rand()%100+10; int j, k=int(sqrt(a)+1e-5); /sqrt(x)为求x的平方根函数 for(j=2; jk) couta ; i-;3. void trans(int x) char a10; int i=0,rem;

2、 do rem=x%16; x=x/16; if(rem0) couta-i; coutendl; 4. #includedouble f1(int n) double sign=1,s=1;for(int i=2;ia;coutf1(a)endl;5. double f1(double a, double b, char op) switch(op) case +: return a+b; case -: return a-b; case *: return a*b; case /: if(b=0) coutdivided by 0!endl; exit(1); else return a/

3、b; default: coutoperator error!endl; exit(1); 6. #include#includevoid main()int x,y;cinx; y=int(sqrt(x); /sqrt(x)为求x的算术平方根for(int i=1;i=y;i+)if(x%i=0) coutx=i*x/iendl; 7. #include void main() int i,p=1,s=0; int N; coutN; for(i=1;i=N;i+) p*=i; s+=p; coutsendl; 8. #include#include#includeconst N=10;in

4、t ff(int x, int y) int z;coutx+yz;if(x+y=z) return 1; else return 0;void main()int a,b,c=0;srand(time(0); /初始化随机数序列for(int i=0;iN;i+) a=rand()%20+1; /rand()函数产生0-32767之间的一个随机数b=rand()%20+1;c+=ff(a,b);cout得分:c*10endl; 9. int s1(int n)int x;if(n=1) x=1;else x=s1(n-1)+n*n;return x; 10. void fun5(char*

5、a, const char* b)while(*b) *a+=*b+;*a=0; 11. templatebool fun8(T a, int n, T key)for(int i=0;in;i+)if(ai=key) return true;return false ;12. void f2(double a, int n)int i; double sum=0;for(i=0;in;i+) sum+=ai;sum/=n;for(i=0;i=sum) coutai;coutendl;13. void f4(char aMN)int c1,c2,c3;c1=c2=c3=0;for(int i=

6、0;iM;i+)if(strlen(ai)=5 & strlen(ai)15) c2+;else c3+;coutc1c2c3endl; 14. void fun3(int aN, int m, int& row, int& col)int x=a00;row=col=0;for(int i=0;im;i+)for(int j=0;jx) x=aij; row=i; col=j; 15. int fun6(int m, int n, int b=2)if(mb & nstr2i) return 1;else return -1;if(str1i=str2i) return 0;else if(

7、str1istr2i) return 1;else return -1;18. IntNode* FindMax(IntNode *f)if(!f) return NULL;IntNode *p=f;f=f-next;while(f) if(f-datap-data)p=f;f=f-next;return p; 假定IntNode的类型定义为: struct IntNode int data; /结点值域 IntNode* next; /结点指针域 ;19. intCount(IntNode *f) if(!f) return 0; int c=0;while(f) c+;f=f-next;r

8、eturn c; 假定IntNode的类型定义为: struct IntNode int data; /结点值域 IntNode* next; /结点指针域 ;20. voidOutput(IntNode *f) if(!f) return;while(f) coutdatanext; coutendl; 假定IntNode的类型定义为: struct IntNode int data; /结点值域 IntNode* next; /结点指针域 ;21. voidInput(IntNode*& f) int n; coutn; while(n0); if(n=0) f=NULL; return; f=new IntNode; IntNode* p=f; cout从键盘输入nnext=new IntNode; cinp-data; p-next =NULL; p=f; f=f-next; delete p; 假定IntNode的类型定义为: struct IntNode int data; /结点值域 IntNode* next; /结点指针域 ;

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

当前位置:首页 > 资格认证/考试 > 自考

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