首页 C++课后习题答案(杨志强_龚沛增)_完整版

C++课后习题答案(杨志强_龚沛增)_完整版

举报
开通vip

C++课后习题答案(杨志强_龚沛增)_完整版第一章一、选择题CABCAACB二、填充题1.main()2.数字0-9、下划线3.字符串4.#include#define5.hex6..h7.语法错误和逻辑错误8.Insert/RemoveBreakpoint9..cpp10.Fileview三、简答题1.C++是C语言的超集。C++中的类和对象部分,C语言没有,C++是面向对象的程序设计。见教材P3。2.C/C++程序是由一个或多个函数组成,其中必须要有一个main()函数。在一个函数内,语句的执行是从上到下的。3.a?,3a,a-b,f(x),AD,a.t...

C++课后习题答案(杨志强_龚沛增)_完整版
第一章一、选择题CABCAACB二、填充题1.main()2.数字0-9、下划线3.字符串4.#include#define5.hex6..h7.语法错误和逻辑错误8.Insert/RemoveBreakpoint9..cpp10.Fileview三、简答题1.C++是C语言的超集。C++中的类和对象部分,C语言没有,C++是面向对象的程序设计。见教材P3。2.C/C++程序是由一个或多个函数组成,其中必须要有一个main()函数。在一个函数内,语句的执行是从上到下的。3.a?,3a,a-b,f(x),AD,a.txt,D$,∏,double4.C/C++程序书写形式自由。一行可以写多条语句,一条语句也可以分别写在不同行上。区别大小写字母。5.用尖括号时,预处理程序在系统指定的文件夹中寻找文件;用双引号时,预处理程序首先在当前文件所在的文件目录中寻找文件,若找不到再到系统指定的文件夹中查找。6.最好的调试手段是设置断点,并让程序运行到该断点,然后在Debug窗口观察各变量的值,从中发现错误。第二章一、选择题BCDCDCCCBB二、1.(x+y)!=(a+b)2.pow(log(10)+x*y),3)3.sin(w*u)/(cos(45*180/3.14)+3*pow(x,y))4.exp(3)+sqrt(2*x+3*y)5.fabs(x-y)+(x+y)/(3*x)6.1/(1/r1+1/r2+1/r3)三、1.a>d||b>d2.z=x>y?x:y3.x<0&&y<04.x+y>z||y+z>z||x+z>y5.(int)(x*100+0.5)/100.6.d>0&&d<=100&&d%2==07.x%5==0||y%5==08.n%k==0?n/k:n/k+1四、1#include"iostream.h"voidmain(){floatr,h,v;cin>>r>>h;v=3.1416*r*r*h;cout<>a>>b>>c;ave=(a+b+c)/3;min=(a>x;c1=x/100;c2=x/10%10;c3=x%10;x=100*c3+10*c2+c1;cout<>year;x=year%400==0||year%4==0&&year%100!=0;x!=0?cout<>year;x=(year%400==0||year%4==0&&year%100!=0)?'y':'n';cout<>x;y=log(x*x+3)/log(10)+3.14/2*cos(40*3.14/180);cout<0count(2)cin>>m>>nm=m-nn=n-m(3)n=mn=n/5m=m+5四、1.#include"iostream.h"#include"math.h"voidmain(){floatx,y;cout<<"inputx:"<>x;if(x<5)y=fabs(x);elseif(x<20)y=3*x*x-2*x+1;elsey=x/5;cout<<"x="<>s;switch(int(s)/1000){case0:p=0;break;case1:p=0.05;break;case2:p=0.08;break;case3:case4:p=0.1;break;default:p=0.15;break;}t=s*p;w=s-t;cout<<"纳税款="<1e-6;n++){t=t*n;e=e+1/t;}cout<<"e="<0)x1=x;elsex2=x;}while(fabs(x2-x1)>eps);cout<max){max=c[i][j];imax=i;jmax=j;}cout<<"max=c["<>ch;for(i=j=0;s[i]!='\0';i++)if(s[i]!=ch){s[j]=s[i];j++;}s[j]='\0';puts(s);}习题一、选择题1.下列叙述错误的是____A_____。A.主函数中定义的变量在整个程序中都是有效的B.复合语句中定义的变量只在该复合语句中有效C.其它函数中定义的变量在主函数中不能使用D.形式参数是局部变量2.若函数的形参为一维数组,则下列说法中错误的是____B、才_____。A.形参数组可以不指定大小B.函数调用时对应的实参只能是数组名C.函数调用时,系统会为形参数组分配存储单元D.函数中对形参的修改将会影响对应的实参值3.若函数的类型和return语句中的 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 达式的类型不一致,则____D_____。A.编译时出错B.运行时出现不确定结果C.不会出错,且返回值的类型以return语句中表达式的类型为准D.不会出错,且返回值的类型以函数类型为准4.下面的函数定义正确的是_____D____。A.floatf(floatx;floaty)B.floatf(floatx,y){returnx*y;}{returnx*y;}C.floatf(x,y)D.floatf(intx,inty){intx,y;returnx*y;}{returnx*y;}5.下面函数头的定义格式正确的是____C_____。A.voidsort(inta[n],intn)B.voidsort(inta[][],intn)C.voidsort(inta[],intn)D.voidsort(inta[],n)6.下面4个程序中输出结果是125的有____C_____。(1).#include"iostream.h"voidcube(intx){x=x*x*x;}voidmain(){intx=5;cube(x);cout< 说明 关于失联党员情况说明岗位说明总经理岗位说明书会计岗位说明书行政主管岗位说明书 形式为voidm(int,int*);利用函数m()对数5和整数j作函数m()定义的计算,正确的调用形式为_____C_____。A.m(&5,&j)B.m(5,j)C.m(5,&j)D.m(&5,j)8.设函数的说明为:voidfun(inta[],intm);,若有定义:inta[10],n,x;则下面调用该函数正确的是____A_____。A.fun(a,n);B.x=fun(a,n);C.fun(a[10],10);D.x=fun(a[],n);9.下面函数说明正确的是____C_____。A.voidf1(inta=3,intb,intc);B.voidf2inta,intb=3,intc);C.voidf3(inta,intb,intc=3);D.voidf4(inta,intb,int3);10.有两个函数分别为:intf(int);和intf(int,int=100);,则下面说法正确的是_____B_____。A.不能在同一个程序中定义B.可以在同一个程序中定义,但不可以重载C.可以在同一个程序中定义并可重载D.以上说法均错误11.以下几种函数 模板 个人简介word模板免费下载关于员工迟到处罚通告模板康奈尔office模板下载康奈尔 笔记本 模板 下载软件方案模板免费下载 的定义正确的是____A_____。A.templateTfun1(Ta,intb){……}C.templatevoidfun1(inta,intb){Ti;……}12.下面程序的输出结果是____B_____。#include"iostream.h"intm=10;voidf(intm,int&n){m=m+2;n=n+2;}voidmain(){intn=5;f(m,n);cout<<"m="<max)max=f(x)__;cout<0.0)_____x1=x_____;elseif(y1*y<0.0)_____x2=x_____;}while(fabs(y)>=eps___&&___fabs(x2-x1)>=eps);return(x);}doublef(doublex){returnx*x*x-5*x*x+16*x-80;}voidmain(){cout<<_____root(1,7)_____<=0;--i){ch[k++]=b[___c[i]___];}______ch[k]='\0'_______;}voidmain(){charch[10];intm,h;cin>>m>>h;convert(m,h,ch);cout<voidreplace(chars[],charc1,charc2){char*p=s;while(*p!='\0'){if(*p==c1)*p=c2;p++;}}voidmain(){chars[80],c1,c2;cin>>s;cin>>c1>>c2;replace(s,c1,c2);cout<doublearea(doubler,double*girth,doublepi=3.14159){*girth=2*pi*r;return(pi*r*r);}voidmain(){doubler,len,s;cin>>r;s=area(r,&len);cout<<"len="<voidfun(doubler,double&girth,double&area,doublepi=3.14159){girth=2*pi*r;area=pi*r*r;}voidmain(){doubler,len,s;cin>>r;fun(r,len,s);cout<<"len="<max){max=x[i][j];ii=i;jj=j;}return(max);}voidmain(){inti,j,t1,t2;floata[SIZE1][SIZE2];cout<<"enterthearray:\n";for(i=0;i#includevoidmystrcat(chars[],chart[],intn){intl1=strlen(s),l2=strlen(t);intk1=l1>n?n:l1,k2=l2>n?n:l2;for(inti=0;i>s>>t;cin>>n;mystrcat(s,t,n);cout<#include"stdio.h"char*dif(chars1[],chars2[]){inti=0;while(s1[i]==s2[i]&&s1[i]!='\0')i++;if(s1[i]!='\0')return(&s1[i]);elsereturnNULL;}voidmain(){chars[30],t[30];cin>>s>>t;char*p;if((p=dif(s,t))!=NULL)cout<intgcd(intm,intn){intr=m%n;if(r!=0)returngcd(n,r);elsereturn(n);}voidmain(){intm,n;cin>>m>>n;cout<intmax(inta,intb){return(a>b?a:b);}intmax(inta,intb,intc){intt=max(a,b);return(max(t,c));}doublemax(doublea,doubleb){return(a>b?a:b);}doublemax(doublea,doubleb,doublec){doublet=max(a,b);return(max(t,c));}voidmain(){doublex,y,z;inta,b,c;cin>>a>>b>>c;cin>>x>>y>>z;cout<datap->next3、structnode*s->data=chr=sNULL三、编程题1、#include"iostream.h"structstaff{charnum[6];charname[8];floatsalary[3];//分项工资floatgs;//实得工资}s[100];voidmain(){inti,j,n;cin>>n;/*输入职工人数*/for(i=0;i>s[i].num>>s[i].name;for(j=0;j<3;j++)cin>>s[i].salary[j];}cout<<"NO.salary\n";for(i=0;ich=s[i];if(head==NULL){head=insert;head->next=NULL;}else{insert->next=head;head=insert;}i++;}p=head;while(p!=NULL){if(p->ch>='A'&&p->ch<='Z')num++;cout<ch;p=p->next;}cout<p1->ch){p2=p1;p1=p1->next;}if(p1==NULL){insert=newnode;insert->ch=c;insert->count=1;if(head==NULL){insert->next=head;head=insert;}else{insert->next=NULL;p2->next=insert;}}elseif(c==p1->ch)p1->count++;else{insert=newnode;insert->ch=c;insert->count=1;if(p1==head){insert->next=head;head=insert;}else{insert->next=p1;p2->next=insert;}}}p1=head;while(p1!=NULL){cout<ch<<''<count<<'\t';p1=p1->next;}}4、#include"stdio.h"#include"iostream.h"structnode{intcoef;intexpn;structnode*next;};structnode*creat(){structnode*head,*tail,*p;intc,e;head=NULL;cin>>c>>e;while(c!=0)//约定以输入系数为0作为多项式的结束{p=newnode;p->coef=c;p->expn=e;if(head==NULL)head=p;elsetail->next=p;tail=p;cin>>c>>e;}tail->next=NULL;returnhead;}voidprint(structnode*h){structnode*p;p=h;while(p!=NULL){if(p->next!=NULL)cout<coef<<'x'<expn<<'+';else{if(p->coef!=0&&p->expn!=0)cout<coef<<'x'<expn<coef!=0)cout<coef<next;}}voidmain(){structnode*h1,*p1,*h2,*p2,*h3,*p3,*newnode,*t3;h1=creat();print(h1);h2=creat();print(h2);p2=h2;h3=NULL;p1=h1;p2=h2;p3=h3;t3=h3;while(p1!=NULL&&p2!=NULL){newnode=newnode;if(p1->expn>p2->expn){newnode->coef=p1->coef;newnode->expn=p1->expn;p1=p1->next;}elseif(p1->expnexpn){newnode->coef=p2->coef;newnode->expn=p2->expn;p2=p2->next;}else{newnode->coef=p2->coef+p1->coef;newnode->expn=p2->expn;p2=p2->next;p1=p1->next;}if(h3==NULL){h3=newnode;t3=newnode;}elset3->next=newnode;t3=newnode;}if(p1==NULL)t3->next=p2;elset3->next=p1;print(h3);}第七章一、选择题1、D2、B3、B4、A5、B6、A7、D8、B9、C10、B二、程序填空1、fname,“w”(ch=getchar())!=’#’count++2、(c=fgetc(fp))length++length=03、”wb”&emp,sizeof(employer),1,fpfclose(fp)“rb”&emp,sizeof(employer),1,fp三、编程题1、#include"iostream.h"#include"stdlib.h"#include"stdio.h"voidmain(){FILE*fp1,*fp2;charch;fp1=fopen("f1.txt","a");if(fp1==NULL){cout<<"can'topenf1.\n";exit(1);}if((fp2=fopen("f2.txt","r"))==NULL){cout<<"can'topenf2.\n";exit(1);}while(1){ch=fgetc(fp2);if(feof(fp2))break;cout<='a'&&s[i]<='z')a[s[i]-'a']++;i++;}for(i=0;i<26;i++)cout<<(char)('a'+i)<<":"<>stu[i].num>>stu[i].name>>stu[i].s[0]>>stu[i].s[1]>>stu[i].s[2];stu[i].ave=(stu[i].s[0]+stu[i].s[1]+stu[i].s[2])/3;}fwrite(stu,sizeof(student),5,fp);fclose(fp);}第八章一、选择题1、A2、A3、C4、C5、6、D7、B8、D9、C10、B11、D12、A13、B14、D15、D二、阅读程序写结果1、con1calledcon2calledcon3calleda=0,b=0a=10,b=10a=10,b=202、05152535453、4564、10,106,67,95、x=0x=10x=7三、编程题1、#include"iostream.h"#include"string.h"classCat{private:intage;doubleweight;charcolor[10];public:voidset(inta,doublew,charc[10]){age=a;weight=w;strcpy(color,c);}voidprint(){cout<<"age:"<>a>>w>>c;c1.set(a,w,c);c1.print();}2、#include"iostream.h"#include"string.h"#include"stdio.h"classMystring{private:char*str;public:Mystring(){}Mystring(char*s){str=newchar[100];strcpy(str,s);}voidset(char*s){str=newchar[100];strcpy(str,s);}voidprint(){cout<>x1>>y1;p1.set(x1,y1);p1.print();cin>>x1>>y1;p1.move(x1,y1);p1.print();cin>>x1>>y1>>r1;c1.set(x1,y1,r1);c1.print();cout<>name;}virtualdoublewage()=0;voidvirtualprint(){cout<>cnum;}doublewage(){return(3000+40*cnum);}voidprint(){Teacher::print();cout<>cnum;}doublewage(){return(2500+30*cnum);}voidprint(){Teacher::print();cout<>cnum;}doublewage(
本文档为【C++课后习题答案(杨志强_龚沛增)_完整版】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
正方体
暂无简介~
格式:doc
大小:90KB
软件:Word
页数:37
分类:
上传时间:2022-05-11
浏览量:1