#include "迅宽stdlib.h"
#include "string.h"
void inputstud (struct employee *stud)
void printstud (struct employee *stud)
void savestud (struct employee *stud)
void SR(struct employee *stud)
struct employee
{
unsigned unm /*这应该用无符亩洞亮号整型吧!*/
char sex[15]
char old[15]
char nation[15]
}
stud[100]
int n=0 /*职工数*/
void main()
{
int x
meun: while (1)
{
system ("cls")/*清屏*/
printf ("\n")
printf ("\t\t\t\t 职工信息管理系统\n")
printf ("\n")
printf ("\t\t\t\t 1:职工信息录入\颤老n")
printf ("\t\t\t\t 2:职工信息输出\n")
printf ("\t\t\t\t 3:职工信息保存\n")
printf ("\t\t\t\t 4:退出\n")
printf("\t\t\t\t\t5:查找并替换职工信息")
printf ("\n")
printf ("\t 请按序号(1~4)选择:")
scanf ("%d",&x)
switch (x)
{
case 1:inputstud (stud)break
case 2:printstud (stud)break
case 3:savestud (stud)break
case 5:SR(stid)break
default :exit (0)
}
}
}
void inputstud (struct employee *stud) /*数据输入*/
{
char ch1, ch
system ("cls")
while (1)
{
printf ("请输入职工号:")
scanf ("%u",&stud[n].num)
printf ("请输入姓名:")
scanf ("%s",stud[n].name)
printf ("请输入性别:")
scanf ("%s",stud[n].sex)
printf ("请输入年龄")
scanf ("%s",stud[n].old)
printf ("请输入民族")
scanf ("%s",stud[n].nation)
printf ("是否继续输入数据(y/n):")
ch=getchar()
ch1=getchar()
n++
if (ch=='n'||ch=='N') break
} /*统计人数*/
printf ("\n\t 数据输入完毕!\n")
}
void printstud (struct employee *stud)
{
int i,j
struct employee b /*定义结构体变量b*/
system ("cls")
for (i=0i<n-1i++) /*冒泡*/
{
if ( stud[i].unm>stud[i+1].unm) /*串比较大小用strcmp*/
{
b=stud[i]
stud[i]=stud[i+1]
stud[i+1]=b
}
}
printf ("以下是所有职工的信息\n")
for (i=0i<ni++)
{
printf ("%6u%6s%6s%6s%6s\n",stud[i].num,stud[i].name,stud[i].sex,stud[i].old,stud[i].nation)
}
printf ("请按任意数字键返回主菜单")
/*这句看不懂,不知道他的作用,不懂*/
getchar()
getchar()
}
void savestud (struct employee *stud)
{
int i
FILE *fp
fp=fopen ("d:\\employee.dat","w") (二进制好像是.bin)
for (i=0i<ni++)
if (fwrite (&stud[i],sizeof(struct employee),1,fp)!=1)
printf ("不能保存文件!\n")
fclose (fp)
printf ("文件保存完毕!\n")
printf ("请按任意数字键返回主菜单")
scanf ("%d",&i)
}
void SR(struct employee *stud)
{ unsigned scompare
char compare[15]
swhil(1)
{ char C
if(n==0) {printf(”还未录入数据\n")goto meun}
printf("请选择查找方式(1.工号查找2姓名查找、输入#停止)\n")
C=getchar()
if (C==#) break
int i
if(C==1)
{ scanf("%u",&scampare)
for(i=0i<nn++)
if(scompare==stud[i].unm)
{printf ("%6s%6s%6s%6s%6s\n",stud[i].num,stud[i].name,stud[i].sex,stud[i].old,stud [i].nation)
printf("请重新录入该职工档案:\n")}
}
eles
{ scanf("%s",scampare)
for(i=0i<nn++)
if(strcmp(compare,stud[i].name)==0)
{printf ("%6s%6s%6s%6s%6s\n",stud[i].num,stud[i].name,stud[i].sex,stud[i].old,stud [i].nation)
printf("请重新录入该职工档案:\n")}
}
printf ("请输入职工号:")
scanf ("%u",&stud[n].num)
printf ("请输入姓名:")
scanf ("%s",stud[n].name)
printf ("请输入性别:")
scanf ("%s",stud[n].sex)
printf ("请输入年龄")
scanf ("%s",stud[n].old)
printf ("请输入民族")
scanf ("%s",stud[n].nation)
for (i=0i<n-1i++) /*冒泡*/
{if ( stud[i].unm>stud[i+1].unm) /*排序*/
{
b=stud[i]
stud[i]=stud[i+1]
stud[i+1]=b
}
}
}}
#include<stdio.h>#define NUM 100//把此处的宏定义成100就是你想要数世的100个职工了
struct WorkerInfo
{
char Number[10]
char name[10]
float wage
}
float arg,*point=&arg//为御孙了正确使用浮点数,此处务必如此定义
void main()
{
struct WorkerInfo wi[NUM]
int i
float sum=0
for(i=0i<NUMi++)
{
printf("Please input the %d woker's information:",i+1)
scanf("%s",wi[i].Number)/* Number 为数组名,不加&*/
scanf("%s",wi[i].name)
scanf("%f",&wi[i].wage)
sum+=wi[i].wage
}
printf("\nThe average wage is :%f\n",sum/NUM)
printf("Number name wage\n")
for(i=0i<NUMi++)
{
if(wi[i].wage<300.00)
printf("%s,%s,%6f\n",wi[i].Number,wi[i].name,wi[i].wage)
}
}
//楼主的程序完全正确,基本不用修改,
//可以把宏定义成3来验证薯拆肢程序的正确与否,
//注意输入的方式,先输入数字,然后回车,
//再输入名字再回车,再输入工资,然后就会转到第二个人了,不然会出错的
我给你编写了一个简单的,你自己缺亮参考一下,自己润色吧!!!#include<念扮桐stdio.h>
typedef struct employee
{
char employee_num[15]
float salary
}employee
main()
{
employee A[10]
for(int i=0i<10i++)
{
printf("input the number and the salary of the employee %d ",i+1)
scanf("%s %f",&A[i].employee_num,&A[i].salary)
}
float average_salary=0
for(i=0i<10i++)
average_salary+=A[i].salary
average_salary=average_salary/10
for(i=0i<10i++)
{
if(A[i].salary<average_salary)
printf("%s,%.4f\n"仔坦,A[i].employee_num,A[i].salary)
}
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)