设计一个程序,完成一名员工的年薪的计算。员工的信息包括:姓名、性别、工号、月基本工资、年终奖、年薪。从键盘输入信息来初始化员工的姓名、性别、工号、月基本工资和年终奖,计算并输出该员工的年薪。
年薪计算公式为:年薪 = 12×月基本工资 + 年终奖。
提示:定义一个结构类型来存放员工的信息。
设计一个程序,完成一名员工的年薪的计算。员工的信息包括:姓名、性别、工号、月基本工资、年终奖、年薪。从键盘输入信息来初始化员工的姓名、性别、工号、月基本工资和年终奖,计算并输出该员工的年薪。
年薪计算公式为:年薪 = 12×月基本工资 + 年终奖。
提示:定义一个结构类型来存放员工的信息。
【以下回答由 GPT 生成】
#include <iostream>
#include <string>
using namespace std;
struct Employee {
string name;
char gender;
int id;
double monthlySalary;
double annualBonus;
};
double calculateAnnualSalary(Employee emp) {
return 12 * emp.monthlySalary + emp.annualBonus;
}
int main() {
Employee emp;
cout << "Enter employee name: ";
cin >> emp.name;
cout << "Enter employee gender (M/F): ";
cin >> emp.gender;
cout << "Enter employee ID: ";
cin >> emp.id;
cout << "Enter employee's monthly salary: ";
cin >> emp.monthlySalary;
cout << "Enter employee's annual bonus: ";
cin >> emp.annualBonus;
double annualSalary = calculateAnnualSalary(emp);
cout << "The annual salary of " << emp.name << " is: " << annualSalary << endl;
return 0;
}
This program defines a struct Employee
to store employee information, a function calculateAnnualSalary
to calculate the annual salary, and then takes input from the user for employee data and outputs the calculated annual salary.
【相关推荐】