| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2099 人关注过本帖
标题:[求助]一道考试试题,谢谢大家,本人新手,希望大家以后多多照顾
只看楼主 加入收藏
which1987
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2006-12-19
收藏
得分:0 
师兄
师兄快来呀!师弟遇到困难了!
2006-12-20 12:43
form521
Rank: 1
来 自:西安
等 级:新手上路
帖 子:162
专家分:4
注 册:2006-12-21
收藏
得分:0 
這個問題有很多人都在問,你們是不是都是一個班的呀?

人生就是个死循环,退出这个循环的条件是系统停止。
2007-01-01 12:12
duopolian
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-12-12
收藏
得分:0 
共享答案
#include<stdio.h>
#include<string.h>
/*#include <malloc.h>*/
#define N sizeof(struct student)
#define M "%d %s %.1f %.1f %.1f %.1f",&p->num,p->name,&p->chinese,&p->math,&p->english,&p->pe
#define K "%d %s %.1f %.1f %.1f %.1f",p->num,p->name,p->chinese,p->math,p->english,p->pe
#define PRINT1 printf("number      name      chinese      math       english       pe")
#define PRINT2 printf(" %d     %s      %.1f      %.1f      %.1f     %.1f\n",p->num,p->name,p->chinese,p->math,p->english,p->pe)
#define PRINT3 printf("*********************************************************\n")
struct student
{
  int num;
  char name[10];
  float chinese;
  float math;
  float english;
  float pe;
  struct student *next;
};
/*input message*/
struct student *input_message(void)
{
    struct student *p1,*p2,*head;
    char ch;
    head=NULL;
    head=p2=p1=(struct student*)malloc(N);
    do
    {
        p1=(struct student *)malloc(N);
 clrscr();
        printf("\n\n\t******Input student message******\n");
        printf("\t  student num:");
        scanf("%d",&p1->num);
        printf("\t  student name:");
        scanf("%s",p1->name);
        printf("\t  student chinese:");
        scanf("%f",&p1->chinese);
        printf("\t  student math:");
        scanf("%f",&p1->math);
        printf("\t  student english:");
        scanf("%f",&p1->english);
        printf("\t  student pe:");
        scanf("%f",&p1->pe);
        p2->next=p1;
        p2=p1;
        printf("\t\tContinue? (Y/N):");
        ch=getch();
     }while(ch=='Y'||ch=='y');
     p2->next=NULL;
     p1=head;
     head=p1->next;
     free(p1);
     printf("\n\tInput over!");
     ch=getchar();
     return head;
}
struct student *insert_message(struct student *h)
{
    struct student *p,*p1;
    char ch;
    do
    {
        int i=1;
 clrscr();
        p1=(struct student *)malloc(N);
        printf("           Please input student message\n");
        printf("\t  student num:");
        scanf("%d",&p1->num);
        printf("\t  student name:");
        scanf("%s",p1->name);
        printf("\t  student chinese:");
        scanf("%f",&p1->chinese);
        printf("\t  student math:");
        scanf("%f",&p1->math);
        printf("\t  student english:");
        scanf("%f",&p1->english);
        printf("\t  student pe:");
        scanf("%f",&p1->pe);
        p1->next=NULL;
        if(h==NULL)  h=p1;
        else
        {
           p=h;
           if(p->num>p1->num)
           {
               p1->next=h;
               h=p1;
           }
           else
           {
               while(p->next!=NULL&&p->next->num<p1->num)
               p=p->next;
               if(p->next==NULL) p->next=p1;
               else if(p->next->num==p1->num)
               {
                   free(p1);
                   i=0;
               }
               else
               {
                  p1->next=p->next;
                  p->next=p1;
               }
           }
        }
    if(i==0)
    printf("\n\n       Failure!");
    else
    printf("\n\t     Continue? (Y/N):");
        ch=getch();
        if(ch=='Y'||ch=='y')
    printf("\n    Go on!");
        else
        return;
    }while(ch=='Y'||ch=='y');
}

struct student *del_message(struct student *h)
{
     struct student *p,*p1;
     int num;
     char ch;
     do
     {
          int i=1;
   clrscr();
          if(h==NULL) i=0;
          else
          {
              printf("Please input number you want to delete:");
              scanf("%d",&num);
              p=h;
              if(p->num==num)
              {
                    h=p->next;
                    free(p);
              }
              else
              {
                   p1=(h)->next;
                   while(p1!=NULL)
                   {
                        if(p1->num==num)
                        {
                              p->next=p1->next;
                             free(p1);
                        }
                        p=p1;
                        p1=p1->next;
                   }
              }
          }
      if(i==0) printf("\n\n\tFailure! Not find the student number!");
      else printf("\n\nFinish! Continue? (Y/N):");
      ch=getch();
      if(ch=='Y'||ch=='y')
      printf("\n    Go on");
      else
      return;
    }while(ch=='Y'||ch=='y');
}

/*print message*/
void print_message(struct student *h)
{
    struct student *p;
     p=h;
    clrscr();
    if(p==NULL)
    {
       printf("\n\n\t\t  NO message! Press any key back to main menu");
       bioskey(0);
    }
    else
    {
       printf("\n\n\t\t\t   *****student Message*****   \n\n");
       PRINT3;
       PRINT1;
       printf("\n");
       while(p!=NULL)
      {
         PRINT2;
         p=p->next;
      }
      printf("\n\n\t\t Print over! Press any key continue!\n\n");
      bioskey(0);
    }
}
/*average_message*/
void average_message(struct student *head)
{
  struct student *p;
  clrscr();
  p=head;
  if(head!=NULL)
   do
     {printf("average=%f\n",(p->chinese+p->math+p->english+p->pe)/4);
      p=p->next;
     }while(p!=NULL);
     getch();
}
/*sum_message*/
void sum_message(struct student *head)
{
  struct student *p;
  clrscr();
  p=head;
  if(head!=NULL)
   do
     {printf("sum=%f\n",p->chinese+p->math+p->english+p->pe);
      p=p->next;
     }while(p!=NULL);
     getch();
}
/*highest_score*/
void highest_score(struct student *head)
{
    struct student *p=head;
   float score[10],tem;
   int i=0,j;
   clrscr();
   while(p!=NULL){
   score[i]=p->chinese+p->math+p->english+p->pe;
   i++;
   p=p->next;}
   for(j=0;j<i;j++)
      if(score[0]<score[j]){
        tem=score[0];
        score[0]=score[j];
         score[j]=tem;
               }
     p=head;
   while((p->chinese+p->math+p->english+p->pe)!=score[0]){
         p=p->next;}
    PRINT1;printf("\n");
    PRINT2;
    getch();
}
void main()
{
  struct student *head;
  char ch;
  do
  {
     clrscr();
    printf("\n\n\n\t  ****student information management system****\n\n");
    printf("\t             A.Input student message\n\n");
    printf("\t             B.Print student message\n\n");
    printf("\t             C.Delete student message\n\n");
    printf("\t             D.insert student message\n\n");
    printf("\t             E.Sum  student message\n\n");
    printf("\t             F.Average  student message\n\n");
    printf("\t             G.Highest student message\n\n");
    printf("\t             Q.Exit\n\n");
    printf("\t             Select (A-Q):");
    ch=getchar();
    switch(ch)
    {
         case 'A': head=input_message();break;
         case 'B': print_message(head);break;
         case 'C': del_message(head);break;
         case 'D': insert_message(head);break;
         case 'E': sum_message(head);break;
     case 'F': average_message(head);break;
         case 'G': highest_score(head);break;
         case 'Q': break;
    }
  }while(ch!='Q');
}




用Turbo C V2.01可运行
2008-12-12 15:54
快速回复:[求助]一道考试试题,谢谢大家,本人新手,希望大家以后多多照顾
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016222 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved