📄 pr08002.cpp
字号:
////////////////////////////////////////
// File Name: pr08002.cpp
////////////////////////////////////////
#include <iostream>
#include <iomanip>
// Define constants.
const float overtime = 1.5;
const float taxrate = 0.15;
const int wkweek = 40;
// Define inline functions.
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);
}
// Function prototype.
void setformat();
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
std::cout << "Enter hours (xx) rate (x.xx): ";
int hours;
float rate;
std::cin >> hours >> rate;
std::cout << "Regular: ";
setformat();
std::cout << regpay(hours, rate) << std::endl;
std::cout << "Overtime: ";
setformat();
std::cout << otimepay(hours, rate) << std::endl;
std::cout << "Gross: ";
setformat();
std::cout << grosspay(hours, rate) << std::endl;
std::cout << "Withholding: ";
setformat();
std::cout << wholding(hours, rate) << std::endl;
std::cout << "Net Pay: ";
setformat();
std::cout << netpay(hours, rate) << std::endl;
return 0;
}
void setformat()
{
std::cout << std::setw(10)
<< std::setiosflags(std::ios::fixed)
<< std::setiosflags(std::ios::right)
<< std::setprecision(2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -