C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案.docx
《C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案.docx》由会员分享,可在线阅读,更多相关《C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案.docx(9页珍藏版)》请在冰豆网上搜索。
![C程序设计教程 第一版 龚沛曾 杨志强 著 高等教育出版社 课后答案.docx](https://file1.bdocx.com/fileroot1/2023-1/10/4efd5dbc-4316-4527-af5f-1e39df1c0227/4efd5dbc-4316-4527-af5f-1e39df1c02271.gif)
C程序设计教程第一版龚沛曾杨志强著高等教育出版社课后答案
C程序设计教程第一版(龚沛曾杨志强著)高等教育出版社课后答案
一、选择题
1-4CACC5AC
6-10DBDCB11-15AABDD
二、阅读程序,写出运行结果
1、
conlcalled.
con2called.mcon3called.
a=0,b=0
a=10,b=10oa=10,b=20
2、c
05
15网
25.
35案
45w
3、答
4后
5a
6课
4、d
10,10
6,6h
7,9
5、k
x=0
x=10
x=7.
三、编程题w
1、#include
classCat
{
private:
intage;
doubleweight;
charcolor;
public:
voidset(inta,doublew,charc)
{age=a;weight=w;color=c;}
intgetage()
{returnage;}
doublegetweight()
{returnweight;}
chargetcolor()
{returncolor;}
voidprint()
{cout<<"age="<voidmain()o{Cata,b;
a.set(4,7.8,'r');c
b.set(1,2.0,'y');
cout<<"age="<cout<<"weight="<cout<<"color="<b.print();案
}答w
后a
2、#include"iostream.h"课
#lianscsludeys"tsrtdigo.h"d
{
chars[200];h
public:
voidini()>>s;}k
voidout()
{puts(s);}.
intlen()
{
char*p=s;
while(*p!
='\0')
wp++;
return(p-s);
}
friendMystringstrcat(Mystrings1,Mystrings2);
};
Mystringstrcat(Mystrings1,Mystrings2)
{
char*p=s1.s,*q=s2.s;
while(*p!
='\0')
p++;
while(*q!
='\0')
{
*p=*q;
p++;
q++;
}m
*p='\0';
returns1;
}ovoidmain()c
{
Mystringp1,p2,p3;
p1.in();p2.in();网
p1.out();p2.out();.
cout<<"p1长度为"<cout<<"p2长度为"<p3=strcat(p1,p2);
p3.out();后
cout<<"连接以后的长度为"<}课
d
3、#include"iostream.h"
classPointh
{
privateo:
ublex,y;k
public:
Point(doublea,doubleb)
{x=a;y=b;}
doublegetx()
{returnx;}
doublegety()
{wreturny;}
voidmove(doublei,doublej)
{x+=i;y+=j;}
};
classCircle:
privatePoint
{
private:
doubler;
public:
Circle(doublea,doubleb,doublet):
Point(a,b)
{r=t;}
doublegetr()
{returnr;}
doublef1()
{return(Point:
:
getx());}
doublef2()m
{return(Point:
:
gety());}
doublearea()
{return3.14159*r*r;}o};c
voidmain()
{PointA(2,2);
CircleB(2,3,1);网
cout<<"PointAis("<A.move(3,2);案
cout<<"PointAis("<cout<<"圆心:
("<cout<<"Theareais"<}a
课d
4、#include"iostream.h"h
classpoint
{private:
X,Y;k
public:
point(intx=0,inty=0)
{X=x;Y=y;}
voidprint()
{wcout<<"点的坐标:
("<friendpointoperator+(point&a,point&b);
};
pointoperator+(point&a,point&b)
{
returnpoint(a.X+b.X,a.Y+b.Y);
}
voidmain()
{
pointp1(3,4),p2(6,8),p3;
p1.print();
p2.print();
p3=p1+p2;
p3.print();
}m5、#include"iostream.h"oclassteacher
{private:
c
inthour;
public:
teacher(inth=0)网
{hour=h;}.
intgeth()案w
{returnhour;}答
后a
voidprint()课
{cout<<"课时数是:
"<virtualintwages()
{h
return(0);
};}k
classprofessor:
publicteacher
{public:
professor(inth):
teacher(h)
{}w
voidprint()
{w
cout<<"基本工资是:
"<<3000<<"元"<cout<<"课时津贴为:
"<<40<<"元/小时"<wteacher:
:
print();
}
virtualintwages()
{intw=geth();
return(3000+40*w);
}
};
classassociateprofessor:
publicteacher
{public:
associateprofessor(inth):
teacher(h)
{}
voidprint()
{m
cout<<"基本工资是:
"<<2500<<"元"<cout<<"课时津贴为:
"<<25<<"元/小时"<teacher:
:
print();o
}
virtualintwages()c
{intw=geth();
return(3000+40*w);
}网
};.
classlecturer:
publicteacher案
{public:
答w
lecturer(inth):
teacher(h)
{}后
voidprint()a
{课
cout<<"基本工资是:
"<<2000<<"元"<cout<<"课时津贴为:
"<<25<<"元/小时"<teacher:
:
print();h
}
virtuailint=wgaegtes(()k
return(3000+40*w);
}.
};
voidmain()w
{
teacher*p;
professora(40);
associateprofessorb(50);
lecturerc(60);
p=&a;
p->print();
cout<<"该教授的工资是:
"<wages()<p=&b;
p->print();
cout<<"该副教授的工资是:
"<wages()<p=&c;
p->print();
cout<<"该讲师的工资是:
"<wages()<
}m
co
网.
案w
答
后a
课d
kh
w.
ww