ImageVerifierCode 换一换
格式:DOCX , 页数:19 ,大小:23.60KB ,
资源ID:20186176      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/20186176.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(西安石油大学《面向对象程序设计》功能与改错Word文档下载推荐.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

西安石油大学《面向对象程序设计》功能与改错Word文档下载推荐.docx

1、exit(1);else return a/b;default:coutoperator error!6.#include#include void main()int x,y;cinx;y=int(sqrt(x);/sqrt(x)为求 x 的算术平方根 for(int i=1;i=y;i+)if(x%i=0)cout”x=”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#include const N=10;int f

2、f(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*a,const char*

3、b)while(*b)*a+=*b+;*a=0;11.template bool 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;i+)sum+=ai;sum/=n;i=sum)coutai;13.void f4(char aMN)int c1,c2,c3;c1=c2=c3=0;for(int i=0;iM;i+)if(strlen(ai)=5&strlen(ai)15)c2+;else c

4、3+;coutc1 c2 c3endl;14.void fun3(int aN,int m,int&row,int&col)int x=a00;row=col=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(str1istr2i)return 1;18.IntNode*FindMax(IntNode*f)if(!f)return NULL;IntNode*p=f;

5、f=f-next;while(f)if(f-datap-data)p=f;return p;假定 IntNode的类型定义为:struct IntNode int data;/结点值域 IntNode*next;/结点指针域 ;19.int Count(IntNode*f)if(!f)return 0;int c=0;while(f)c+;return c;20.void Output(IntNode*f)if(!f)return;while(f)coutdatanext;21.void Input(IntNode*&f)int n;coutn;while(n0);if(n=0)f=NULL;

6、return;f=new IntNode;cout”从键盘输入”nnext=new IntNode;cinp-data;p-next=NULL;p=f;delete p;22.int f(const char*s)int i=0;while(*s+)i+;return i;23.char*f(char*s)int n=strlen(s);char*r=new charn+1;i=a&sidata=x;/3 行 p-next=NULL;/4 行 if(list=NULL)return p;/5 行 NODE*p1=list;/6 行 while(p1-next!=NULL)p1=p1-next;

7、/7 行 p1=p;/8 行 return list;错误行的行号为_和_。分别改正为_和_。2.在下面的定义中,NODE是链表结点的结构,addToList 则是一函数,其功能是:将一个值为 x 的新结点添加到以 plist 为表头指针的链表的首部(即第一个结点的前面)并返回表头指针。函数中有两处错误,指出错误所在行的行号并提出改正意见。struct NODE int data;NODE*next;NODE*adndToList(NODE*plist,int x)/1 行 NODE*p;/2 行 *p=new NODE;/3 行 p-data=x;/4 行 p-next=NULL;/5 行

8、plist=p;/6 行 return p;/7 行 错误行的行号为_和_。3.假定要求下面程序的输出结果为“11/15”,其主函数中存在着三行语句错误,请指出错误语句行的行号并改正错误行。#include class Franction /定义分数类 int nume;/定义分子 int deno;/定义分母 public:/把*this 化简为最简分数,具体定义在另外文件中实现 void FranSimp();/返回两个分数*this 和 x 之和,具体定义在另外文件中实现 Franction FranAdd(const Franction&x);/置分数的分子和分母分别 0和 1 voi

9、d InitFranction()nume=0;deno=1;/置分数的分子和分母分别 n和 d void InitFranction(int n,int d)nume=n;deno=d;/输出一个分数 void FranOutput()coutnume/denoendl;void main()/1 行 /2 行 Franction a,b,c;/3 行 a.InitFranction(6,15);/4 行 b.InitFranction(1);/5 行 c.InitFranction();/6 行 c=FranAdd(a,b);/7 行 coutc.nume/c.denoendl;/8 行

10、/9 行 错误行的行号为_、_和_。分别改正为_、_和_。4.假定要求下面程序的输出结果为“23/20”,其主函数中存在着三条语句错误,请指出错误语句行的行号并改正。/输出一个分数 void FranOutput()coutnume/denoInitFranction(6,15);/5 行 b.InitFranction(3,4);/6 行 Franction c;/7 行 c.InitFranction();/8 行 c=a.FranAdd(b);/9 行 coutc.FranOutput()endl;/10 行 /11 行 错误行的行号为_、_和_。5.下面是一个类的定义,存在着 3处语法

11、错误,请指出错误行的行号并改正。class CE /1 行 private:/2 行 int a,b;/3 行 int getmin()return(ab?a:b);/4 行 public/5 行 int c;/6 行 void SetValue(int x1,int x2,int x3)/7 行 a=x1;b=x2;c=x3;/8 行 ;/9 行 int GetMin();/10 行;/11 行 int GetMin()/12 行 int d=getmin();/13 行 return(dc?d:c);/14行 /16 行 错误行的行号为_、_和_。6.下面程序段第 4-10 行中存在着三条

12、语句的语法错误,请指出错误语句的行号并改正。class A /1 行 int a,b;/2 行 const int c;/3 行 public/4 行 A():c(0);a(0);b(0)/5 行 A(int aa,int bb)c(aa+bb);a=aa;b=bb;/6 行 ;/7 行 A a,b(1,2);/8 行 A*x=&a,&y=b;/9 行 A*z=new A,w10;/10 行 错误行的行号为_、_和_。分别改正为_、_ 和_。Public:A():c(0),a(0),b(0)A(int aa,int bb):c(aa+bb)a=aa;7.下面程序段第 4-9 行中存在着三条语句

13、错误,请指出错误语句的行号并说明原因。/3 行 public:/4 行 A()a=b=c=0;/5 行 A(int aa,int bb):/7 行 A a,b(1,2,3);/8 行 A x(2,3),y(4);/9 行 错误行的行号为_、_和_。错误原因分别为_、_和_。8.下面程序段第 10-17 行中存在着三条语句错误,请指出错误语句的行号并说明原因。class A /1 行 int a;/2 行 public:/3 行 A(int aa=0):a(aa)/4 行 ;/5 行 class B /6 行 int a,b;/7 行 const int c;/8 行 A d;/9 行 publ

14、ic:/10 行 B():c(0)a=b=0;/11 行 B(int aa,int bb):d(aa+bb)/12 行 a=aa;c=aa-bb;/13 行 /14 行 /15 行 B a,b(1,2);/16 行 B x=a,y(b),z(1,2,3),;/17 行 错误行的行号为_、_和_。错误原因分别为_、_ 和_。9.假定要求下面程序输出结果为“d=800,f=60”,在第 4-23行中存在着三条语句错误,请指出错误语句的行号并改正。#include class A /1 行 int a10;int n;/3 行 A(int aa,int nn):n(nn)/4 行 for(int i

15、=0;i+)aai=ai;/5 行 /6 行 int Get(int i)return ai;/7 行 int SumA(int n);/8 行;/9 行 int A:SumA(int n)/10 行 int s=0;/11 行 for(int j=0;jn;j+)s+=aj;/12 行 return s;/13 行 /14 行 void main()/15 行 int a=2,5,8,10,15,20;/16 行 A x(a,6);/17 行 int d=1;/18 行 for(int i=0;i4;i+)d*=x.ai;/19 行 int f=SumA(6);/20 行 coutd=d,;

16、/21 行 coutf=fendl;/22 行 /23 行 错误行的行号为_、_和_。5 19 20 分别改正为_、_和_。10.下面是分数类 fract 的定义及测试主程序,在类定义及其友元函数定义中有两处错误,更正错误后程序应显示 41/28,请指出错误所在行的行号并给出改正意见。class fract int den;/分子 int num;/分母 public:fract(int d=0,int n=1):den(d),num(n)/1 行 friend fract&operator+=(fract,fract&);/2 行 void show()coutden/next=p;2.3

17、5 p=new NODE;p-next=plist;3.5 7 8 b.InitFranction(1,3);c=a.FranAdd(b);c.FranOutput()4.6 9 10 b-InitFranction(3,4);c=a-FranAdd(*b);c.FranOutput()5.5 9 12 public:int CE:GetMin()6.4 5 6 Public:7.5 8 9 在函数体给常量 c赋值 定义 b多一个参数 定义 y少一个参数 8.13 15 17 在函数体给常量 c赋值 缺少分号 定义 z 多一个参数 9.5 19 20 ai=aai;d*=x.Get(i);int f=x.SumA(6);10.2 5 friend fract&operator+=(fract&,fract);fract&f1,fract f2);

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1