c编程题试题题库Word文档下载推荐.docx

上传人:b****1 文档编号:3881101 上传时间:2023-05-02 格式:DOCX 页数:22 大小:18.15KB
下载 相关 举报
c编程题试题题库Word文档下载推荐.docx_第1页
第1页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第2页
第2页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第3页
第3页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第4页
第4页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第5页
第5页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第6页
第6页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第7页
第7页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第8页
第8页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第9页
第9页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第10页
第10页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第11页
第11页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第12页
第12页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第13页
第13页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第14页
第14页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第15页
第15页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第16页
第16页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第17页
第17页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第18页
第18页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第19页
第19页 / 共22页
c编程题试题题库Word文档下载推荐.docx_第20页
第20页 / 共22页
亲,该文档总共22页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

c编程题试题题库Word文档下载推荐.docx

《c编程题试题题库Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《c编程题试题题库Word文档下载推荐.docx(22页珍藏版)》请在冰点文库上搜索。

c编程题试题题库Word文档下载推荐.docx

endl;

}

private:

inthour;

intminute;

intsec;

};

 

intmain()

{

Timet1;

t1.set_time();

t1.show_time();

return0;

1.2

编写一个基于对象的程序,求长方体的体积,要求:

(1)定义一个长方体类Box,类内有私有数据成员lengh(长)、width(宽)、height(高),公有成员函数get_value()、volume()。

(2)get_value()函数和volume()函数在类外定义。

get_value()作用是从键盘输入长、宽、高的值,volume()的作用是计算长方体的体积并在屏幕上显示。

(3)在main()函数定义Box类的对象box1,并调用get_value()函数给长、宽、高赋值,调用volume()函数输出长方体体积。

classBox

{public:

voidget_value();

voidvolume();

floatlengh;

floatwidth;

floatheight;

voidBox:

get_value()

{cout<

pleaseinputlengh,width,height:

;

lengh;

width;

height;

volume()

volmueofbox1is"

lengh*width*height<

{Boxbox1;

box1.get_value();

box1.volume();

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()函数求出并显示数组元素的最大值。

classArray_max

voidset_value();

voidmax_value();

intarray[10];

intmax;

};

voidArray_max:

set_value()

{inti;

for(i=0;

i<

10;

i++)

array[i];

max_value()

{inti;

max=array[0];

for(i=1;

if(array[i]>

max)max=array[i];

cout<

max="

max;

{Array_maxarrmax;

arrmax.set_value();

arrmax.max_value();

1.4

编写一个程序,用成员函数重载运算符“+”,使之能用于两个复数相加。

classComplex

Complex(){real=0;

imag=0;

Complex(doubler,doublei){real=r;

imag=i;

Complexoperator+(Complex&

c2);

voiddisplay();

doublereal;

doubleimag;

ComplexComplex:

operator+(Complex&

c2)

{Complexc;

c.real=real+c2.real;

c.imag=imag+c2.imag;

returnc;

voidComplex:

display()

{cout<

("

real<

"

imag<

i)"

{Complexc1(3,4),c2(5,-10),c3;

c3=c1+c2;

c1="

c1.display();

c2="

c2.display();

c1+c2="

c3.display();

1.5

编写一个程序,用友元函数重载运算符“+”,使之能用于两个复数相加。

iostream.h>

Complex(doubler){real=r;

friendComplexoperator+(Complex&

c1,Complex&

Complexoperator+(Complex&

{returnComplex(c1.real+c2.real,c1.imag+c2.imag);

c1.display();

c2.display();

c3.display();

1.6

编写一个基于对象的程序,求圆球的体积,要求:

(1)定义一个圆球类Circle,类内有私有数据成员radius(半径),公有成员函数get_value()、volume()。

get_value()作用是从键盘输入半径的值,volume()的作用是计算圆球的体积并在屏幕上显示。

(圆球体积计算公式为:

v=4/3πr3)

(3)在main()函数定义Circle类的对象circle1,并调用get_value()函数给球半径赋值,调用volume()函数输出圆球的体积。

classCircle

floatradius;

voidCircle:

pleaseinputradius:

radius;

volmueofcircle1is"

4.0/3*3.14159*radius*radius*radius<

{Circlecircle1;

circle1.get_value();

circle1.volume();

1.7

(1)定义一个日期类Date,类内有私有数据成员year(年)、month(月)、day(日),公有成员函数set_date()、show_date()。

(2)set_date()函数和show_date()函数在类外定义。

set_date()作用是从键盘输入年、月、日的值,show_date()的作用是在屏幕上显示年、月、日的值。

(3)在main()函数定义Date类的对象d1,并调用set_date()函数给日期赋值,调用show_date()函数输出日期的值。

classDate

voidset_date();

voidshow_date();

intyear;

intmonth;

intday;

voidDate:

set_date()

year;

month;

day;

show_date()

year<

-"

month<

day<

Dated1;

d1.set_date();

d1.show_date();

2.1

编写一个面向对象的程序,要求:

(1)定义一个基类Student,类内有私有数据成员num(学号)、name(姓名)、sex(性别),公有成员函数get_value()、display(),get_value()作用是从键盘给num、name、sex赋值,display()的作用是显示num、name、sex的值。

(2)定义一个派生类Student1,Student1公有继承自Student类。

Student1类新增私有数据成员age(年龄)、addr(地址),新增公有成员函数get_value_1()、display_1()。

get_value_1()的作用是实现从键盘给num、name、sex、age、addr赋值,display_1()的作用是显示num、name、sex、age、addr的值。

(3)在main()函数定义Student1类的对象stud1,并调用get_value_1()函数给对象赋值,调用display_1()函数显示学生的所有信息。

classStudent

voidget_value()

num>

name>

sex;

voiddisplay()

num:

"

num<

name:

name<

sex:

sex<

private:

intnum;

charname[10];

charsex;

classStudent1:

publicStudent

voidget_value_1()

{get_value();

age>

addr;

voiddisplay_1()

{display();

age:

age<

address:

addr<

}

intage;

charaddr[30];

{Student1stud1;

stud1.get_value_1();

stud1.display_1();

2.2

(2)定义一个派生类Student1,Student1私有继承自Student类。

privateStudent

{display();

2.3

编写一个面向对象的程序,要求:

(2)定义一个派生类Student1,Student1保护继承自Student类。

protectedStudent

2.4

(1)定义一个基类Student,类内有保护数据成员num(学号)、name(姓名)、sex(性别),公有成员包括构造函数、show()函数。

构造函数带3个参数用于定义对象时赋初值,show()函数作用是显示学生信息,即num、name、sex的值。

Student1类新增私有数据成员age(年龄)、addr(地址),新增公有成员包括构造函数、show()函数。

构造函数带5个参数用于定义对象时赋初值,show()函数作用是显示学生信息,即num、name、sex、age、addr的值。

(3)在main()函数定义Student1类的对象stud1并赋初值,调用show()函数显示该学生的所有信息。

#include<

string>

classStudent

Student(intn,stringnam,chars)

{num=n;

name=nam;

sex=s;

voidshow()

{cout<

protected:

stringname;

charsex;

publicStudent

Student1(intn,stringnam,chars,inta,charad[]):

Student(n,nam,s)

{age=a;

addr=ad;

{Student:

show();

endl<

stringaddr;

intmain()

{Student1stud1(10010,"

Wang-li"

'

f'

19,"

115BeijingRoad,Shanghai"

);

stud1.show();

2.5

(1)定义一个基类Student,类内有保护数据成员num(学号)、name(姓名),公有成员包括构造函数、show()函数。

构造函数带2个参数用于定义对象时赋初值,show()函数作用是显示学生信息,即num、name的值。

Student1类新增私有数据成员age(年龄)、addr(地址)以及子对象monitor(班长,Student类型),新增公有成员包括构造函数、show()函数。

构造函数带6个参数用于定义对象时赋初值,show()函数作用是显示学生的所有信息,即本人的num、name、age、addr以及班长的num、name。

Student(intn,stringnam)

Student1(intn,stringnam,intn1,stringnam1,inta,stringad)

:

Student(n,nam),monitor(n1,nam1)

Thisstudentis:

Student:

Classmonitoris:

monitor.show();

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2