c语言学生证管理系统(有待改进)

此程序目前还有很多问题

如:

//空链表时不能插入数据

//不能插入到第一个链表
//无文件操作

//删除不掉第一个链表

具体的有待改进。。。

#include <conio.h>/*清屏函数*/
#include <stdio.h>
#include <malloc.h>
#include <cstdlib>
#include <string.h>
#define LEN sizeof(struct student)
int n;
struct student
{
int num;
char name[20];
char xingbie[10];
int old;
char minzu[10];
char address[20];
char zhuanye[20];
char ruday[20];
char faday[20];
struct student *next;
};                          //
struct student *creat();          //创建函数
void prin(struct student *head);
struct student *del(struct student *head);
struct student *insert(struct student *head,struct student *stud);
struct student *xiugai(struct student *head);
struct student *find(struct student *head);
void dayin(struct student *head);




struct student *creat()
{
system("cls");
struct student *head,*p1,*p2;
head=NULL;
n=0;
p1=p2=(struct student *)malloc(LEN);          //动态创建内存
printf("\t\t输入学号    :");
scanf("%d",&p1->num);
printf("\n\t\t输入姓名    :");
scanf("%s",&p1->name);
printf("\n\t\t输入性别    :");
scanf("%s",&p1->xingbie);
printf("\n\t\t输入年龄    :");
scanf("%d",&p1->old);
printf("\n\t\t输入民族    :");
scanf("%s",&p1->minzu);
printf("\n\t\t输入地址    :");
scanf("%s",&p1->address);
printf("\n\t\t输入专业    :");
scanf("%s",&p1->zhuanye);
printf("\n\t\t输入进校日期:");
scanf("%s",&p1->ruday);
printf("\n\t\t输入填发日期:");
scanf("%s",&p1->faday);
printf("\n\t\t********************\n");
while(p1->num!=0)
{
n=n+1;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
printf("\n\t\t输入学号    :");
   scanf("%d",&p1->num);
   printf("\n\t\t输入姓名    :");
    scanf("%s",&p1->name);
   printf("\n\t\t输入性别    :");
    scanf("%s",&p1->xingbie);
    printf("\n\t\t输入年龄    :");
    scanf("%d",&p1->old);
    printf("\n\t\t输入民族    :");
    scanf("%s",&p1->minzu);
    printf("\n\t\t输入地址    :");
    scanf("%s",&p1->address);
    printf("\n\t\t输入专业    :");
    scanf("%s",&p1->zhuanye);
    printf("\n\t\t输入进校日期:");
    scanf("%s",&p1->ruday);
    printf("\n\t\t输入填发日期:");
    scanf("%s",&p1->faday);
printf("\n\t\t********************\n");


}
p2->next=NULL;
fflush(stdin);
getch();
return head;




}






void prin(struct student *head)
{
struct student *p;
p=head;
if(head!=NULL)
{
printf("\n\t\t输入数据如下:\n\n");
printf("\t--------------------------------------------------------------------\n");
printf("\t学号---姓名---性别---年龄---民族---地址---专业---进校日期---填发日期\n");
do
{

printf("\t%d%7s%7s%7d%7s%7s%7s%7s%11s",p->num,p->name,p->xingbie,p->old,p->minzu,p->address,p->zhuanye,p->ruday,p->faday);
printf("\n\t--------------------------------------------------------------------\n");
p=p->next;
}while(p!=NULL);
}
else
printf("\n\t\t无学生信息存在!");
fflush(stdin);
getch();
}






struct student *del(struct student *head)
{
struct student *p1,*p2;
struct student *newhead;
int num;
newhead=head;
p1=head;
system("cls");
if(head==NULL)
{
printf("\n\t\t空链表!没有信息删除!\n");
printf("\n\t\t");
getch();
return 0;
}

printf("\t\t输入要删除的学号:");
   scanf("%d",&num);
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
newhead=p1->next;


else
p2->next=p1->next;


printf("\n\t\t删除:%d\n",num);
n=n-1;
}
else
printf("\n\t\t%d没有找到!\n",num);


getch();
return newhead;


}




struct student *insert(struct student *head,struct student *stud)
{
struct student *p0,*p1,*p2;
p1=head;
p0=stud;
system("cls");
p0=(struct student *)malloc(LEN);
printf("\t\t输入要插入的数据:\n\n");
   printf("\t\t输入学号    :");
   scanf("%d",&p0->num);
    printf("\n\t\t输入姓名    :");
    scanf("%s",&p0->name);
   printf("\n\t\t输入性别    :");
    scanf("%s",&p0->xingbie);
    printf("\n\t\t输入年龄    :");
    scanf("%d",&p0->old);
    printf("\n\t\t输入民族    :");
    scanf("%s",&p0->minzu);
    printf("\n\t\t输入地址    :");
    scanf("%s",&p0->address);
    printf("\n\t\t输入专业    :");
    scanf("%s",&p0->zhuanye);
    printf("\n\t\t输入进校日期:");
    scanf("%s",&p0->ruday);
    printf("\n\t\t输入填发日期:");
    scanf("%s",&p0->faday);
   


if(head!=NULL)
{ while((p0->num>p1->num)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->num<=p1->num)
{
if(head==p1)
{
head=p0;
p0->next=p1;
}
else
p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;
p0->next=NULL;
}
n=n+1;
fflush(stdin);
getch();

}
else
{
head=p0;
p0->next=NULL;
n=n+1;
getch();

}
return head;
}







struct student *xiugai(struct student *head)
{
system("cls");
struct student *p,*p1;
int i,num;
p=head;
if(head!=NULL)
{
printf("\t\t输入要修改学生的学号:");
scanf("%d",&num);
while(num!=p->num&&p->next!=NULL)
{
p1=p;
p=p->next;

}
if(num==p->num)
{
printf("\t\t选择要修改的内容\n");
printf("\n\t\t1.学号\n");
printf("\n\t\t2.姓名\n");
printf("\n\t\t3.性别\n");
printf("\n\t\t4.年龄\n");
printf("\n\t\t5.民族\n");
printf("\n\t\t6.地址\n");
printf("\n\t\t7.专业\n");
printf("\n\t\t8.进校日期\n");
printf("\n\t\t9.填发日期\n");
printf("\n\t\t");
scanf("%d",&i);
switch(i)
{
case 1:
printf("\n\t\t输入修改后的学号:");
scanf("%d",&p->num);break;
case 2:
printf("\n\t\t输入修改后的姓名:");
scanf("%s",&p->name);break;
case 3:
printf("\n\t\t输入修改后的性别:");
scanf("%s",&p->xingbie);break;
case 4:
printf("\n\t\t输入修改后的年龄:");
scanf("%d",&p->old);break;
case 5:
printf("\n\t\t输入修改后的民族:");
scanf("%s",&p->minzu);break;
case 6:
printf("\n\t\t输入修改后的地址:");
scanf("%s",&p->address);break;
case 7:
printf("\n\t\t输入修改后的专业:");
scanf("%s",&p->zhuanye);break;
case 8:
printf("\n\t\t输入修改后的进校日期:");
scanf("%s",&p->ruday);break;
case 9:
printf("\n\t\t输入修改后的填发日期:");
scanf("%s",&p->faday);break;


}
}
else
{
printf("\n\t\t学号输入错误,没有改学生存在!");
}
}
else
{
printf("\n\t\t空链表,不能修改任何信息!\n");
getch();
return 0;
}
fflush(stdin);
getch();
return head;


}







struct student *find(struct student *head)
{
struct student *p1,*p2;
int i,num;
char name[10];
if(head!=NULL)
{
printf("\t\t选择查找方式:\n");
printf("\n\t\t1.学号\n");
printf("\n\t\t2.姓名\n");
printf("\n\t\t");
scanf("%d",&i);
switch(i)
{
case 1:
printf("\n\t\t输入要查找的学号:");
scanf("%d",&num);
p1=head;
        while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(num==p1->num)
{
printf("\n\t学号---姓名---性别---年龄---民族---地址---专业---进校日期---填发日期\n");
        printf("\t%d%7s%7s%7d%7s%7s%7s%7s%11s",p1->num,p1->name,p1->xingbie,p1->old,p1->minzu,p1->address,p1->zhuanye,p1->ruday,p1->faday);
printf("\n\t--------------------------------------------------------------------\n");
}
else
printf("\n\t\t学号输入错误,没有该学号学生存在!\n");
fflush(stdin);
getch();
break;
case 2:
printf("\n\t\t输入要查找的姓名:");
scanf("%s",&name);
p1=head;
while((strcmp(name,p1->name)!=0)&&p1->next!=0)
{
p2=p1;
p1=p1->next;
}
if(strcmp(name,p1->name)==0)
{
printf("\n\t学号---姓名---性别---年龄---民族---地址---专业---进校日期---填发日期\n");
        printf("\t%d%7s%7s%7d%7s%7s%7s%7s%11s",p1->num,p1->name,p1->xingbie,p1->old,p1->minzu,p1->address,p1->zhuanye,p1->ruday,p1->faday);
printf("\n\t--------------------------------------------------------------------\n");
}
else
printf("\n\t\t没有该同学存在!\n");
fflush(stdin);
getch();
break;
}
}
else 
{
printf("\n\t\t空链表,没有学生信息!\n");
getch();
return 0;
}
return head;


}









/*void dayin(struct student *head)
{
system("cls");
FILE *fp;
//int i;
struct student *p;
p=head;
if((fp=fopen("project.txt","w+"))=NULL)
{
printf("\n\t\t打开文件失败!\n");
exit(0);
}
//printf("*****************^$^%$##\n");
do
{
fputc(p->num,fp);
fputs(p->name,fp);
fputs(p->xingbie,fp);
fputc(p->old,fp);
fputs(p->minzu,fp);
fputs(p->address,fp);
fputs(p->zhuanye,fp);
fputs(p->ruday,fp);
fputs(p->faday,fp);
p=p->next;


}while(p->next!=NULL);
fclose(fp);
printf("\n\t\t打印信息完毕!");
getch();
}*/






void main()

system("color 1d");
struct student *p;
struct student stu;
int chose;
//p=creat();
    //readfile(p);
    do
{
system("cls");
printf("\t\t选择需要的操作:");
printf("\n\n\t\t1.创建信息");
printf("\n\n\t\t2.插入信息");
printf("\n\n\t\t3.修改信息");
printf("\n\n\t\t4.查找信息");
printf("\n\n\t\t5.查看信息");
printf("\n\n\t\t6.删除信息");
//printf("\n\n\t\t7.打印信息");
printf("\n\n\t\t0.退出");
printf("\n\n\t\t");
scanf("%d",&chose);
switch(chose)
{
case 1:
p=creat();break;
case 2:
insert(p,&stu);break;
case 3:
xiugai(p);break;
case 4:
find(p);break;
case 5:
prin(p);break;
case 6:
del(p);break;
//case 7:
// dayin(p);break;


}


}while(chose!=0);
printf("\n\t\t");





设计一个学生证的管理程序。该程序应该具有以下功能: (l)录入某位学生的学生证信息(学生证应该包含的位息请参看自己的学生证); (2)给定学号,显示某位学生的学生证信息; (3)给定某个班级的班号,按学号由小到大显示该班所有学生的学生证信息; (4)给定某个班级的班号,按姓名的字典顺序显示该班所有学生的学生证信息; (5)给定某位学生的学号,修该学生的学生证信息; (6)给定某位学生的学号,删除该学生的学生证信息。 题目要求: (1)按照分析、设计、编码、调试和测试的软件开发过程完成这个应用程序,即在程序中加入异常处理,检查用户输入数据的有效性,以保证程序的健壮性; (2)学生证应该包含的信息请参看自己的学生证; (3)为各项操作功能设计一个菜单,应用程序运行后,先显示这个菜单,然后用户通过菜单选项选则所需进行的操作项目,菜单要界面友好、清晰; (4)将所有学生证信息存储在一个文件中,并实现文件的读写操作,即将输入的数据以文件的形式存盘,将原来已经存盘的文件读入内存,进行管理; (5)应保证测试用例测试程序的各种边缘情况。 输入要求: 应用程序运行后,在屏幕上显示一个菜单。用户可以根据需要,选定相应的操作项目。进入每个操作后,根据应用程序的提示信息,从键盘输入相应的信息。 输出要求: (1)应用程序运行后,在屏幕上显示一个菜单。 (2)要求用户输入数据时,要给出清晰、明确的提示信息,包括输入的数据内容、格式及结束方式等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值