欢迎来到天天文库
浏览记录
ID:47203194
大小:69.69 KB
页数:16页
时间:2019-08-25
《中国石油大学(华东)c上机作业》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C++上机作业第二章2.25#includeusingnamespacestd;intmain(){inta,b;int&m=a,&n二b;cin>>a»b;if(m>n)cout«nTheresultistvnvv”H«m«endl;elseif(n>m)cout«HTheresultis,,«m«"vendl;elsecout«nTheresultis"vvnvv”H«m«endl;return0;}2.22#includeusingnamespacestd;intmain(){int*a=newint[
2、21];int*b=newint(3);a[l]=a[2]=l;cout«a[l]«'t'«a⑵v<、t‘;while(*b<=20){a[*b]=a[*b-l]+a[*b-2];cout«a[*b]«'f;if(*b%5==0)cout«endl;*b=*b+l;}delete[]a;deleteb;return0;}2.23#inelude#ineludeusingnamespacestd;doublesroot(inta){return(double)sqrt((float)a);}doublesroot
3、(longintb){return(double)sqrt((longdouble)b);}doublesroot(doublec){return(double)sqrt(c);}intmain(){inta;longintb;doublec;cin>>a»b»c;cout«sroot(a)«nH«sroot(b)«nH«sroot(c)«endl;return0;}2.24#includeusingnamespacestd;intmain(){inti,j,l,sum=0;for(i=0;i<101;i++)for(j=0;j
4、<51;j++)for(l=0;l<21;l++){if(i+2*j+5*l==100)sum++;}cout«HSumisH«sum«endl;return0;}2.26#ineludeusingnamespacestd;inlineintf(intx);intmain(){inta,b,c;cin>>a»b;if(f(a)==O)cout«"Rootis:"«a«endl;elseif(f(b)==O)cout«"Rootis:"«b«endl;else{c=(a+b)/2;while(f(c)!=0){if(f(c)*f(
5、a)<0)b=c;else{a=c;}c=(a+b)/2;}cout«"Rootis:"«c«endl;}return0;}inlineintf(intx){inth;h=2*x*x*x-4*x*x+3*x-6;returnh;}3.30#includeusingnamespacestd;classcounter{public:counter(intnumber);//构造函数voidincrementf);〃给原值加1voiddecrement();///给原值减1intgetvaluef);〃取得计数器值intprint()
6、;〃显示计数private:intvalue;};counter::counter(intnumber){value=number;}voidcounter::increment(){value=value+l;}voidcounter::decrement(){value=value-l;}intcounter::getvalue(){returnvalue;}intcounter::print(){returnvalue;}intmain(){inta,i;cin>>a;counterA(a);for(i=2;i<=A.getvalue()+l
7、;i++){cout«HvalueisH«i«endl;}for(i=A.print()-l;i>=0;i-){cout«nvalueistvivvendl;}return0;}3.31#includeusingnamespacestd;classDate{public:voidprintDate();〃显示口期voidsetDayfintd);〃设置日期值voidsetMonth(intm);〃设置月的值voidsetYear(inty);〃设置年的值private:intday,month,year;};voidDate::
8、setDay(intd){day=d;}voidDate::setMonth(intm){month=m;}voidDat
此文档下载收益归作者所有