level 10
员工多少人也没讲,我设了常量在里面,到时候你可以做微调。
具体计算工资,你也可以单独拎出来做一个子函数,这些都不是重点,关键是报酬范围的设置,这里比较依赖具体值。
我理解的是,你老师应该是不允许使用switch-case这个写法,改成定义一个array存储各自情况的值。
2022年11月24日 22点11分
3
level 10
talk is cheap, show you code
#include<iostream>#
include // 随机数
#include<iomanip>#
include // 顺序容器 静态数组
using std::cout;using
std::endl;using
std::array;
const int N = 20; // 假定员工规模
// 给每个员工假定销售额, 随机在(a, b)区间
void InitArr(array &arr, int a, int b){
std::random_device rd;
std::mt19937 engine(rd());
std::uniform_int_distribution di(a, b);
for (array::iterator i = arr.begin(); i != arr.end(); i++)
*i = di(engine);
}
int main(){
array staff; // 所有员工的销售额
array status{0}; // 报酬范围的9种情形
InitArr(staff, 0, 9999);
cout << "Sales: ";
for (auto e : staff) cout << std::setw(5) << e;
cout << endl;
cout << "Wages: ";
for (int i = 0; i < staff.size(); i++) {
int wage = staff.at(i) * 9 / 100 + 200; // 实际工资 = 9%提成+200底薪
cout << std::setw(5) << wage;
status[wage/100-2]++;
}
for (int i = 2; i < 10 ; i++)
cout << endl << i << "00~" << i << "99 美元: "<< status.at(i-2);
cout << endl << "1000 美元及以上: " << status[8] << '\n';
return 0;
}
2022年11月24日 22点11分
4