第六章函数和递归入门
#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转载请标明出处.