首页 > 用户发贴区 > 编程问题提问区 > 有人能帮我再加点内容么?
2008
08-28

有人能帮我再加点内容么?

/*程序说明:

1.此程序为简易版的数据库

2.其工作能力有以下几点:

⑴首先按次序输入N个学生的【号码  姓名  各科成绩】

⑵此程序只能对某一行进行添加或者删除,再添加的时候直接按键盘上的“+”

  在删除某一行的时候,直接按键盘上的“-”,如果不做任何修改,则直接在

  屏幕上输入“quit”即可退出程序。

⑶程序为了进一步完善,还进行了查找某学生成绩的项目,其分为两种。一种

  是根据学生的号码进行某个学生内容的查找;一种是根据需生的姓名进行某个

  学生内容的查找。

⑷此简易程序仅为了满足要求,还有很多内容需要以后进一步的完善!

*/

struct student {int num;

       char name[20];

       int res1;/*定义数学成绩*/

       int res2;/*定义英语成绩*/

       int res3;/*定义科技之光成绩*/

       struct student *next;/*创建学生人数动态链表分配*/

       };                       

#define PRINT “\r %3d   %4s   %3d    %3d    %3d\n”

#define print “\r num   name  math   English   science\n”

#define NULL 0

#define LEN sizeof(struct student)   

#include “conio.h”

struct student *p[100];int k=1,s=1,choose1,choose3,choose4,choose5;

char rename[20];

char y[20];

char str3[]={“quit”};

char str4[20];

welcome()/*开篇花絮*/

{int j;char a;

textcolor(YELLOW);

gotoxy(28,10);

cprintf(“Welcome My easy Excel!”); /*定义字体颜色,并输出*/

textcolor(RED);

gotoxy(26,20);

cprintf(“press any key to continue:”);

while(!kbhit());/*(kbhit_检验当前按下的键)*/

system(“cls”);/*清屏*/

}

choose()

{struct student out();

struct student operation();

char str5[]={“num”};

char str6[]={“name”};

char str1[]={“-”},str2[]={“+”};

E:{printf(“\nchoose the:\n”);

  printf(“     1.find a student’s number(num);\n\n”);

  /*输入学生的号码并查找出来次学生的内容*/

  printf(“     2.pick out student’s name(name);\n\n”);

  /*输入学生的姓名,并查找出来次学生的所有内容*/

  printf(“     3.add or delete another row of student’s informations( + or – ):\n\n”);

  /*输入“-”表示删除某一行,输入“+”表示添加某行,输入“quit表示退出程序*/

  printf(“  You can choose one of condition to change students’ Excel!\n”);

  printf(“   Please write down your choose or input ‘quit’ to exit:”);

  scanf(“%s”,str4);

  if(strcmp(str3,str4)==0) {clrscr();out();}

  else if(strcmp(str2,str4)==0) operationa();

  else if(strcmp(str1,str4)==0) operationc();

  else if(strcmp(str5,str4)==0) operationd();

  else if(strcmp(str6,str4)==0) operatione();

  else {printf(“error\n\n”);goto E;}

  }

}

operationa()

{struct student out();

struct student *add;int u;

struct student *p1,*p5;

p1=p[0];p5=p[0];

system(“cls”);

printf(“\n\n\n\n”);

textcolor(YELLOW);

cprintf(“Please input the add row:”);

scanf(“%d”,&s);

if(s!=0)

{add=(struct student *)malloc(LEN);

  {printf(“\n\n\nInput the student’s num:”);

  scanf(“%d”,&add->num);

  printf(“\n\n\n\n”);

  printf(“input the student’s name:”);

  scanf(“%s”,&add->name);

  printf(“\n\n\n\n”);

  printf(“input the student’s math result:”);

  scanf(“%d”,&add->res1);

  printf(“\n\n\n\n”);

  printf(“input the student’s English result:”);

  scanf(“%d”,&add->res2);

  printf(“\n\n\n\n”);

  printf(“input the student’s science result:”);

  scanf(“%d”,&add->res3);

  }

if(s==1) {add->next=p[0];p[0]=add;out();}

if(s!=1)

{for(u=1;u<s;u++)

  {p1=p1->next;

   if(u!=1)p5=p5->next;

  }

  p5->next=add;

  add->next=p1;

}

out();

}  

}

operationc()

{struct student out();

int q;

struct student *p3,*p4;

p3=p[0];p4=p[0];

printf(“\nPlease input the Delete row:”);

scanf(“%d”,&k);

if(k!=0)

{if(k==1) {p[0]=p[0]->next;out();}

if(k!=1)

{for(q=0;q<k;q++)

  {p3=p3->next;

  if((q!=0)&&(q!=1)) p4=p4->next;

  }

  p4->next=p3;

}

  out();

}

}

operationd()

{struct student out();

struct student *p6,*p7;

int x,i,j; char a[]={“Y”},b[]={“N”},c[10];

p6=p[0];p7=p[1];

system(“cls”);

printf(“\n\n\nPlease input the student’s number :”);

scanf(“%d”,&x);

for(;strcmp(x,p6->num)!=0&&p7!=NULL;)

  {p6=p7;p7=p7->next;}

if(x==p6->num)

{system(“cls”);

  printf(“\n\n”);

  printf(print);

  printf(PRINT,p6->num,p6->name,p6->res1,p6->res2,p6->res3);

  textcolor(YELLOW);

  cprintf(“\npress any key to continue:”);

  while(!kbhit());

  system(“cls”);

loop1 : printf(“\n1 change a new num.\n”);

   printf(“\n2 change a new name.\n”);

   printf(“\n3 change a new math’s score.\n”);

   printf(“\n4 change a new English’s score.\n”);

   printf(“\n5 change a new science’s score.\n”);

   printf(“\n6 Go out and print the students’ information.\n”);

   printf(“\nInput your choose:”);

   scanf(“%d”,&i);

   switch(i)

     {case 1 : change1(); p6->num=choose1; break;

     case 2 : change2(); strncpy(p6->name,rename,20); break;

     case 3 : change3(); p6->res1=choose3; break;

     case 4 : change4(); p6->res2=choose4; break;

     case 5 : change5(); p6->res3=choose5; break;

     case 6 : goto looq1 ;

     }

   system(“cls”);

   printf(“The new information is :\n”);

   printf(print);

   printf(PRINT,p6->num,p6->name,p6->res1,p6->res2,p6->res3);

   printf(“\npress any key to continue!”);

   while(!kbhit()); system(“cls”);

chooseyn1 :

     printf(“\n\nIf you want change others information, pleas choose<Y> else<N>:”);

     gets(c); if(strcmp(c,a)==0)

         {goto loop1;}

        else if(strcmp(c,b)==0)

         {}

        else if(strcmp(c,a)!=0&&strcmp(c,b)!=0)

         {printf(“\n\nerro!\n\nplease choose <Y> or <N>:”);

          goto chooseyn1;}

   looq1: out();

}

else if(x==p7->num)

   {system(“cls”);

    printf(“\n\n”);

    printf(print);

    printf(PRINT,p7->num,p7->name,p7->res1,p7->res2,p7->res3);

    textcolor(YELLOW);

    cprintf(“\npress any key to continue:”);

    while(!kbhit());

    system(“cls”);

loop2 : printf(“\n1 change a new num.\n”);

    printf(“\n2 change a new name.”);

    printf(“\n3 change a new math’s score.\n”);

    printf(“\n4 change a new English’s score.\n”);

    printf(“\n5 change a new science’s score.\n”);

    printf(“\n6 Go out and print the students’ information.\n”);

    printf(“\nInput your choose:”);

    scanf(“%d”,&i);

    switch(i)

     {case 1 : change1(); p6->num=choose1; break;

     case 2 : change2(); strncpy(p7->name,rename,20); break;

     case 3 : change3(); p6->res1=choose3; break;

     case 4 : change4(); p6->res2=choose4; break;

     case 5 : change5(); p6->res3=choose5; break;

     case 6 : goto looq2;

     }

   system(“cls”);

   printf(“The new information is :\n”);

   printf(print);

   printf(PRINT,p7->num,p7->name,p7->res1,p7->res2,p7->res3);

   printf(“\npress any key to continue!”);

   while(!kbhit()); system(“cls”);

chooseyn2 :

     printf(“\n\nIf you want change others information, pleas choose<Y> else<N>:”);

     gets(c); if(strcmp(c,a)==0)

         {goto loop1;}

        else if(strcmp(c,b)==0)

         {}

        else if(strcmp(c,a)!=0&&strcmp(c,b)!=0)

         {printf(“\n\nerro!\n\nplease choose <Y> or <N>:”);

          goto chooseyn2;}

    looq2: out();

     }

else if(x!=p6->num&&x!=p7->num)

   {system(“cls”);

    printf(“\n\n”);

    textcolor(RED);

    cprintf(“erro!!!\n\n\n”);

    printf(“It couldn’t find the number, please input a right one.\n\n\n”);

    textcolor(YELLOW);

    cprintf(“    press any key to countinue:”);

    while(!kbhit());

    system(“cls”);

    out();}

}

operatione()

{struct student out();

struct student *p8,*p9;

int i; char a[]={“Y”},b[]={“N”},c[10];

p8=p[0];p9=p[1];

system(“cls”);

textcolor(YELLOW);

cprintf(“\n\n\nPlease input the student’s name :”);

gets(y);

for(;strcmp(y,p8->name)!=0&&p9->name!=NULL;)

  {p8=p9; p9=p9->next;}

if(strcmp(y,p8->name)==0)

{system(“cls”);

  printf(“\n\n”);

  printf(print);

  printf(PRINT,p8->num,p8->name,p8->res1,p8->res2,p8->res3);

  textcolor(YELLOW);

  cprintf(“\npress any key to continue:”);

  while(!kbhit());

  system(“cls”);

loop3 : printf(“\n1 change a new num.\n”);

   printf(“\n2 change a new name.\n”);

   printf(“\n3 change a new math’s score.\n”);

   printf(“\n4 change a new English’s score.\n”);

   printf(“\n5 change a new science’s score.\n”);

   printf(“\n6 Go out and print the students’ information.\n”);

   printf(“\nInput your choose:”);

   scanf(“%d”,&i);

   switch(i)

     {case 1 : change1(); p8->num=choose1; break;

     case 2 : change2(); strncpy(p8->name,rename,20); break;

     case 3 : change3(); p8->res1=choose3; break;

     case 4 : change4(); p8->res2=choose4; break;

     case 5 : change5(); p8->res3=choose5; break;

     case 6 : goto looq3;

     }

   system(“cls”);

   printf(“The new information is :\n”);

   printf(print);

   printf(PRINT,p8->num,p8->name,p8->res1,p8->res2,p8->res3);

   printf(“\npress any key to continue!”);

   while(!kbhit()); system(“cls”);

chooseyn3 :

     printf(“\n\nIf you want change others information, pleas choose<Y> else<N>:”);

     gets(c); if(strcmp(c,a)==0)

         {goto loop3;}

        else if(strcmp(c,b)==0)

         {}

        else if(strcmp(c,a)!=0&&strcmp(c,b)!=0)

         {printf(“\n\nerro!\n\nplease choose <Y> or <N>:”);

          goto chooseyn3;}

    looq3:  out();

  }

  else if(strcmp(y,p9->name)==0)

    {system(“cls”);

     printf(“\n\n”);

     printf(print);

     printf(PRINT,p9->num,p9->name,p9->res1,p9->res2,p9->res3);

     textcolor(YELLOW);

     cprintf(“\npress any key to continue:”);

     while(!kbhit());

     system(“cls”);

loop4 : printf(“\n1 change a new num.\n”);

   printf(“\n2 change a new name.\n”);

   printf(“\n3 change a new math’s score.\n”);

   printf(“\n4 change a new English’s score.\n”);

   printf(“\n5 change a new science’s score.\n”);

   printf(“\n6 Go out and print the students’ information.\n”);

   printf(“\n6 Go out and print the students’ information.\n”);

   printf(“\nInput your choose:”);

   scanf(“%d”,&i);

   switch(i)

     {case 1 : change1(); p9->num=choose1; break;

     case 2 : change2(); strncpy(p9->name,rename,20); break;

     case 3 : change3(); p9->res1=choose3; break;

     case 4 : change4(); p9->res2=choose4; break;

     case 5 : change5(); p9->res3=choose5; break;

     case 6 : goto looq4;

     }

   system(“cls”);

   printf(“The new information is :\n”);

   printf(print);

   printf(PRINT,p9->num,p9->name,p9->res1,p9->res2,p9->res3);

   printf(“\npress any key to continue!”);

   while(!kbhit()); system(“cls”);

chooseyn4 :

     printf(“\n\nIf you want change others information, pleas choose<Y> else<N>:”);

     gets(c); if(strcmp(c,a)==0)

         {goto loop4;}

        else if(strcmp(c,b)==0)

         {}

        else if(strcmp(c,a)!=0&&strcmp(c,b)!=0)

         {printf(“\n\nerro!\n\nplease choose <Y> or <N> !”);

          goto chooseyn4;}

   looq4: out();

  }

  else if(strcmp(y,p8->name)!=0&&strcmp(y,p9->name)!=0)

   {system(“cls”);

    printf(“\n\n”);

    textcolor(RED);

    cprintf(“erro!!!\n\n\n”);

    printf(“It couldn’t find the number, please input a right one.\n\n\n”);

    textcolor(YELLOW);

    cprintf(“    press any key to countinue:”);

    while(!kbhit());

    system(“cls”);

    out();

  }

}

struct student out()

{char a;struct student *p2;

p2=p[0];

clrscr();

printf(print);

for(;;)

  {printf(PRINT,p2->num,p2->name,p2->res1,p2->res2,p2->res3);

  if(p2->next==NULL) break;

  p2=p2->next;

  }

  if(strcmp(str3,str4)!=0) choose();

  else if(strcmp(str3,str4)==0) scanf(“%c”,&a);

    else;

}

struct student *creat() /*增加的学生信息表链*/

{int n;

for(n=0;n<=100;n++)

{p[n]=(struct student *)malloc(LEN);

  p[n]->next=NULL;

  printf(“\nInput the %dth student’s num:”,n+1);

  scanf(“%d”,&p[n]->num);                           

  if(p[n]->num==0) {p[n]->name[0]=’-';p[n]->name[1]=’*';p[n]->res1=p[n]->res2=p[n]->res3=0;break;}

  printf(“\n\n”);

  textcolor(YELLOW);

  cprintf(“Input the %dth student’s name:”,n+1);

  textcolor(WHITE);

  cscanf(“%s”,&p[n]->name);

  printf(“\n\n”);

  textcolor(WHITE);

  cprintf(“Input the %dth student’s math result:”,n+1);

  scanf(“%d”,&p[n]->res1);

  printf(“\n\n”);

  textcolor(WHITE);

  cprintf(“Input the %dth student’s English result:”,n+1);

  scanf(“%d”,&p[n]->res2);

  printf(“\n\n”);

  textcolor(WHITE);

  cprintf(“Input the %dth student’s science result:”,n+1);

  scanf(“%d”,&p[n]->res3);

  clrscr();                                 

}

for(n=0;;n++)

{p[n]->next=p[n+1];

if(p[n]->next==NULL) break;

}                                                                                                                             

return(NULL);                                    

}

change1()

{printf(“Please input a new number !”);

scanf(“%d”,&choose1);}

change2()

{printf(“Please input a new name!”);

gets(rename);}

change3()

{printf(“Please input a new math’s score !”);

scanf(“%d”,&choose3);}

change4()

{printf(“Please input a new English’s score !”);

scanf(“%d”,&choose4);}

change5()

{printf(“Please input a new science’s score !”);

scanf(“%d”,&choose5);}

main()                 

{

welcome();

creat();

out();

}


留下一个回复