cpp02.cpp

来自「C++参考书」· C++ 代码 · 共 60 行

CPP
60
字号

// Coded by plusir -- Dec.29.2002.
// Standard C++ Bible -- (P232-8-2)

#include <iostream>
#include <iomanip>
using namespace std ;

const float overtime = 1.5f ;
const float taxrate = 0.15f ;
const int wkweek = 40 ;

inline int reg( int h ) { return h < wkweek ? h : wkweek ; }
inline int otime( int h ) { return h < wkweek ? 0 : h - wkweek ; }
inline float otimepay( int h, float r ) { return r * otime( h ) * overtime ; }
inline float regpay( int h, float r ) { return r * reg( h ) ; }
inline float grosspay( int h, float r ) { return otimepay( h, r ) + regpay( h, r ) ; }
inline float wholding( int h, float r ) { return grosspay( h, r ) * taxrate ; }
inline float netpay( int h, float r ) { return grosspay( h, r ) - wholding( h, r ) ; }

void setformat( void ) ;

int main()
{
	cout << "Enter hours( xx ) rate( x.xx ): " ;
	int hours ;
	float rate ;
	cin >> hours >> rate ;

	cout << "Ragular: " ;
	setformat() ;
	cout << regpay( hours, rate ) << endl ;

	cout << "Overtime: " ;
	setformat() ;
	cout << otimepay( hours, rate ) << endl ;

	cout << "Gross: " ;
	setformat() ;
	cout << grosspay( hours, rate ) << endl ;

	cout << "Witholding: " ;
	setformat() ;
	cout << wholding( hours, rate ) << endl ;

	cout << "Net Pay: " ;
	setformat() ;
	cout << netpay( hours, rate ) << endl ;

	return 0 ;
}

void setformat( void )
{
	cout
		<< setw( 10 )
		<< setiosflags( ios::fixed | ios::right )
		<< setprecision( 2 ) ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?