c语言创建学生成绩数据库说明书,利用C语言版本的数据库制作一个学生成绩管理系统...

#include

#include

#include

#define TRUE 1

#define FLASE -1

typedef struct student

{

char name[10];

char sex[10];

char Class[10];

float mark;

int age;

struct student *prev;

struct student *next;

}node;/*定义结构体*/

char strbuf[40];

char strmark[10];

FILE *fp;/*定义只想文件的指针*/

//将链表中的学生信息导入到文本当中

void save(node *h)

{

char strbuf[40];//定义一个字符串来储存链表学生信息中的姓名,性别,班级。

char strmark[10];//用来储存链表中的学生的年龄,成绩。

if((fp=fopen("D:\\student.txt","wb"))==NULL)//判断是否打开文本。!!!!注意你要储存信息的文本最好添加在除C盘之外的地方

{

printf("不能打开该文件");

}

node *p=h;

while(p)//通过判断p是否为空

{

strcpy(strbuf,p->name);//将链表中的名字赋值给字符串。

strcat(strbuf,".");

strcat(strbuf,p->sex );

strcat(strbuf,".");

strcat(strbuf,p->Class );

strcat(strbuf,".");

itoa(p->age ,strmark,10);//将int类型装换为字符串类型

strcat(strbuf,strmark);

strcat(strbuf,".");

itoa(p->mark ,strmark,10);

strcat(strbuf,strmark);

fwrite(strbuf,1,strlen(strbuf),fp);//写入到文本当中

fwrite("\r\n",1,strlen("\r\n"),fp);//换行

p=p->next ;

}

fclose(fp); //一定要关闭文本否则将保存失败

printf("保存成功\n");

}

//打印链表中的信息

void print(node *h)

{

if (h == NULL)

{

return ;

}

else

{

node *p = h;

while (p)

{

printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:%.0f\n", p->name, p->age,p->sex,p->Class ,p->mark );

p = p->next;

}

printf("\n");

}

}

//用来将文本中的信息重新插入到链表当中

node *creat3(node *h,char strstuname[10],char sex[10],char class1[10] ,int age,float mark)

{

node *p = (node *)malloc(sizeof(node));

memset(p, 0, sizeof(node));

strcpy(p->name ,strstuname);

strcpy(p->sex ,sex);

strcpy(p->Class ,class1);

p->age=age;

p->mark =mark;

p->next = NULL;

p->prev = NULL;

if (h == NULL)

{

h = p;

}

else

{

p->next = h;

h->prev = p;

h = p;

}

/*printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:%f\n", p->name, p->age,p->sex,p->Class ,p->mark );*/

/* return h; */

}

//将文本中的信息添加到链表当中

node* load(node *h)

{

char strbuf[50]={0};

char strstuname[10]={0};

char strstusex[10]={0};//为了来储存文本中的信息。

char strstuage[10]={0};

char strstuclass[10]={0};

char strstumark[10]={0};

if((fp=fopen("D:\\student.txt","rb"))==NULL)

{

printf("不能打开该文件");

exit(0);

}

node *p=h;

int ncount=0;

int j=0;

while(NULL !=fgets(strbuf,50,fp))

{

int i=0;

ncount=0;

j=0;

for(i=0;strbuf[i]!='\r';i++)

{

if(0==ncount)

{

strstuname[i]=strbuf[i];

if(strbuf[i]=='.')

{

strstuname[i]='\0';

ncount++;

}

}

else if(1==ncount)

{

strstusex[j]=strbuf[i];

j++;

if(strbuf[i]=='.')

{

strstusex[j-1]='\0';

ncount++;

j=0;

}

}

else if(2==ncount)

{

strstuclass[j]=strbuf[i];

j++;

if(strbuf[i]=='.')

{

strstuclass[j-1]='\0';

ncount++;

j=0;

}

}

else if(3==ncount)

{

strstuage[j]=strbuf[i];

j++;

if(strbuf[i]=='.')

{

strstuage[j-1]='\0';

ncount++;

j=0;

}

}

else

{

strstumark[j]=strbuf[i];

j++;

}

}

h=creat3(h,strstuname,strstusex,strstuclass,atoi(strstuage),atoi(strstumark));//调用前面的插入函数来插入到链表当中

}

printf("导入成功\n");

fclose(fp);//!!!!一定要记得关闭文本

return h;

}

//从头部插入

node  *creat(node *h)

{

while (1)

{

node *p = (node *)malloc(sizeof(node));

if (p == NULL)

return h;

memset(p, 0, sizeof(node));

printf("请输入学生的年龄:");

int age;

scanf("%d",&age );

if (age==0)

{

break;

}

p->age =age;

printf("请输入学生的名字:");

scanf("%s",&p->name);

printf("请输入学生的性别:");

scanf("%s",p->sex );

printf("请输入学生的班级:");

scanf("%s",&p->Class );

printf("请输入学生的成绩");

scanf("%f",&p->mark ) ;

p->next = NULL;

p->prev = NULL;

if (h == NULL)

{

h = p;

}

else

{

p->next = h;

h->prev = p;

h = p;

}

}

return h;

}

//从尾部插入

node *creat1(node *h)

{

while (1)

{

node *p = (node *)malloc(sizeof(node));

if (p == NULL)

return h;

memset(p, 0, sizeof(node));

printf("请输入学生的年龄:");

int age;

scanf("%d",&age );

if (age==0)

{

break;

}

p->age =age;

printf("请输入学生的名字:");

scanf("%s",&p->name);

printf("请输入学生的性别:");

scanf("%s",p->sex );

printf("请输入学生的班级:");

scanf("%s",&p->Class );

printf("请输入学生的成绩");

scanf("%f",&p->mark ) ;

p->next = NULL;

p->prev = NULL;

if (h == NULL)

{

h = p;

}

else

{

node *q = h;

while (q->next)

{

q = q->next;

}

q->next = p;

p->prev = q;

}

}

return h;

}

node* sort(node *h)

{

int temp;

if(h==NULL)

{

return h;

}

else if(h->next==NULL)

{

return h;

}

else

{

node *p=h;

node *i;

node *q;

/*node *p;*/

while(p)

{

for(i=p;i->next!=NULL;i=i->next)

{

q=i->next ;

if(i->ageage )

{

temp=q->age ;

q->age =i->age ;

i->age=temp;

}

}

p=p->next;

}

return h;

}

}

//从尾部打印

void Lastprint(node *h)

{

if(h==NULL)

{

return ;

}

else

{

node *p=h;

while(p)

{

printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:%.0f\n", p->name, p->age,p->sex,p->Class ,p->mark );

p=p->prev ;

}

printf("\n");

}

}

//通过成绩查询

void select1(node *h,float mark)

{

if(h==NULL)

{

return ;

}

else

{

node *p=h;

while(p)

{

if(p->mark==mark)

{

printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:.0%f\n", p->name, p->age,p->sex,p->Class ,p->mark );

}

p=p->next ;

}

printf("\n");

}

}

//通过姓名修改

void update1(node *h,char name[10])

{

float mark;

if(h==NULL)

{

return ;

}

else

{

node *p=h;

while(p)

{

if(strcmp(p->name ,name)==0)

{

printf("请输入要修改的成绩");

scanf("%f",&mark);

p->mark =mark;

printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:%.0f\n", p->name, p->age,p->sex,p->Class ,p->mark );

}

p=p->next;

}

}

}

node *Sort(node *h)

{

float temp;

if(h==NULL)

{

return h;

}

else if(h->next==NULL)

{

return h;

}

else

{

node *p=h;

node *i;

node *q;

/*node *p;*/

while(p)

{

for(i=p;i->next!=NULL;i=i->next)

{

q=i->next ;

if(i->markmark )

{

temp=q->mark ;

q->mark  =i->mark;

i->mark=temp;

}

}

p=p->next;

}

}

}

//排序之后的成绩打印

void SortMark(node *h)

{

if (h == NULL)

{

return ;

}

else

{

node *p = h;

while (p)

{

printf("%f\n",p->mark );

p = p->next;

}

printf("\n");

}

}

//通过姓名查找

void select2(node *h,char name[10])

{

if(h==NULL)

{

return ;

}

else

{

node *p=h;

while(p)

{

if(strcmp(p->name ,name)==0)

{

printf("姓名:%s    年龄:%d   性别:%s   班级:%s   成绩:%.0f\n", p->name, p->age,p->sex,p->Class ,p->mark );

}

p=p->next ;

}

printf("\n");

printf("查找无此人");

}

}

//销毁链表

void destroy(node *h)

{

if (h == NULL)

{

return;

}

else

{

node *p=h;

while (p)

{

free(p);

p = p->next;

}

}

}

//通过姓名来删除链表中的信息

int delete1(node **h, char name[10])

{

if (*h == NULL)

{

return -1 ;

}

else

{

node *p = *h;

while (p)

{

if (strcmp(p->name,name)==0)

{

if (p ==*h)

{

*h =(*h)->next;

(*h)->prev = NULL;

free(p);

}

else if (p->next == NULL)

{

p->prev->next = NULL;

free(p);

}

else

{

p->prev->next = p->next;

p->next->prev = p->prev;

free(p);

}

}

p = p->next;

}

return -1;

}

}

int main(int argc , char* argv[])

{

node *h=NULL;

int temp;

int da=1;

printf("                       **************************  开始 学生成绩管理系统   ***********************\n");

printf("                       ************************** (1) 从链表的头部插入   ***********************\n");

printf("                       ************************** (2) 从链表的尾部插入   ***********************\n");

printf("                       ************************** (3) 打印链表中的信息   ***********************\n");

printf("                       ************************** (4) 通过姓名查找学生的信息并打印**********************\n");

printf("                       ************************** (5) 通过姓名修改学生的成绩:***********************\n");

printf("                       ************************** (6) 通过姓名删除学生的信息:***********************\n");

printf("                       ************************** (7) 成绩从大到小的排序:***********************\n");

printf("                       ************************** (8)       写入到文本       :***********************\n");

printf("                       ************************** (9)       从文本中读出       :***********************\n");

printf("                       ************************** (10)       退出程序       :***********************\n");

while(da)

{

printf("请输入数字来选择功能\n");

scanf("%d",&temp);

switch(temp)

{

case 1: h=creat(h);

break;

case 2: creat1(h);

break;

case 3:  Print(h);

break;

case 4: char name [10];

printf("请输入要查询的名字");

scanf("%s",&name);

select2(h,name);

break;

case 5:

printf("请输入要修改的学生成绩的名字");

char name1 [10];

scanf("%s",&name1);

update1(h,name1);

Print(h);

break ;

case 6:

printf("请输入要删除学生的信息");

char name2[10];

scanf("%s", &name2);

delete1(&h, name2);

Print(h);

break ;

case 7:

Sort(h);

SortMark(h);

break;

case 8:

save(h);

break;

case 9:

h=load(h);

break;

case 10:

da=0;

break;

}

}

}

1189708-20171208132641890-1187762351.png

1189708-20171208132725421-1331340998.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值