好兵帅克下载:C语言的程序

来源:百度文库 编辑:高校问答 时间:2024/04/27 23:39:56
那位能给一个C语言的学生成绩管理系统
有插入,修改,删除,查找,显示的功能。用单链表做!!!
本人急用!!!
谢过!!!

我这有一个成绩的管理系统
#include<stdio.h>
#include<conio.h> /*头文件*/
#define ERROR 0
#define TRUE 1
#define FALSE 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10 /*宏定义*/

typedef int Status ; /*类型名定义用status代替int*/

struct STU{ /*定义学生信息结构体*/
char name[20];
char stuno[10];
int age;
int score;
};
typedef struct STU SElemType; /*类型名定义用selemtype代替结构体STU*/

struct STACK /*定义结构体指针*/
{
SElemType *base;
SElemType *top;
int stacksize;
};

typedef struct STACK SqStack; /*类型名定义用sqstack代替结构体stack*/
typedef struct STACK *pSqstack; /*类型名定义用*psqstack代替结构体stack*/

Status InitStack(SqStack **S);
Status DestroyStack(SqStack *S);
Status ClearStack(SqStack *S);
Status StackEmpty(SqStack S);
int StackLength(SqStack S);
Status GetTop(SqStack *Sa,SElemType *e);
Status Push(SqStack *S,SElemType e);
Status Pop(SqStack *Sa,SElemType *e);
Status StackPrintElem(SElemType e);
Status StackTraverse(SqStack S,SElemType *e);
Status input(SElemType e,SqStack *Sa); /*函数申明*/

Status InitStack(SqStack **S)
{ /*初始化栈*/
(*S)=(SqStack *) malloc(sizeof(SqStack)); /*为栈申请空间*/
(*S)->base=(SElemType *)malloc(STACK_INIT_SIZE *sizeof(SElemType)); /*为学生信息的结构体申请空间*/
if(!(*S)->base)exit(OVERFLOW);
(*S)->top=(*S)->base;
(*S)->stacksize=STACK_INIT_SIZE;
return OK;
}

Status DestroyStack(SqStack *Sa)
{ /*销毁栈*/
free(Sa->base);
free(Sa); /*释放空间*/
}

Status ClearStack(SqStack *Sa)
{ /*清空栈*/
Sa->top=Sa->base;
}

Status StackEmpty(SqStack S)
{ /*测试栈是否为空*/
if(S.top==S.base)
printf("the stack is empty!\n");
else
printf("the stack is not empty!\n");
}

StackLength(SqStack S)
{ /*求栈长度*/
int i;
SElemType *p;
i=0;
p=S.top;
while(p!=S.base) /*依次改变top指针并用i记录*/
{p--;
i++;
}
printf("\ni=%d\n",i);
}

Status GetTop(SqStack *Sa,SElemType *e)
{ /*读栈顶元素*/
if(Sa->top==Sa->base)
return ERROR;
else{ *e=*(Sa->top-1);
StackPrintElem(*e); /*调用打印函数*/
}
}
Status Push(SqStack *S,SElemType e)
{ /*入桟*/
if(S->top-S->base>=S->stacksize)
{

S->base=(SElemType *) realloc(S->base,
(S->stacksize + STACKINCREMENT) * sizeof(SElemType));
if(!S->base)exit(OVERFLOW);
S->top=S->base+S->stacksize;
S->stacksize += STACKINCREMENT;
}

*(S->top++)=e; /*保存入桟信息*/
return OK;
}

Status Pop(SqStack *Sa,SElemType *e)
{ /*出栈*/
if(Sa->top==Sa->base)
return ERROR;
else{
*e=*Sa->top;
StackPrintElem(*e);
}

}

Status StackPrintElem(SElemType e)
{ /*打印*e元素的信息*/
printf("%s %s %d %d\n",e.name,e.stuno,e.age,e.score);
}

Status StackTraverse(SqStack S,SElemType *e)
{ /*遍历并打印*/
while(S.top!=S.base)
{
S.top--;
e=S.top;
StackPrintElem(*e);
}
}
Status input(SElemType e,SqStack *Sa) /*输入信息*/
{ int i,n;

printf("Input the n:"); /*输入要插入的元素的个数*/
scanf("%d",&n);

for(i=0;i<n;i++)
{
printf("input:");
scanf("%s %s %d %d",&e.name,&e.stuno,&e.age,&e.score);
Push(Sa,e);
}

}

main()
{ int j,i,n;
SElemType e;
SqStack *Sa;

clrscr();

printf("\n\n-------------------SqStack Demo is running...----------------\n\n");
printf("First is Push function.\n");

InitStack(&Sa); /*初始化栈*/

printf(" Now Stack is Empty.\n");

input(e,Sa); /*输入*/

printf("StackTraverse and printing:\n");
StackTraverse(*Sa,&e); /*遍历并打印*/
printf(" StackLength is i:");
StackLength(*Sa); /*求栈长度*/

printf("\nthe number you want output:"); /*要出桟元素的个数*/
scanf("%d",&j);

Sa->top=Sa->top-1;
for(i=0;i<j;i++)
{ Pop(Sa,&e);
Sa->top=Sa->top-1;
} /*出栈个数及打印*/
Sa->top=Sa->top+1;
StackEmpty(*Sa); /*测试栈是否为空*/

printf("StackTraverse and printing:\n");
StackTraverse(*Sa,&e);

input(e,Sa); /*输入*/

printf(" StackLength is i:");
StackLength(*Sa); /*求栈长度*/

printf("StackTraverse and printing:\n");
StackTraverse(*Sa,&e); /*遍历并打印*/

printf("\nGetTop is:");
GetTop(Sa,&e); /*读栈顶元素*/

ClearStack(Sa); /*清空栈*/

printf(" StackLength is i:");
StackLength(*Sa); /*求栈长度*/

DestroyStack(&Sa); /*销毁栈*/

getch();
}
以下是运行的结果:
-------------------SqStack Demo is running...----------------

First is Push function.
Now Stack is Empty.
Input the n:3
input:stu5 2004005 19 65
input:stu3 2004003 19 82
input:stu2 2004002 20 79
StackTraverse and printing:
stu2 2004002 20 79
stu3 2004003 19 82
stu5 2004005 19 65
StackLength is i:
i=3

the number you want output:2
stu2 2004002 20 79
stu3 2004003 19 82
the stack is not empty!
StackTraverse and printing:
stu5 2004005 19 65
Input the n:2
input:stu1 2004001 18 95
input:stu6 2004006 19 35
StackLength is i:
i=3
stu6 2004006 19 35
stu1 2004001 18 95
stu5 2004005 19 65

GetTop is:stu6 2004006 19 35
StackLength is i:
i=0

我这个是用链表做的

#include "string.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "alloc.h"
#include "graphics.h"

int get_key( )
{int c=0;
c=getch( );
if(c==0 )
{c=getch( );
return (c+256);
}return c; }

void clean_w()
{ setfillstyle(1,1);
bar(110,186,470,340);}

void clean_w3()
{ setfillstyle(1,1);
bar(95,358,477,377);}

typedef struct student
{ char *name;
char *num;
char *math,*chinese,*english;
struct student *next;
}linklist;
linklist *Creat()
{ linklist *head,*p;head=NULL;
p=malloc(sizeof(struct student));
p->next=head;head=p;
p->name="asd";
p->num="1";
p->math="97";
p->chinese="91";
p->english="92";
p=malloc(sizeof(struct student));
p->name="zxc";
p->num="2";
p->math="85";
p->chinese="97";
p->english="99";
p->next=head;head=p;
p=malloc(sizeof(struct student));
p->name="vbn";
p->num="3";
p->math="93";
p->chinese="95";
p->english="96";
p->next=head;head=p;
return head;
}

linklist *w_insert(linklist *ps)
{int i,x=270;
linklist *s;
char c;
char *b;
static char name[12],num[12],math[12],chinese[12],english[12];
s=malloc(sizeof(linklist));
clean_w3();
setcolor(10);
outtextxy(145,363,"Input Name?");
for(i=0;i<7;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;outtextxy(x+=8,363,b);
name[i]=c;}
name[i]='\0';
s->name=name;
clean_w3();x=270;
outtextxy(145,363,"Input Num?");
for(i=0;i<7;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;outtextxy(x+=8,363,b);
num[i]=c;}
num[i]='\0';
s->num=num;
clean_w3();x=270;
outtextxy(145,363,"Input Math?");
for(i=0;i<7;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;outtextxy(x+=8,363,b);
math[i]=c;}
math[i]='\0';
s->math=math;
clean_w3();x=270;
outtextxy(145,363,"Input Chinese?");
for(i=0;i<7;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;outtextxy(x+=8,363,b);
chinese[i]=c;}
chinese[i]='\0';
s->chinese=chinese;
clean_w3();x=270;
outtextxy(145,363,"Input English?");
for(i=0;i<7;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;outtextxy(x+=8,363,b);
english[i]=c;}
english[i]='\0';
s->english=english;
clean_w3();
s->next=ps;
return s;}

linklist *w_delete(linklist *ps)
{int i=1,save,x=270;
char c,*b;
char name[12];
linklist *s,*p,*pss,*r,*head;
s=malloc(sizeof(linklist));
clean_w3();
head=ps;
setcolor(10);
outtextxy(150,363,"Del Which one ?");
setcolor(10);
for(i=0;i<10;i++)
{b=malloc(2);
c=getch();
*b=c;
*(b+1)='\0';
if(c==13)break;
outtextxy(x+=8,363,b);
name[i]=c;}
name[i]='\0';
s->name=name;
pss=ps;
i=1;
while(strcmp(name,pss->name)&&(pss->next!=NULL))
{i+=1;pss=pss->next;}
pss=ps;
save=i;
for(i=1;i<save-1;i++)
{pss=pss->next;}
if(save==1){head=pss->next;clean_w3();return(head);}
r=pss->next;
pss->next=r->next;
free(r);
clean_w3();
return (head);}

linklist *w_range(linklist *ps,int n)
{char *b;
int i,j,y=210;
linklist *p,*r,*save,*rs,*pp,*oo,*ohead,*head,*s,*max,*min;
double tot,totmax;
setcolor(10);
p=ps;
rs=ps;
head=NULL;
ohead=NULL;
s=ps;
max=ps;
rs=ps;
for(i=0;i<n;i++)
{pp=malloc(sizeof(linklist));
pp->next=head;head=pp;
pp->name=rs->name;
pp->num=rs->num;
pp->math=rs->math;
pp->chinese=rs->chinese;
pp->english=rs->english;
rs=rs->next;}
for(i=0;i<n;i++)
{oo=malloc(sizeof(linklist));
oo->next=ohead;ohead=oo;
oo->name=pp->name;
oo->num=pp->num;
oo->math=pp->math;
oo->chinese=pp->chinese;
oo->english=pp->english;
pp=pp->next;}
clean_w();
outtextxy(120,y,"Name");
outtextxy(170,y,"Num");
outtextxy(230,y,"Math");
outtextxy(280,y,"Chinese");
outtextxy(350,y,"English");
outtextxy(420,y,"Aver");
setcolor(10);
for(i=1;i<n;i++)
{p=s;
max=s;
save=s;
for(j=0;j<n-i;j++)
{totmax=(atof(max->math)+atof(max->chinese)+atof(max->english))/3;
p=p->next;
tot=(atof(p->math)+atof(p->chinese)+atof(p->english))/3;
if(totmax<tot)max=p;
else min=p;}
s=s->next;
moveto(120,y+=20);
outtext(max->name);
outtextxy(170,y,max->num);
outtextxy(230,y,max->math);
outtextxy(280,y,max->chinese);
outtextxy(350,y,max->english);
tot=(atof(max->math)+atof(max->chinese)+atof(max->english))/3;
b=malloc(20);
outtextxy(420,y,gcvt(tot,5,b));
max->name=save->name;
max->num=save->num;
max->chinese=save->math;
max->math=save->chinese;
max->english=save->english;}
outtextxy(120,y+=20,min->name);
outtextxy(170,y,min->num);
outtextxy(230,y,min->math);
outtextxy(280,y,min->chinese);
outtextxy(350,y,min->english);
tot=(atof(min->math)+atof(min->chinese)+atof(min->english))/3;
b=malloc(20);
outtextxy(420,y,gcvt(tot,5,b));
return oo;}

void open_w(linklist *ps,int n)
{linklist *pps;
char *b;
int j,y=210,t;
double tot;
setcolor(10);
clean_w();
pps=ps;
outtextxy(120,y,"Name");
outtextxy(170,y,"Num");
outtextxy(230,y,"Math");
outtextxy(280,y,"Chinese");
outtextxy(350,y,"English");
outtextxy(420,y,"Aver");
setcolor(10);
t=20*(n+1);
y+=t;
for(j=1;j<=n;j++)
{moveto(120,y-=20);
outtext(pps->name);
outtextxy(170,y,pps->num);
outtextxy(230,y,pps->math);
outtextxy(280,y,pps->chinese);
outtextxy(350,y,pps->english);
tot=(atof(pps->math)+atof(pps->chinese)+atof(pps->english))/3;
b=malloc(20);
outtextxy(420,y,gcvt(tot,5,b));
pps=pps->next;}
}
int x=0,y=0,b;
void box(int,int,int,int,int);
void far line(int startx,int starty,int endx,int endy);

main()
{int D,M;
int i;
int size;
int num=3;
linklist *p;
D=0;
M=0;
i=0;
p=Creat();
initgraph(&D,&M,"");
setbkcolor(0);
box(8,8,580,480,7);
box(9,9,579,479,4);
box(10,10,578,478,7);
setfillstyle(1,1);
bar(10,11,578,477);
setfillstyle(1,1);
bar(95,59,477,78);
setcolor(46);
settextstyle(0,0,1);
outtextxy(176,68,"Student's Score Management");
setfillstyle(1,7);
bar(95,80,477,105);
line(95,178,230,178);
line(326,178,477,178);
line(95,354,240,354);
line(326,354,477,354);
outtextxy(234,175,"Report Card");
outtextxy(244,350,"Annotation");
setcolor(10);
settextstyle(SMALL_FONT,HORIZ_DIR,4);
outtextxy(389,95,"Ver.2000 FREE !");
settextstyle(0,0,1);
setcolor(0);
setfillstyle(1,1);
outtextxy(100,90,"File");
outtextxy(165,90,"Edit");
outtextxy(240,90,"Quit");
outtextxy(310,90,"About");
setcolor(4);
outtextxy(100,90,"F");
outtextxy(165,90,"E");
outtextxy(240,90,"Q");
outtextxy(310,90,"A");
do
{b=get_key ();
x=Hr();
if(b==333)
{switch(x)
{ case 0: setfillstyle(1,7);
bar(305,80,360,105);
setcolor(0);
outtextxy(310,90,"About");
setcolor(4);
outtextxy(310,90,"A");
setfillstyle(1,0);
bar(95,80,140,105);
setcolor(15);
outtextxy(100,90,"File");
break;
case 1: setfillstyle(1,7);
bar(95,80,140,105);
setcolor(0);
outtextxy(100,90,"File");
setcolor(4);
outtextxy(100,90,"F");
setfillstyle(1,0);
bar(160,80,215,105);
setcolor(15);
outtextxy(165,90,"Edit");
break;
case 2: setfillstyle(1,7);
bar(160,80,215,105);
setcolor(0);
outtextxy(165,90,"Edit");
setcolor(4);
outtextxy(165,90,"E");
setfillstyle(1,0);
bar(235,80,290,105);
setcolor(15);
outtextxy(240,90,"Quit");
break;
case 3: setfillstyle(1,7);
bar(235,80,290,105);
setcolor(0);
outtextxy(240,90,"Quit");
setcolor(4);
outtextxy(240,90,"Q");
setfillstyle(1,0);
bar(305,80,360,105);
setcolor(15);
outtextxy(310,90,"About");
break;
}
}
if (b==331)
{switch(x)
{ case 0:setfillstyle(1,7);
bar(160,80,215,105);
setcolor(0);
outtextxy(165,90,"Edit");
setcolor(4);
outtextxy(165,90,"E");
setfillstyle(1,0);
bar(95,80,140,105);
setcolor(15);
outtextxy(100,90,"File");
break;
case 1:setfillstyle(1,7);
bar(235,80,290,105);
setcolor(0);
outtextxy(240,90,"Quit");
setcolor(4);
outtextxy(240,90,"Q");
setfillstyle(1,0);
bar(160,80,215,105);
setcolor(15);
outtextxy(165,90,"Edit");
break;
case 2:setfillstyle(1,7);
bar(305,80,360,105);
setcolor(0);
outtextxy(310,90,"About");
setcolor(4);
outtextxy(310,90,"A");
setfillstyle(1,0);
bar(235,80,290,105);
setcolor(15);
outtextxy(240,90,"Quit");
break;
case 3:setfillstyle(1,7);
bar(95,80,140,105);
setcolor(0);
outtextxy(100,90,"File");
setcolor(4);
outtextxy(100,90,"F");
setfillstyle(1,0);
bar(305,80,360,105);
setcolor(15);
outtextxy(310,90,"About");
break;
}
}
if (x==0&&b==13)
{ setfillstyle(1,7);
bar(95,105,156,160);
setcolor(0);
setfillstyle(1,0);
outtextxy(100,115,"Insert");
outtextxy(100,143,"Delete");
setcolor(4);
outtextxy(100,115,"I");
outtextxy(100,143,"D");
do
{box(96,107,155,159,0);
b=get_key ();
y=ud();
if (b==336||b==328)
{setfillstyle(1,7);
bar(95,80,140,105);
setcolor(0);
outtextxy(100,90,"File");
setcolor(4);
outtextxy(100,90,"F");
switch(y)
{case 0: setfillstyle(1,7);bar(96,135,155,158);
setcolor(0);outtextxy(100,143,"Delete");
setcolor(4);outtextxy(100,143,"D");
setfillstyle(1,0);bar(96,107,155,130);
setcolor(15);outtextxy(100,115,"Insert");break;
case 1: setfillstyle(1,7);bar(96,105,155,130);
setcolor(0);outtextxy(100,115,"Insert");
setcolor(4);outtextxy(100,115,"I");
setfillstyle(1,0);bar(96,135,155,158);
setcolor(15);outtextxy(100,143,"Delete");break;
}
}
if ((y==0)&&(b==13)) {p=w_insert(p);num+=1;}
if ((y==1)&&(b==13)) {p=w_delete(p);num-=1;}
}
while (b!=27);
setfillstyle(1,1);
bar(95,106,156,160);
}

if (x==1&&b==13)
{ setfillstyle(1,7);
bar(160,105,215,157);
setcolor(0);
setfillstyle(1,0);
outtextxy(165,114,"Print");
outtextxy(165,140,"Range");
setcolor(4);
outtextxy(165,114,"P");
outtextxy(165,140,"R");
do
{ box(161,106,214,155,0);
b=get_key();
y=ud();
if (b==336||b==328)
{ setfillstyle(1,7);
bar(160,80,215,105);
setcolor(0);
outtextxy(165,90,"Edit");
setcolor(4);
outtextxy(165,90,"E");
switch(y)
{ case 0:setfillstyle(1,7);bar(161,130,214,155);
setcolor(0);outtextxy(165,140,"Range");
setcolor(4);outtextxy(165,140,"R");
setfillstyle(1,0);bar(161,106,214,130);
setcolor(15);outtextxy(165,114,"Print");
break;
case 1:setfillstyle(1,7);bar(161,106,214,130);
setcolor(0);outtextxy(165,114,"Print");
setcolor(4);outtextxy(165,114,"P");
setfillstyle(1,0);bar(161,130,214,155);
setcolor(15);outtextxy(165,140,"Range");
break;}
}
if ((y==0)&&(b==13)) open_w(p,num);
if ((y==1)&&(b==13)) p=w_range(p,num);
}
while (b!=27);
setfillstyle(1,1);
bar(160,106,215,158);
}

if (x==2&&b==13)
{char x;
setcolor(13);
outtextxy(106,363,"Thank for use See You Next Time === Press Esc");
x=getch();
if (x==27){closegraph();exit(1);}
setfillstyle(1,1);
bar(95,358,477,377);
}
if (x==3&&b==13)
{setfillstyle(1,0);
bar(95,358,477,377);
setcolor(4);
settextstyle(0,0,1);
outtextxy(100,365,"MADE IT BY 99043311 GAOYUFEI");
b=get_key ();
while (b==328);
setfillstyle(1,1);
bar(95,358,477,377);
}
}while (i==0);
closegraph();
exit(0);
}

int Hr()
{if (b==333) x=x+1;if (b==331) x=x-1;
if (x==4) x=0;if (x==-1) x=3;
return x;}
ud()
{if (b==336) y=y+1;if (b==328) y=y-1;
if (y==2) y=0;if (y==-1) y=1;
return y;}

void box(int startx,int starty,int endx,int endy,int color)
{setcolor(color);
line(startx,starty,startx,endy);
line(startx,starty,endx,starty);
line(endx,starty,endx,endy);
line(endx,endy,startx,endy);}

这是期末C语言课程设计吧..不过我以前做过了..现在不知道放哪了..呵.

一看就是同学...问我正想问的问题...

一看就是同学...问我正想问的问题...