试题一第一题题目:定义盒子Box类,要求具有以下成员:可设置盒子形状;可计算盒子体积;可计算盒子的表面积输出结果见图:样张.JPG-------------------------------------------------------*/#includeiostream#includecmathusingnamespacestd;/**********Program**********/classBox{doublex,y,z,s,v;public:Box(doublea=0,doubleb=0,doublec=0);~Box(){};voidinit(doublea,doubleb,doublec);voidshow();doublevolue();doublearea();};Box::Box(doublea,doubleb,doublec){x=a;y=b;z=c;}voidBox::init(doublea,doubleb,doublec){x=a;y=b;z=c;}doubleBox::volue(){v=x*y*z;returnv;}doubleBox::area(){s=2*(x*y+y*z+z*x);returns;}/**********End**********/voidBox::show(){coutx=xy=yz=zendl;couts=sv=vendl;}voidmain(){Boxa;a.init(2,3,4);a.volue();a.area();a.show();}第二题/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:有一个Time类,包含数据成员hour(小时)、minute(分)和sec(秒),定义三个获取数据成员的成员函数和一个模拟秒表的函数成员go(每调用一次go走一秒),格式:voidgo(void)doublegetHour(void){returnhour;}doublegetMinute(void){returnminute;}doublegetSec(void){returnsec;}输出结果见图:样张.JPG-------------------------------------------------------*/#includeiostreamusingnamespacestd;/**********Program**********/classClock{doublehour,minute,sec;public:Clock(intH,intM,intS){hour=H;minute=M;sec=S;}voidgo();intgetHour(void){returnhour;}intgetMinute(void){returnminute;}intgetSec(void){returnsec;}};voidClock::go(){sec++;if(sec=60){minute++;sec=0;}if(minute=60){hour++;minute=0;}}/**********End**********/voiddisplay(Clockck){coutck.getHour()点ck.getMinute()分ck.getSec()秒;}voidmain(void){inti;intINTERVAL;//耗时,单位为秒INTERVAL=rand();INTERVAL=rand();Clockclock(9,55,0);cout起点=;display(clock);coutendl;for(i=1;i=INTERVAL;i++)clock.go();cout终点=;display(clock);coutendl;cout耗时INTERVAL秒endl;}第三题/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:声明复数类complex,并使用成员函数add实现复数加法,并输出结果,注意虚部为负数和0时的输出。输出结果见图:样张.JPG-------------------------------------------------------*/#includeiostreamusingnamespacestd;/**********Program**********/classComplex{doubleR,I;public:Complex(doubleX=0,doubleY=0){R=X;I=Y;}Complexadd(Complexp);voidshow();};ComplexComplex::add(Complexp){ComplexQ;Q.R=R+p.R;Q.I=I+p.I;R=p.R;I=Q.I;returnQ;}/**********End**********/voidComplex::show(){if(I0)coutR+Iiendl;elseif(I==0)coutRendl;elsecoutR--Iiendl;}voidmain(){Complexa(3,4),b(5,6),c;c=a.add(b);//c=a+bc.show();}第四题/*-------------------------------------------------------【程序设计】---------------------------------------------------------题目:请补足date类和card的成员函数定义。输出结果见图:样张.JPG-------------------------------------------------------*/#includeiostream#includeiomanipusingnamespacestd;classdate{intyear;intmonth;intday;public:date(intYear=0,intMonth=0,intDay=0);//构造函数,给出初始的年月日voidsetdate(intYear,intMonth,intDay);//设置年月日intget_year();//获取年份intget_month();//获取月份intget_day();//获取日期};classcard{intbook;//图书编号intreader;//借阅者编号dateborrow_day;//出借日期intexpiry;//借阅期限public:card(intBook,intReader,dateBorrow_day,intExpiry=60);//构造函数dateget_borrow_day();//获取出借日期dateget_return_day();//获取归还日期,归还日期=出借日期+借阅期限intget_book();//获取图书编号intget_reader();//获取借阅者编号intget_expiry();//获取借阅期限};/**********Program**********/date::date(intYear,intMonth,intDay){year=Year;month=Month;day=Day;}voiddate::setdate(intYear,intMonth,intDay){year=Year;month=Month;day=Day;}intdate::get_year(){returnyear;}intdate::get_month(){returnmonth;}intdate::get_day(){returnday;}card::card(intBook,intReader,dateBorrow_day,intExpiry):borrow_day(Borrow_day){book=Book;reader=Reader;expiry=Expiry;}datecard::get_borrow_day(){returnborrow_day;}datecard::get_return_day(){datereturn_day;intm,n,q;inti;m=borrow_day.get_day();n=borrow_day.get_month();q=borrow_day.get_year();for(i=1;i=expiry;i++){m++;if((q%4==0&&q%400!=0)||q%400==0){if((n==1||n==3||n==5||n==7||n==8||n==10||n==12)&&m31){n++;m=1;}elseif((n==4||n==6||n==9||n==11)&&m30){n++;m=1;}elseif(n==2&&m29){n++;m=1;}}else{if((n==1||n==3||n==5||n==7||n==8||n==10||n==12)&&m31){n++;m=1;}elseif((n==4||n==6||n==9||n==11)&&m30){n++;m=1;}elseif(n==2&&m28){n++;m=1;}}if(n12){q++;n=1;}}return_day.setdate(q,n,m);returnreturn_day;}intcard::get_book(){returnbook;}intcard::get_reader(){returnreader;}intcard::get_expiry(){returnexpiry;}/**********End**********/voidmain(){intstu=2012678;//借阅者编号intcbook=100034;//图书编号dateday(2012,1,31);//出借日期cardc1(cbook,stu,day);//创建card对象c1//以下打印借书卡c1信息cout借书卡c1:endl;cout-----------------------------------------------------endl;coutsetw(10)'*'图书号:c1.get_book()endl;coutsetw(10)'*'借书人:c1.get_reader()endl;coutsetw(10)'*'借阅期限:c1.get_expiry()endl;coutsetw(10)'*'出借日期:c1.get_borrow_day().get_year():c1.get_borrow_day().get_month():c1.get_borrow_day().get_day()endl;coutsetw(10)'*'归还日期:c1.get_return_day().get_year():c1.get_return_day().get_month():c1.get_return_day().get_day()endl;cout-----------------------------------------------------endl;day.setdate(2012,12,