学历改变命运
24小时客服:4008135555/010-82335555
当前位置:首页 > 笔记串讲 > 自考“高级语言程序设计”习题答案详解(42

自考“高级语言程序设计”习题答案详解(42)

2007年09月04日    来源:   字体:   打印

  2.编一个程序,输入10个职工的编号、姓名、基本工资、职务工资,求出其中“基本工资十职务工资”更少的职工姓名并输出。

  「解」类似上一程序,直接给出程序如下:

  # include

  # define N 10

  struct person {

  char no[10];

  char name[20];

  float base1;

  float base2;

  } person[N], *p, *minp;

  void main ()

  { float d;

  char buf[120];

  printf(“输入%d个人的编号、姓名、基本工资、职务工资 \n”, N);

  for(p=person; p<PERSON+N; P++) {

  scanf(“%s”, buf); strncpy(p -> no,buf,9);

  scanf(“%s”, buf); strncpy( p -> name, buf, 19);

  scanf(“%f”, &d);p -> base1 =d;

  scanf(“%f”,&d);p -> base2=d;

  }

  for(minp=p=person; p<PERSON+N; P++)

  if (p -> basel+p -> base2< minp -> basel+ minp -> base2) minp =p;

  printf(“基本工资与职务工资和更少的职工是%s \n”,minp -> name);

  printf(“他的基本工资与职务工资和是%.2f \n”,minp -> basel+ minp -> base2);

  }

  3.编一个程序,输入10个学生的学号、姓名、3门课程的成绩,求出总分更高的学生姓名并输出。

  「解」类似上一程序,直接给出程序如下:

  # include

  # include

  # define N 10

  struct stu {

  char no[10];

  char name[20];

  int score[3];

  } students[N],*p, *maxp;

  void main()

  { char buf[120]; int maxs;

  printf(“输入%d个学生的编号、姓名、三门课程成绩 \n”, N);

  for(p= students;p< students+N;p++) {

  scanf(“%s”, buf); strncpy(p -> no, buf, 9);

  scanf(“%s”, buf); strncpy( p -> name, buf,19);

  scanf(“%d%d%d”,&p -> score[O], &p -> score[1], &p -> score[2]);

  }

  for(maxp= p =students, maxs=-1; p< students+N; p++)

  if( p -> score[0] + p -> score[1]+p -> score[2]> maxs) {

  maxp=p;maxs=p ->score[0]+p -> score[1]+p ->score[2];

  }

  printf(“更高总分的学生是%s他的总分是 %d \n”, maxp -> name, maxs);

  }

关闭