懂C语言的进来,做一个编程
用结构体表示一个职工的信息(姓名,级别,工资),定义一个结构体数组表示十个职工,并对职工的姓名,级别赋初值,计算所有职工的工资,并在文件中输出每个职工的所有信息.(先完成...
用结构体表示一个职工的信息(姓名,级别,工资),定义一个结构体数组表示十个职工,并对职工的姓名,级别赋初值,计算所有职工的工资,并在文件中输出每个职工的所有信息.(先完成在屏幕输出,学完文件后再修改从文件输出)
1,从键盘录入10个职工的级别(初级,中级,高级),2根据职工级别计算职工工资(初级为800,中级为1000,高级1200),并计算工资总和,3输出所有职工级别及工资,并输出工资总额. 展开
1,从键盘录入10个职工的级别(初级,中级,高级),2根据职工级别计算职工工资(初级为800,中级为1000,高级1200),并计算工资总和,3输出所有职工级别及工资,并输出工资总额. 展开
3个回答
展开全部
/*用C实现
用结构体表示一个职工的信息(姓名,级别,工资),定义一个结构体数组表示十个职工,
并对职工的姓名,级别赋初值,计算所有职工的工资,并在文件中输出每个职工的所有信息
.(先完成在屏幕输出,学完文件后再修改从文件输出)
1,从键盘录入10个职工的级别(初级,中级,高级),
2根据职工级别计算职工工资(初级high为800,中级higher为1000,高级highest1200),并计算工资总和,
3输出所有职工级别及工资,并输出工资总额.*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct StaffInformation
{
char name[30];
char level[30];
int salary;
};
void main()
{
StaffInformation staff[10];
FILE *fp;
int i;
int sum = 0;
//输入员工资料,并计算工资及其总和
for (i = 0; i < 10; i++)
{
printf("please input the staff information:No %d of 10\nname level(high,higher,higest)\n",i+1);
scanf("%s%s",staff[i].name,staff[i].level);
//等级输入不合规则,错误处理
while(strcmp(staff[i].level,"high") && strcmp(staff[i].level,"higher") && strcmp(staff[i].level,"highest"))
{
printf("The staff level is wrong,please input again!\n");
scanf("%s",staff[i].level);
}
if (!strcmp(staff[i].level,"high"))
{
staff[i].salary = 800;
}else if (!strcmp(staff[i].level,"higher"))
{
staff[i].salary = 1000;
}else if (!strcmp(staff[i].level,"highest"))
{
staff[i].salary = 1200;
}
sum += staff[i].salary;
printf("\n");
}
//输出所有职工级别及工资,并输出工资总额,输出文件为staff.txt
if ((fp = fopen("staff.txt","w")) ==NULL)
{
printf("open the file error!");
exit(0);
}
printf("The staff information:\nname level salary\n");
for (i = 0; i < 10; i++)
{
printf("%s\t%s\t%d\n",staff[i].name,staff[i].level,staff[i].salary);
fprintf(fp,"%s\t%s\t%d\n",staff[i].name,staff[i].level,staff[i].salary);
}
printf("the sum of salary:%d\n",sum);
fprintf(fp,"the sum of salary:%d",sum);
fclose(fp);
}
//我要分啊,呵呵
用结构体表示一个职工的信息(姓名,级别,工资),定义一个结构体数组表示十个职工,
并对职工的姓名,级别赋初值,计算所有职工的工资,并在文件中输出每个职工的所有信息
.(先完成在屏幕输出,学完文件后再修改从文件输出)
1,从键盘录入10个职工的级别(初级,中级,高级),
2根据职工级别计算职工工资(初级high为800,中级higher为1000,高级highest1200),并计算工资总和,
3输出所有职工级别及工资,并输出工资总额.*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct StaffInformation
{
char name[30];
char level[30];
int salary;
};
void main()
{
StaffInformation staff[10];
FILE *fp;
int i;
int sum = 0;
//输入员工资料,并计算工资及其总和
for (i = 0; i < 10; i++)
{
printf("please input the staff information:No %d of 10\nname level(high,higher,higest)\n",i+1);
scanf("%s%s",staff[i].name,staff[i].level);
//等级输入不合规则,错误处理
while(strcmp(staff[i].level,"high") && strcmp(staff[i].level,"higher") && strcmp(staff[i].level,"highest"))
{
printf("The staff level is wrong,please input again!\n");
scanf("%s",staff[i].level);
}
if (!strcmp(staff[i].level,"high"))
{
staff[i].salary = 800;
}else if (!strcmp(staff[i].level,"higher"))
{
staff[i].salary = 1000;
}else if (!strcmp(staff[i].level,"highest"))
{
staff[i].salary = 1200;
}
sum += staff[i].salary;
printf("\n");
}
//输出所有职工级别及工资,并输出工资总额,输出文件为staff.txt
if ((fp = fopen("staff.txt","w")) ==NULL)
{
printf("open the file error!");
exit(0);
}
printf("The staff information:\nname level salary\n");
for (i = 0; i < 10; i++)
{
printf("%s\t%s\t%d\n",staff[i].name,staff[i].level,staff[i].salary);
fprintf(fp,"%s\t%s\t%d\n",staff[i].name,staff[i].level,staff[i].salary);
}
printf("the sum of salary:%d\n",sum);
fprintf(fp,"the sum of salary:%d",sum);
fclose(fp);
}
//我要分啊,呵呵
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询