我是靠谱客的博主 幸福含羞草,这篇文章主要介绍设有6个职工,每个职工包括职工号和工资。从键盘输入职工的数据,求平均工资,并输出最高工资和对应的职工号,现在分享给大家,希望可以做个参考。

设有6个职工,每个职工包括职工号和工资。从键盘输入职工的数据,求平均工资,并输出最高工资和对应的职工号

#include<iostream>
using namespace std;
const int size = 6;
struct employee
{
	long int id;
	double salary;
}; struct employee info[6];
void input(employee* info, int size);
double find_max(employee* info, int size);
double average_salary(employee* info, int size);
int main()
{
	cout << "please input the employee's information:" << endl;
	input(info, 6);
	cout << "平均工资为:" << average_salary(info, 6) << endl;
	cout << "最高工资为:" << find_max(info, 6) << endl;
	return 0;
}
void input(employee* info, int size)
{
	int i;
	for (i = 0; i < size; i++)
	{
		cin >> info[i].id >> info[i].salary;
	}
}
double find_max(employee* info, int size)
{
	int i,id;
	double max = 0;
	for (i = 0; i < size; i++)
	{
		if (info[i].salary > max)

		{
			max = info[i].salary;
			id = info[i].id;
		}
	}
	cout << "最高工资的职工的职工号为:" <<id << endl;
	return max;
}
double average_salary(employee* info, int size)
{
	int i;
	double sum=0, avg;
	for (i = 0; i < size; i++)
	{
		sum += info[i].salary;
	}
	avg = sum / size;
	return avg;
}

最后

以上就是幸福含羞草最近收集整理的关于设有6个职工,每个职工包括职工号和工资。从键盘输入职工的数据,求平均工资,并输出最高工资和对应的职工号的全部内容,更多相关设有6个职工,每个职工包括职工号和工资。从键盘输入职工内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(59)

评论列表共有 0 条评论

立即
投稿
返回
顶部