一个小作业

作者在 2010-07-01 10:29:09 发布以下内容
/*
有10个职工,每个职工的数据包括职工编号、姓名、职称、工龄及基准工资,从键盘输入每个职工的数据,
具体要求:
(1) 通过键盘接收数据;
(2) 计算并输出每个职工应发的工资(工资计算原则是:基准工资*职称系数+基准工资*10%*工龄系数;
职称系数:初级为1、中级为1.2、高级为1.5;工龄系数=工龄/2);
(3) 计算并输出平均工资;
(4) 按工资从低到高进行排序;
(5) 从排序结果中,查找满足某一工资的职工信息,并输出;
(6) 所有操作都要给出相应的提示,方便他人操作。
*/
#include<stdio.h>
#include<string.h>
struct gongren
{ int n;
  char name[30];
  char zc[18];
  int o;
  int m;
  float sum;
}w[10];
int i;
void win();
void Input();
void Output();
void average();
void count();
void getincome();
void Input()
{
    printf("请依次输入:职工编号、姓名、职称、工龄及基准工资\n");
    for (i=0;i<10;i++)
      scanf("%d%s%s%d%d",&w[i].n,w[i].name,w[i].zc,&w[i].o,&w[i].m);
    printf("10个数据已经全部输入完成!\n");
    win();
}

void Output()
{
    count();
    for(i=0;i<10;i++)
      printf("ID:%d\nName:%s\nLeval:%s\nWork age:%d\nIncome:%f\n",w[i].n,w[i].name,w[i].zc,w[i].o,w[i].sum);
    win();
}
void count()
{
  float x=1.0;
  for (i=0;i<10;i++)
  {
      if (!strcmp(w[i].zc,"c")) x=1.0;
      if (!strcmp(w[i].zc,"z")) x=1.2;
      if (!strcmp(w[i].zc,"g")) x=1.5;
      w[i].sum=w[i].m*x+w[i].m*0.10*((w[i].o+0.0)/2.0);
  }
}

void average()
{
    float aver=0.0;
    count();
    for (i=0;i<10;i++)
      aver+=w[i].sum+0.0;
    aver/=2;
    printf("平均工资为: %f\n",aver);
  win();
}

void P()
{
  int j;
  struct gongren tmp;
  count();
  for (i=0;i<10;i++)
      for (j=i+1;j<10;j++)
          if (w[i].sum>w[j].sum)
          {
                tmp.sum=w[i].sum;
                w[i].sum=w[j].sum;
                w[j].sum=tmp.sum;
                
                strcpy(tmp.zc,w[i].zc);
                strcpy(w[i].zc,w[j].zc);
                strcpy(w[j].zc,tmp.zc);
                    
                tmp.n=w[i].n;
                w[i].n=w[j].n;
                w[j].n=tmp.n;

                tmp.m=w[i].m;
                w[i].m=w[j].m;
                w[j].m=tmp.m;

                tmp.o=w[i].o;
                w[i].o=w[j].o;
                w[j].o=tmp.o;

                strcpy(tmp.name,w[i].name);
                strcpy(w[i].name,w[j].name);
                strcpy(w[j].name,tmp.name);
              }
              Output();
  win();

}

void Pr()
{
    int key,flag=0;
    printf("输入:职工编号来查找\n");
    scanf("%d",&key);
    count();
    for(i=0;i<10;i++)
        if(key==w[i].n)
        {
            flag=1;
            break;
        }
        if(flag)
        {
            printf("ID:%d\nName:%s\nLeval:%s\nWork age:%d\n Income:%f\n",w[i].n,w[i].name,w[i].zc,w[i].o,w[i].sum);
            printf("You found him!\n");
        }
        else
            printf("Not found!\n");
        win();
}

void win()
{
  int hi;
  printf("+-------------------------------------------------+\n");
  printf("|                                                 |\n");
  printf("|        欢迎来到工资管理系统                     |\n");
  printf("|                                                 |\n");
  printf("+-------------------------------------------------+\n");
  printf("| 1.输入数据              2.计算工资              |\n");
  printf("| 3.平均工资              4.高低排序              |\n");
  printf("| 5.查找并显示            0.关闭程序              |\n");
  printf("+-------------------------------------------------+\n");
  printf("请输入你的选择:");
  scanf("%d",&hi);
  switch(hi)
   {
     case 0: exit(0);break;
     case 1: Input(); break;
     case 2: getincome(); break;
     case 3: average(); break;
     case 4: P(); break;
     case 5: Pr();break;
   }
}
void getincome()
{
    count();
    for (i=0;i<10;i++)
        printf("%s的工资为:%f\n",w[i].name,w[i].sum);
    win();
}
    
void main()
{
  win();
}
 
默认分类 | 阅读 618 次
文章评论,共0条
游客请输入验证码
浏览52057次
文章分类