1 / 36
文档名称:

C 大学教程习题解答(第七版).docx

格式:docx   大小:51KB   页数:36页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

C 大学教程习题解答(第七版).docx

上传人:mh900965 2017/12/22 文件大小:51 KB

下载得到文件列表

C 大学教程习题解答(第七版).docx

文档介绍

文档介绍:第六章函数和递归入门

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double calculateCharges( double hours );
int main( )
{
double hours1, hours2, hours3;
cout << "Input the hours of car :";
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;

}
double calculateCharges( double hours )
{
if( ( hours >0 ) && ( hours <= 3 ) )
return ;
else
if( ( hours>3 )&& ( hours <= 19 ) )
return +ceil( hours - 3 )*;
else
return 10;
}

#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
double roundToInteger( double );
double roundToTenths( double );
double roundToHundredths( double );
double roundToThousandths( double );
int main( )
{
double x;
cout << " Please Input the number: ";
cin >> x;
cout << "roundToInteger :" << roundToInteger( x ) <<endl;
cout << "roundToTenths :" << roundToTenths( x ) <<endl;
cout << "roundToHundredths :" << roundToHundredths( x ) <<endl;
cout << "roundToThousandths :" << roundToThousandths( x ) <<endl;
}
double roundToInteger( double number )
{
return floor( number + .5 ) ;
}
double roundToTenths( double number )
{
return floor( number*10 + .5 ) / 10;
}
double roundToHundredths( double number )
{
return floor( number*100 + .5 ) / 100;
}
double roundToThousandths( double number )
{
return floor( number*1000 + .5 ) / 1000;
}

#include<iostream>
#include<iomanip>
#include<ctime>