有份C语言的题目谁能帮忙下

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:39:10
统计工资
1 设计题目
本课程设计要求设计一个公司职员的数据结构,并使用结构指针数组存储职员信息,统计公司员工工资总额和平均工资。
2 设计要求
设计要求实现如下功能:
(1)使用结构指针数组设计一个公司职员的数据结构,使用下述的结构定义:
typedef struct employee{
int age;
char *name;
double salary;
}*PEMP;
(2)在主函数里构造一个指针数组company,用来存放职工信息。
(3)设计一个update函数,用来给company赋值。
函数update(company, id, age, name, salary)的四个参数为:
company: 结构指针数组
id: company的下标
age: 年龄,整数类型
salary: 薪水,实数
(4)设计一个readin函数,直接采用调用update函数的方式进行赋值。例如:update(company, 2, 30, “LI MING”, 3000.0);
(5)编写total函数对工资求和。
这个函数应该能对全体职工和某一年龄段的职工的工资求和。
(6)编写mean函数求平均工资。
这个函数应该能对全体职工和大于某一年龄段的职工的工资求和并计算相应的平均值。

3 算法分析
为了简单起见,假设在主函数main中定义结构数组指针如下:
PEMP company[num];
下面说明几个函数的设计问题:
(1)readin函数
数组company属于main函数,它是不可见的,所以必须作为readin函数的参数。因为参数传递是传地址的方式,所以不需要返回值。以数据为例,这个函数的定义和使用方法如下:
void reading(company)
PEMP company[];
{
update(company, 2, 23, “张文”,3000.0);
update(company, 1, 33, “王微”,2400.

工资的题:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct manlib
{ char name[12];
int many;
};
main()
{ void list(struct manlib stuman);
struct manlib stuman[3];
int i;
char temp[15];
for(i=0;i<3;i++)
{ printf("请输入员工的数据:名字 工资\n");
gets(stuman[i].name);
gets(temp);
stuman[i].many=atoi(temp);
}
printf("----------------------\n");
printf("名字 工资\n");
for(i=0;i<3;i++)
list(stuman[i]);
printf("----------------------\n");
printf("公司员工收入总额 员工平均收入\n");
printf(" %d %15d\n",stuman[0].many+stuman[1].many+stuman[2].many,(stuman[0].many+stuman[1].many+stuman[2].many)/3);
}
void list(struct manlib stuman)
{
printf("%-12s %5d\n",stuman.name,stuman.many);
}