下载此文档

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


文档分类:IT计算机 | 页数:约36页 举报非法文档有奖
1/36
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/36 下载此文档
文档列表 文档介绍
第六章函数和递归入门

#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>

C 大学教程习题解答(第七版) 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数36
  • 收藏数0 收藏
  • 顶次数0
  • 上传人mh900965
  • 文件大小51 KB
  • 时间2017-12-22