- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
C++面向对象程序设计上机考试题库
一、第一类题目( 20 道,每题 7 分,在 word 中保留代码并将输出结果窗口保留)
1.定义盒子 Box 类,要求具有以下成员:长、宽、高分别为 x,y,z ,可设置盒子形状;可计算盒子体积;可计算盒子的表面积。
#includeiostream
class Box
{ private:
int x,y,z; int v,s;
public:
void int(int x1=0,int y1=0,int z1=0) {x=x1;y=y1;z=z1;} void volue() {v=x*y*z;}
void area() {s=2*(x*y+x*z+y*z);}
void show()
{coutx= x y= y z=zendl;
couts= s v= vendl;
}
};
void main()
{ Box a; (2,3,4); ();
();
();
}
2.有两个长方柱,其长、宽、高分别为:( 1)30,20,10;( 2)12,10, 20。分别求他们的体积。编一个基于对象的程序,在类中用带参数的构造函数。
#include iostream
using namespace std;
class Box
{public:
Box(int,int,int);Box box1Box box2Box box1Box box2endl; cout() is the Minimum of two inteder numbers.endlendl; Comparefloat cmp2,;
cout() is the Maximum of two float numbers.endl; cout() is the Minimum of two float numbers.endlendl; Comparechar cmp3(a,A);
cout() is the Maximum of two characters.endl; cout() is the Minimum of two characters.endl; return 0;
}
3.建立一个对象数组,内放 5 个学生的数据(学号、成绩),用指针指向数组首元素,输出第 1,3,5 个学生的数据。初值自拟。
#include iostream
using namespace std;
class Student
{public:
Student(int n,double s):num(n),score(s){}
void display();
private:
int num;
double score;
};
void Student::display()
{coutnum scoreendl;}
int main()
{Student stud[5]={
Student(101,,Student(102,,Student(103,,
Student(104,,Student(105,};
Student *p=stud;
for(int i=0;i=2;p=p+2,i++)
p-display();
return 0;
}
4.建立一个对象数组,内放 5 个学生的数据(学号、成绩),设立一个函数 max,用指向对象的指针作函数参数, 在 max函数中找出 5 个学生中成绩最高者, 并输出其学号。 初值自拟。
#include iostream
using namespace std;
class Student
{public:
Student(int n,float s):num(n),score(s){}
int num;
float score;
};
void main()
{Student stud[5]={
Student(101,,Student(102,,Student(103,,
Student(104,,Student(105,};
void max(Student* );
Student *p=stud[0];
max(p);
}
void max(Student *arr)
{float max_score=arr[0].score;
int k=0;
for(int i=1;i5;i++)
if(arr[i].scoremax_score) {max_score=arr[i].score;k=i;} coutarr[k].num max_scoreendl;
}
5.用 new建立一个动态一维数组,并初始化 int[10]={1,2,3,4,5,6,7,8,9,10}, 用指针
输出,最后销毁数组所占空间。
#includeiostream
#includestring
using namesp
文档评论(0)