#include<iostream>#include<cmath>#include<iomanip>usingnamespacestd;doublecalculateCharges(doublehours);intmain(){doublehours1,hours2,hours3;cout<<"Inputthehoursofcar:";cin>>hours1>>hours2>>hours3;cout<<fixed<<setprecision(2);cout<<"Car"<<setw(20)<<"Hours"<<setw(20)<<"Charge"<<endl;cout<<"1"<<setw(20)<<hours1<<setw(20)<<calculateCharges(hours1)<<endl;cout<<"2"<<setw(20)<<hours2<<setw(20)<<calculateCharges(hours2)<<endl;cout<<"3"<<setw(20)<<hours3<<setw(20)<<calculateCharges(hours3)<<endl;cout<<"TOTAL"<<setw(16)<<hours1+hours2+hours3<<setw(20)<<calculateCharges(hours1)+calculateCharges(hours2)+calculateCharges(hours3)<<endl;}doublecalculateCharges(doublehours){if((hours>0)&&(hours<=3));elseif((hours>3)&&(hours<=19))+ceil(hours-3)*;elsereturn10;}#include<iostream>#include<cmath>#include<iomanip>usingnamespacestd;doubleroundToInteger(double);doubleroundToTenths(double);doubleroundToHundredths(double);doubleroundToThousandths(double);intmain(){doublex;cout<<"PleaseInputthenumber:";cin>>x;cout<<"roundToInteger:"<<roundToInteger(x)<<endl;cout<<"roundToTenths:"<<roundToTenths(x)<<endl;cout<<"roundToHundredths:"<<roundToHundredths(x)<<endl;cout<<"roundToThousandths:"<<roundToThousandths(x)<<endl;}doubleroundToInteger(doublenumber){returnfloor(number+.5);}doubleroundToTenths(doublenumber){returnfloor(number*10+.5)/10;}doubleroundToHundredths(doublenumber){returnfloor(number*100+.5)/100;}doubleroundToThousandths(doublenumber){returnfloor(number*1000+.5)/1000;}#include<iostream>#include<iomanip>#include<ctime>#include<cstdlib>usingnamespacestd;intmain(){srand(time(0));intx;x=1+rand()%1;cout<<"x="<<x<<endl;x=1+rand()%100;cout<<"x="<<x<<endl;x=0+rand()%9;cout<<"x="<<x<<endl;x=1000+rand()%112;cout<<"x="<<x<<endl;x=-1+rand()%2;cout<<"x="<<x<<endl;x=-3+rand()%15;cout<<"x="<<x<<endl;}#include<iostream>#include<iomanip>#include<ctime>#include<cstdlib>usingnamespacestd;intmain(){intarray1[]={2,4,6,8,10};intarray2[]={3,5,7,9,11};intarray3
C++大学教程习题解答(第七版) 来自淘豆网www.taodocs.com转载请标明出处.