好文档 - 专业文书写作范文服务资料分享网站

c++编程题试题库完整

天下 分享 时间: 加入收藏 我要投稿 点赞

- - .. --

1.1

编写一个基于对象的程序,要求: (1)定义一个时间类Time,类内有私有数据成员hour(小时)、minute(分钟)、sec(秒),公有成员函数set_time()、show_time()。

(2)set_time()函数和show_time()函数在类内定义。set_time()作用是从键盘输入时间、分钟、秒的值,show_time()的作用是在屏幕上显示时间、分钟、秒的值。 (3)在main()函数定义Time类的对象t1,并调用set_time()函数给时间赋值,调用show_time()函数输出时间的值。 #include using namespace std; class Time {public:

void set_time() {cin>>hour; cin>>minute; cin>>sec; }

void show_time()

{cout<

private: int hour; int minute; int sec; };

int main() {

word 可编辑.

- - .. --

Time t1;

t1.set_time(); t1.show_time(); return 0; } 1.2

编写一个基于对象的程序,求长方体的体积,要求: (1)定义一个长方体类Box,类内有私有数据成员lengh(长)、width(宽)、height(高),公有成员函数get_value()、volume()。

(2)get_value()函数和volume()函数在类外定义。get_value()作用是从键盘输入长、宽、高的值,volume()的作用是计算长方体的体积并在屏幕上显示。 (3)在main()函数定义Box类的对象box1,并调用get_value()函数给长、宽、高赋值,调用volume()函数输出长方体体积。 #include using namespace std; class Box {public:

void get_value(); void volume(); private:

float lengh; float width; float height; };

void Box::get_value()

{ cout<<\ cin>>lengh;

word 可编辑.

- - .. --

cin>>width; cin>>height; }

void Box::volume() { cout<<\of box1 is \

int main() {Box box1;

box1.get_value(); box1.volume(); return 0; }

1.3.

编写一个基于对象的程序,求一个有十个数据的整型数组中元素的最大值,要求: (1)定义一个类Array_max,类内有私有数据成员array[10]、max分别存储十个整数、最大值,公有成员函数set_value()、max_volume()。

(2)set_value()函数和max_volume()函数在类外定义。get_value()作用是从键盘输入数组十个元素的值,max_volume()的作用是求出并显示数组元素的最大值。

(3)在main()函数定义Array_max类的对象arrmax,并调用set_value()函数给数组赋值,调用max_volume()函数求出并显示数组元素的最大值。 #include using namespace std; class Array_max {public:

void set_value();

word 可编辑.

c++编程题试题库完整

--..--1.1编写一个基于对象的程序,要求:(1)定义一个时间类Time,类内有私有数据成员hour(小时)、minute(分钟)、sec(秒),公有成员函
推荐度:
点击下载文档文档为doc格式
33pt57ae7t1xu1x81dzc4m0xd0pwbf00nnx
领取福利

微信扫码领取福利

微信扫码分享