本文目录一览:
- 1、c语言编写学生信息管理系统
- 2、如何用C语言编写学生信息管理系统
- 3、C语言学生信息管理系统程序设计
- 4、c语言学生管理信息系统
- 5、用C语言设计一个学生信息查询系统程序
- 6、c语言小型图书信息管理系统
c语言编写学生信息管理系统
/*好吧,其实你可以上网看看,那么多的,你可以自己修改下*/
#include stdio.h
#include malloc.h
#include string.h
#include stdlib.h
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
char name[20];
long int num;
char sex[4];
int age;
char address[30];
double tele_num;
char aihao[20];
struct student *next;
};//定义一个结构题
int TOTAL_NUM = 0;//学生总数
struct student *head = NULL;
void welcome (); //欢迎界面
void mainmenu (); //主界面
void record (); //记录数据
void insert(struct student *stu); //插入数据
void display(struct student *stu); //显示一个学生的信息
void displayAll (); //显示所有学生的信息
void query_by_num (); //按学号查询学生信息
void readData (); //读取文件里学生的信息
void writeData (); //向文件写入学生信息
void freeAll (); //清空链表内容
void del (); //删除学生信息
void change (); //更改学生信息
void devise (struct student *p); //选择更改内容
int main (void)
{
welcome ();
//显示主菜单
mainmenu ();
return 0;
}
//显示欢迎信息
void welcome ()
{
printf ("+----------------------------------------------------+\n");
printf ("| |\n");
printf ("| 欢迎使用网络工程学院信息安全092班学生信息管理系统 |\n");
printf ("| |\n");
printf ("+----------------------------------------------------+\n");
}
//系统主菜单
void mainmenu ()
{
int choice;
choice = -1;
readData ();
printf ("\n温馨提示:为保证您的操作得到保存,请按正常顺序退出系统^_^\n");
do
{
printf ("\n\n\n");
printf ("\t\t\t--------------------------------------------\n");
printf ("\t\t\t+ 信息安全092班学生信息管理系统 |\n");
printf ("\t\t\t--------------------------------------------\n");
printf ("\t\t\t+ [1]----录入学生信息 |\n");
printf ("\t\t\t+ [2]----浏览学生信息 |\n");
printf ("\t\t\t+ [3]----查询学生信息 |\n");
printf ("\t\t\t+ [4]----删除学生信息 |\n");
printf ("\t\t\t+ [5]----修改学生信息 |\n");
printf ("\t\t\t+ [0]----退出系统 |\n");
printf ("\t\t\t+*·*·*·*·*·*·*·*·*·*·*·*·*·*·*|\n");
printf ("\t\t\t--------------------------------------------\n");
printf ("请输入您的选择:");
scanf ("%d", choice);
switch (choice)
{
case 0:
writeData ();
freeAll ();
exit (0);
case 1:
record ();
break;
case 2:
displayAll ();
break;
case 3:
query_by_num ();
break;
case 4:
del ();
break;
case 5:
change ();
break;
default:
printf ("\n无效选项!");
break;
}
}
while (choice != 0);
}
//录入学生信息
void record ()
{
struct student *p0;
p0 = (struct student *)malloc(LEN);
printf ("请输入学生的姓名:");
scanf ("%s",p0-name);
printf ("请输入学生的学号:");
scanf ("%ld",p0-num);
printf ("请输入学生的性别:");
scanf ("%s",p0-sex);
printf ("请输入学生的年龄:");
scanf ("%d",p0-age);
printf ("请输入学生的地址:");
scanf ("%s",p0-address);
printf ("请输入学生的电话:");
scanf ("%lf",p0-tele_num);
printf ("请输入学生的爱好:");
scanf ("%s",p0-aihao);
insert (p0);
printf ("该学生的信息为:\n");
printf ("-------------------------------------------------------------------------------\n");
printf ("姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n");
display (p0);
}
void insert (struct student *stu)
{
struct student *p0, *p1, *p2;
p1 = head;
p0 = stu;
if (head == NULL)
{
head = p0;
p0-next = NULL;
}
else
{
while ((p0-num p1-num)(p1-next != NULL))
{
p2 = p1;
p1 = p1-next;
}
if (p0-num = p1-num)
{
if (head == p1)
head = p0;
else
p2-next = p0;
p0-next = p1;
}
else
{
p1-next = p0;
p0-next = NULL;
}
}
TOTAL_NUM++;
}
void display (struct student *p)
{
printf ("%s\t%ld\t%d\t%s\t%s\t\t%.0f\t%s\n", p-name, p-num, p-age, p-sex, p-address, p-tele_num, p-aihao);
}
//浏览学生信息
void displayAll()
{
struct student *p;
printf("学生总数:%d\n", TOTAL_NUM);
p = head;
if (head != NULL)
{
printf("\n姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n");
printf("-------------------------------------------------------------------------------\n");
do
{
display(p);
p = p-next;
}
while(p != NULL);
}
printf ("\n");
}
//按学号查询学生信息
void query_by_num ()
{
int num;
struct student *p1;
printf("请输入学生的学号:");
scanf("%ld", num);
if(head==NULL)
{
printf("无学生记录!\n");
return;
}
p1 = head;
while (num!=p1-num p1-next!=NULL)
p1 = p1-next;
if (num == p1-num)
{
printf ("姓名\t学号\t\t年龄\t性别\t地址\t\t电话\t\t爱好\n");
printf ("-------------------------------------------------------------------------------\n");
display (p1);
}
else
printf ("没有该学生记录,请核对!");
}
//写入文件
void writeData ()
{
FILE* fp;//文件指针
struct student *p;
fp = fopen("1.txt", "w");
if (!fp)
{
printf("文件打开错误!");
return;
}
fprintf(fp,"%d\n", TOTAL_NUM);
for(p = head; p!= NULL; p= p-next)
{
fprintf(fp,"%s\t%ld\t%s\t%d\t%s\t%.0f\t%s\n", p-name, p-num, p-sex, p-age, p-address, p-tele_num, p-aihao);
}
fclose (fp);
}
void freeAll ()
{
struct student *p1, *p2;
p1 = p2=head;
while(p1)
{
p2=p1-next;
free (p1);
p1 = p2;
}
}
//读取文件
void readData ()
{
FILE* fp;//文件指针
struct student *p1, *p2;
fp = fopen("1.txt", "r");
if (!fp)
{
printf("文件打开错误!");
return;
}
fscanf(fp,"%d\n", TOTAL_NUM);
head = p1 = p2 = (struct student *)malloc(LEN);
fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%lf\t%s\n", p1-name, p1-num, p1-sex, p1-age, p1-address, p1-tele_num, p1-aihao);
while(!feof(fp))
{
p1 = (struct student *)malloc(LEN);
fscanf(fp,"%s\t%ld\t%s\t%d\t%s\t%lf\t%s\n", p1-name, p1-num, p1-sex, p1-age, p1-address, p1-tele_num, p1-aihao);
p2-next = p1;
p2 = p1;
}
p2-next = NULL;
fclose(fp);
}
//删除学生信息
void del ()
{
struct student *p1, *p2;
long int num;
if (head == NULL)
{
printf("无学生记录!\n");
return;
}
printf("请输入您要删除的学生的学号:");
scanf("%ld", num);
p1 = head;
while (num != p1-num p1-next != NULL)
{
p2 = p1;
p1 = p1-next;
}
if(num == p1-num)
{
if(p1 == head)
head = p1-next;
else p2-next = p1-next;
free(p1);
TOTAL_NUM--;
}
else
printf("没有该学生记录,请核对!\n");
}
//修改学生信息
void change ()
{
struct student *p1, *p2;
long int num;
if (head == NULL)
{
printf ("无学生记录!\n");
return;
}
printf ("请输入您要修改的学生的学号:");
scanf ("%ld", num);
p1 = head;
while (num != p1-num p1-next != NULL)
{
p2 = p1;
p1 = p1-next;
}
if(num == p1-num)
devise (p1);
else
printf("没有该学生记录,请核对!\n");
}
void devise (struct student *p)
{
int choice;
choice = -1;
do
{
printf("请选择您要修改的学生的信息内容:\n");
printf("+----------------------+\n");
printf("| 姓名 请按 1 |\n");
printf("| 学号 请按 2 |\n");
printf("| 性别 请按 3 |\n");
printf("| 年龄 请按 4 |\n");
printf("| 地址 请按 5 |\n");
printf("| 电话 请按 6 |\n");
printf("| 爱好 请按 7 |\n");
printf("| 取消 请按 0 |\n");
printf("+----------------------+\n");
printf("请输入您的选择:");
scanf("%d", choice);
switch (choice)
{
case 0:
return;
case 1:
printf("请输入新姓名:");
scanf("%s", p-name);
break;
case 2:
printf("请输入新学号:");
scanf("%d", p-num);
break;
case 3:
printf("请输入新性别:");
scanf("%s", p-sex);
break;
case 4:
printf("请输入新年龄:");
scanf("%s", p-age);
break;
case 5:
printf("请输入新地址:");
scanf("%s", p-address);
break;
case 6:
printf("请输入新电话:");
scanf("%lf", p-tele_num);
break;
case 7:
printf("请输入新爱好:");
scanf("%s", p-aihao);
break;
default:
printf("\n无效选项!");
break;
}
}
while(choice != 0);
}
如何用C语言编写学生信息管理系统
参考如下学生信息管理系统的C源代码吧。
#include stdio.h
#include string.h
/*定义学生结构体*/
struct Student
{
char ID[20];
char Name[20];
float Mark1;
float Mark2;
float Mark3;
float Average;
};
/*声明学生数组及学生数量*/
struct Student students[1000];
int num=0;
/*求平均值*/
float Avg(struct Student stu)
{
return (stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
int Student_SearchByIndex(char id[])
{
int i;
for (i=0;inum;i++)
{
if (strcmp(students[i].ID,id)==0)
{
return i;
}
}
return -1;
}
/*通过姓名返回数组下标*/
int Student_SearchByName(char name[])
{
int i;
for (i=0;inum;i++)
{
if (strcmp(students[i].Name,name)==0)
{
return i;
}
}
return -1;
}
/*显示单条学生记录*/
void Student_DisplaySingle(int index)
{
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[index].ID,students[index].Name,
students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);
}
/*插入学生信息*/
void Student_Insert()
{
while(1)
{
printf("请输入学号:");
scanf("%s",students[num].ID);
getchar();
printf("请输入姓名:");
scanf("%s",students[num].Name);
getchar();
printf("请输入成绩:");
scanf("%f",students[num].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",students[num].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",students[num].Mark3);
getchar();
students[num].Average=Avg(students[num]);
num++;
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*修改学生信息*/
void Student_Modify()
{
//float mark1,mark2,mark3;
while(1)
{
char id[20];
int index;
printf("请输入要修改的学生的学号:");
scanf("%s",id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要修改的学生信息为:\n");
Student_DisplaySingle(index);
printf("-- 请输入新值--\n");
printf("请输入学号:");
scanf("%s",students[index].ID);
getchar();
printf("请输入姓名:");
scanf("%s",students[index].Name);
getchar();
printf("请输入成绩:");
scanf("%f",students[index].Mark1);
getchar();
printf("请输入成绩:");
scanf("%f",students[index].Mark2);
getchar();
printf("请输入成绩:");
scanf("%f",students[index].Mark3);
getchar();
students[index].Average=Avg(students[index]);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*删除学生信息*/
void Student_Delete()
{
int i;
while(1)
{
char id[20];
int index;
printf("请输入要删除的学生的学号:");
scanf("%s",id);
getchar();
index=Student_SearchByIndex(id);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要删除的学生信息为:\n");
Student_DisplaySingle(index);
printf("是否真的要删除?(y/n)");
if (getchar()=='y')
{
for (i=index;inum-1;i++)
{
students[i]=students[i+1];//把后边的对象都向前移动
}
num--;
}
getchar();
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按姓名查询*/
void Student_Select()
{
while(1)
{
char name[20];
int index;
printf("请输入要查询的学生的姓名:");
scanf("%s",name);
getchar();
index=Student_SearchByName(name);
if (index==-1)
{
printf("学生不存在!\n");
}
else
{
printf("你要查询的学生信息为:\n");
Student_DisplaySingle(index);
}
printf("是否继续?(y/n)");
if (getchar()=='n')
{
break;
}
}
}
/*按平均值排序*/
void Student_SortByAverage()
{
int i,j;
struct Student tmp;
for (i=0;inum;i++)
{
for (j=1;jnum-i;j++)
{
if (students[j-1].Averagestudents[j].Average)
{
tmp=students[j-1];
students[j-1]=students[j];
students[j]=tmp;
}
}
}
}
/*显示学生信息*/
void Student_Display()
{
int i;
printf("%10s%10s%8s%8s%8s%10s\n","学号","姓名","成绩","成绩","成绩","平均成绩");
printf("-------------------------------------------------------------\n");
for (i=0;inum;i++)
{
printf("%10s%10s%8.2f%8.2f%8.2f%10.2f\n",students[i].ID,students[i].Name,
students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average);
}
}
/*将学生信息从文件读出*/
void IO_ReadInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","rb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fread(num,sizeof(int),1,fp)!=1)
{
num=-1;
}
else
{
for(i=0;inum;i++)
{
fread(students[i],sizeof(struct Student),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
void IO_WriteInfo()
{
FILE *fp;
int i;
if ((fp=fopen("Database.txt","wb"))==NULL)
{
printf("不能打开文件!\n");
return;
}
if (fwrite(num,sizeof(int),1,fp)!=1)
{
printf("写入文件错误!\n");
}
for (i=0;inum;i++)
{
if (fwrite(students[i],sizeof(struct Student),1,fp)!=1)
{
printf("写入文件错误!\n");
}
}
fclose(fp);
}
/*主程序*/
void main()
{
int choice;
IO_ReadInfo();
while(1)
{
/*主菜单*/
printf("\n------ 学生成绩管理系统------\n");
printf("1. 增加学生记录\n");
printf("2. 修改学生记录\n");
printf("3. 删除学生记录\n");
printf("4. 按姓名查询学生记录\n");
printf("5. 按平均成绩排序\n");
printf("6. 退出\n");
printf("请选择(1-6):");
scanf("%d",choice);
getchar();
switch(choice)
{
case 1:
Student_Insert();
break;
case 2:
Student_Modify();
break;
case 3:
Student_Delete();
break;
case 4:
Student_Select();
break;
case 5:
Student_SortByAverage();
Student_Display();
break;
case 6:
exit(0);
break;
}
IO_WriteInfo();
}
}
C语言学生信息管理系统程序设计
如果多找几个人,我倒是有兴趣加入一起做,毕竟这个程序还是挺大的,代码量也大,不是说一个人一两天就能完成的。
c语言学生管理信息系统
#include"stdio.h" #define SIZE 100000 #include"string.h" #include"stdlib.h" #include"conio.h" struct student {int n; int num; char name[10]; int C; int Maths; int En; float ave; }stu[SIZE]; /*录入数据*/ void finput() { FILE *fp; int i,p; fp=fopen("fstu","wb"); for(i=0;iSIZE;i+1) { printf("i=%d输入序号i(当输入i=-1时,返回),i=",i++); scanf("%d",i); if(i==-1) { fclose(fp); return; } else { printf("请输入学号,姓名,C成绩,数学成绩,英语成绩:"); scanf("%d%s%d%d%d",stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En); stu[i].ave=(stu[i].C+stu[i].Maths+stu[i].En)/3.0; stu[i].n=i+1; fwrite(stu[i],sizeof(structstudent),1,fp); } } fclose(fp); } /*输出数据*/ void flist() { FILE *fp; int i; fp=fopen("fstu","rb"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;fread(stu[i],sizeof(structstudent),1,fp)==1;i++) { printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("-----------------------------------------------------------\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); fclose(fp); } /*查找数据*/ void fsearch() { FILE *fp; int i,num; fp=fopen("fstu","rb"); rewind(fp); printf("请输入要查找的学号:"); scanf("%d",num); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 查询结果\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;i=SIZE;i++) if(stu[i].num==num) { printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("-----------------------------------------------------------\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n\n"); fclose(fp); } /*增加数据*/ void fadden() { int i,s; FILE *fp; fp=fopen("fstu","ab+"); rewind(fp); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;fread(stu[i],sizeof(structstudent),1,fp)==1;i++) { printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); s=i; for(i=s;iSIZE;i++) { printf("i=%d 输入序号i(当输入i=-1时,返回),i=",i+1); scanf("%d",i); if(i==-1) { fclose(fp); return; } else { printf("请输入学号,姓名,C成绩,数学成绩,英语成绩:"); stu[i].n=i+1; scanf("%d%s%d%d%d",stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En); stu[i].ave=(stu[i].C+stu[i].Maths+stu[i].En)/3.0; fwrite(stu[i],sizeof(structstudent),1,fp); } } fclose(fp); } /*修改数据*/ void fchange() { FILE *fp; int i,num,n; int flag=0; printf("请输入要修改学生的学号:"); scanf("%d",num); for(i=0;i=SIZE;i++) if(stu[i].num==num) { printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); printf("-----------------------------------------------------------\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); n=i; flag=1; break; } if(flag==0) { printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 输入错误!\n"); printf(" 请返回!\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); return; } printf("\n\n\n"); fp=fopen("fstu","rb+"); fseek(fp,n*sizeof(struct student),0); printf("请输入新的学号,姓名,C成绩,数学成绩,英语成绩:"); scanf("%d%s%d%d%d",stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En); stu[i].ave=(stu[i].C+stu[i].Maths+stu[i].En)/3.0; fwrite(stu[i],sizeof(structstudent),1,fp); fclose(fp); fp=fopen("fstu","rb"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;fread(stu[i],sizeof(structstudent),1,fp)==1;i++) { printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("-----------------------------------------------------------\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); fclose(fp); } /*成绩排序*/ void ftaxis() { int i,j,n; FILE *fp; struct student t; fp=fopen("fstu","rb"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;fread(stu[i],sizeof(structstudent),1,fp)==1;i++) { printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("-----------------------------------------------------------\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); fclose(fp); n=i; for(i=0;in;i++) for(j=i+1;jn;j++) if(stu[i].avestu[j].ave) { t=stu[i]; stu[i]=stu[j]; stu[j]=t; } fp=fopen("fstus","wb"); printf("\n\n\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf(" 成绩列表\n"); printf("-----------------------------------------------------------\n"); printf("序号 学号 姓名 C成绩 数学 英语 平均\n"); printf("-----------------------------------------------------------\n"); for(i=0;in;i++) { fwrite(stu[i],sizeof(structstudent),1,fp); printf("%d%8d%8s%8d%8d%8d%16.2f\n",stu[i].n,stu[i].num,stu[i].name,stu[i].C,stu[i].Maths,stu[i].En,stu[i].ave); } printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); fclose(fp); } /*主函数*/ main() { int n; for(;;) { printf("\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf("※ ※\n"); printf("※ 欢迎来到学生信息管理系统 ※\n"); printf("※ ※\n"); printf("※ 系部:通信工程 专业:通信工程 ※\n"); printf("※ 姓名: 学号: ※\n"); printf("※ 班内序号: 指导老师: ※\n"); printf("※ ※\n"); printf("※ 主菜单 ※\n"); printf("※ ※\n"); printf("※ ▲1.录入数据▲ ※\n"); printf("※ ▲2.输出数据▲ ※\n"); printf("※ ▲3.查找数据▲ ※\n"); printf("※ ▲4.增加数据▲ ※\n"); printf("※ ▲5.修改数据▲ ※\n"); printf("※ ▲6.成绩排序▲ ※\n"); printf("※ ▲7.退出系统▲ ※\n"); printf("※ ※\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※\n\n"); printf("请输入选择项(1-7):"); scanf("%d",n); printf("\n\n\n\n"); if(n0n8) { switch(n) { case 1:finput();break; case 2:flist();break; case 3:fsearch();break; case 4:fadden();break; case 5:fchange();break; case 6:ftaxis();break; case 7:printf("※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf("※ ※\n"); printf("※ 谢谢使用! ※\n"); printf("※ 再见! ※\n"); printf("※ ※\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※\n"); exit(0); } } else { printf("※※※※※※※※※※※※※※※※※※※※※※※※\n"); printf("※ ※\n"); printf("※ 输入错误! ※\n"); printf("※ 请退出! ※\n"); printf("※ ※\n"); printf("※※※※※※※※※※※※※※※※※※※※※※※※\n"); break; } } }
用C语言设计一个学生信息查询系统程序
1、首先创建一个c语言项目。然后右键头文件,创建一个Stu的头文件。
2、编写头文件的代码。再将数据结构的增删改查和结构体写入头文件。
3、在源文件中创建main源文件和Stu源文件。再main文件中写入int mian()代码。
4、然后在mian主函数中,写入while语句无限循环。再写入Init函数。
5、在Stu源文件的Init函数用printf语句,将学生管理系统输出。再创建链表的头节点head。
6、然后用switch函数对操作进行判断。再执行数据结构的增删改查功能。这样一个学生管理系统的基本框架就完成了。
c语言小型图书信息管理系统
#include stdio.h
#include stdlib.h
#include "windows.h"
#include "string.h"
#define S_MAX 50
int user_count = 0; //用户信息的总数
int book_count = 0;
char ini_path[100] = { "\0" }; //数据文件的绝对路径
char user_path[100] = { "\0" }; //用户数据文件的绝对路径
char book_path[100] = { "\0" };
int book_pos = 0; //book数组的计数
int user_pos = 0;
struct user_data
{
char name[10];
char book_name[50];
}user[S_MAX];
struct book_data
{
char no[10];
char name[50];
char author[30];
char money[10];
char in_or_out[10];
char user_name[10];
}book[S_MAX];
void read_file() //从文件读取数据
{
user_pos = 0;
int i;
for (i = 0; iS_MAX; i++)
{
memset(user[i].name, '\0', 10);
memset(user[i].book_name, '\0', 50);
memset(book[i].no, '\0', 10);
memset(book[i].name, '\0', 50);
memset(book[i].author, '\0', 30);
memset(book[i].money, '\0', 10);
memset(book[i].in_or_out, '\0', 10);
memset(book[i].user_name, '\0', 10);
}
user_count = GetPrivateProfileInt("USER", "user_count", 0, user_path);
book_count = GetPrivateProfileInt("book", "book_count", 0, book_path);
for (i = 0; iuser_count; i++)
{
char t[5] = { "\0" };
sprintf(t, "%d", i + 1);
GetPrivateProfileString(t, "name", "", user[i].name, 10, user_path);
GetPrivateProfileString(t, "book_name", "", user[i].book_name, 50, user_path);
user_pos++;
}
for (i = 0; ibook_count; i++)
{
char t[5] = { "\0" };
sprintf(t, "%d", i + 1);
GetPrivateProfileString(t, "no", "", book[i].no, 10, book_path);
GetPrivateProfileString(t, "name", "", book[i].name, 50, book_path);
GetPrivateProfileString(t, "author", "", book[i].author, 30, book_path);
GetPrivateProfileString(t, "money", "", book[i].money, 10, book_path);
GetPrivateProfileString(t, "in_or_out", "", book[i].in_or_out, 10, book_path);
GetPrivateProfileString(t, "user_name", "", book[i].user_name, 10, book_path);
book_pos++;
}
}
void write_file()
{
int i;
for (i = 0; iuser_count; i++)
{
char t[5] = { "\0" };
sprintf(t, "%d", i + 1);
WritePrivateProfileString(t, "name", NULL, user_path);
WritePrivateProfileString(t, "book_name", NULL, user_path);
WritePrivateProfileString(t, "no", NULL, book_path);
WritePrivateProfileString(t, "name", NULL, book_path);
WritePrivateProfileString(t, "author", NULL, book_path);
WritePrivateProfileString(t, "money", NULL, book_path);
WritePrivateProfileString(t, "in_or_out", NULL, book_path);
WritePrivateProfileString(t, "user_name", NULL, book_path);
}
char temp[5] = { "\0" };
int temp_count = 0;
for (i = 0; iuser_pos; i++)
{
if (strcmp(user[i].name, "") == 0)
{
continue;
}
char t[5] = { "\0" };
sprintf(t, "%d", i + 1);
WritePrivateProfileString(t, "name", user[i].name, user_path);
WritePrivateProfileString(t, "book_name", user[i].book_name, user_path);
temp_count++;
}
sprintf(temp, "%d", temp_count);
WritePrivateProfileString("USER", "user_count", temp, user_path);
temp_count = 0;
for (i = 0; ibook_pos; i++)
{
if (strcmp(book[i].no, "") == 0)
{
continue;
}
char t[5] = { "\0" };
sprintf(t, "%d", i + 1);
WritePrivateProfileString(t, "no", book[i].no, book_path);
WritePrivateProfileString(t, "name", book[i].name, book_path);
WritePrivateProfileString(t, "author", book[i].author, book_path);
WritePrivateProfileString(t, "money", book[i].money, book_path);
WritePrivateProfileString(t, "in_or_out", book[i].in_or_out, book_path);
WritePrivateProfileString(t, "user_name", book[i].user_name, book_path);
temp_count++;
}
sprintf(temp, "%d", temp_count);
WritePrivateProfileString("BOOK", "book_count", temp, book_path);
}
void search_user_name() //按借书人姓名查询
{
system("cls");
char search_key[10] = { "\0" };
printf("请输入要查询图书借书人:");
scanf("%s", search_key);
int i;
int s[10] = { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
int s_i = 0;
int find = 0;
for (i = 0; ibook_pos; i++)
{
if (strcmp(book[i].user_name, search_key) == 0)
{
find = 1;
s[s_i] = i;
s_i++;
printf("\n编 号: %s", book[i].no);
printf("\n名 称: %s", book[i].name);
printf("\n作 者: %s", book[i].author);
printf("\n金 额: %s", book[i].money);
printf("\n状 态: %s", book[i].in_or_out);
printf("\n借 书 人: %s\n", book[i].user_name);
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!");
}
else
{
for (i = 0; is_i; i++)
{
printf("\n\n第%d本书: %s", i + 1, book[i].name);
}
printf("\n\n共%d本", i);
}
fflush(stdin);
getchar();
}
void search_book_author() //按图书作者查询
{
system("cls");
char search_key[50] = { "\0" };
printf("请输入要查询图书的作者:");
scanf("%s", search_key);
int i;
int find = 0;
for (i = 0; ibook_pos; i++)
{
if (strcmp(book[i].author, search_key) == 0)
{
find = 1;
printf("\n编 号: %s", book[i].no);
printf("\n名 称: %s", book[i].name);
printf("\n作 者: %s", book[i].author);
printf("\n金 额: %s", book[i].money);
printf("\n状 态: %s", book[i].in_or_out);
printf("\n借 书 人: %s\n", book[i].user_name);
break;
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!");
}
fflush(stdin);
getchar();
}
void search_book_name() //按图书名称查询
{
system("cls");
char search_key[50] = { "\0" };
printf("请输入要查询图书的名称:");
scanf("%s", search_key);
int i;
int find = 0;
for (i = 0; ibook_pos; i++)
{
if (strcmp(book[i].name, search_key) == 0)
{
find = 1;
printf("\n编 号: %s", book[i].no);
printf("\n名 称: %s", book[i].name);
printf("\n作 者: %s", book[i].author);
printf("\n金 额: %s", book[i].money);
printf("\n状 态: %s", book[i].in_or_out);
printf("\n借 书 人: %s\n", book[i].user_name);
break;
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!");
}
fflush(stdin);
getchar();
}
void search_book_no() //按图书编号查询
{
system("cls");
char search_key[10] = { "\0" };
printf("请输入要查询图书的编号:");
scanf("%s", search_key);
int i;
int find = 0;
for (i = 0; ibook_pos; i++)
{
if (strcmp(book[i].no, search_key) == 0)
{
find = 1;
printf("\n编 号: %s", book[i].no);
printf("\n名 称: %s", book[i].name);
printf("\n作 者: %s", book[i].author);
printf("\n金 额: %s", book[i].money);
printf("\n状 态: %s", book[i].in_or_out);
printf("\n借 书 人: %s\n", book[i].user_name);
break;
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!");
}
fflush(stdin);
getchar();
}
void search_all_book() //查询所有图书
{
system("cls");
if (book_pos == 0)
{
printf("真TM穷,一本书都没有");
}
else
{
int i;
printf("共有%d本书\n", book_pos);
for (i = 0; ibook_pos; i++)
{
printf("\n编号:%s 名称:%s 作者:%s 金额:%s 状态:%s", book[i].no, book[i].name, book[i].author, book[i].money, book[i].in_or_out);
if (strcmp(book[i].in_or_out, "out") == 0)
{
printf(" 借书人:%s", book[i].user_name);
}
}
}
fflush(stdin);
getchar();
}
void search_all_user() //查询所有用户
{
system("cls");
if (user_pos == 0)
{
printf("要倒闭了?一个人都没有!");
}
else
{
int i;
printf("共有%d个用户\n", user_pos);
for (i = 0; iuser_pos; i++)
{
printf("\n用户名称: %s 借书名称: ", user[i].name);
if (strcmp(user[i].book_name, "") != 0)
{
printf("%s", user[i].book_name);
}
else
{
printf("未借书");
}
}
}
fflush(stdin);
getchar();
}
void No7() //查询
{
int f = 1;
int sel;
while (f)
{
system("cls");
printf(" *********************************\n");
printf(" * *\n");
printf(" * 图书管理系统--查询 *\n");
printf(" * *\n");
printf(" * 1.按图书编号查询 *\n");
printf(" * *\n");
printf(" * 2.按图书名称查询 *\n");
printf(" * *\n");
printf(" * 3.按作者查询 *\n");
printf(" * *\n");
printf(" * 4.按借书人姓名查询 *\n");
printf(" * *\n");
printf(" * 5.查询所有图书 *\n");
printf(" * *\n");
printf(" * 6.查询所有用户 *\n");
printf(" * *\n");
printf(" * 0.返回主菜单 *\n");
printf(" * *\n");
printf(" *********************************\n");
printf("请选择:(1,2,3,4,5,6,0) ");
fflush(stdin);
scanf("%d", sel);
getchar();
switch (sel)
{
case 1:
search_book_no();
break;
case 2:
search_book_name();
break;
case 3:
search_book_author();
break;
case 4:
search_user_name();
break;
case 5:
search_all_book();
break;
case 6:
search_all_user();
break;
case 0:
f = 0;
break;
default:
break;
}
}
}
void No6() //用户信息删除
{
system("cls");
char del_key[10] = { "\0" };
printf("请输入要删除的用户名称:");
scanf("%s", del_key);
int i, del_pos;
int find = 0;
for (i = 0; iuser_pos; i++)
{
if (strcmp(user[i].name, del_key) == 0)
{
find = 1;
printf("\n姓 名: %s", user[i].name);
if (strlen(user[i].book_name)0)
{
printf("\n所借书籍: %s", user[i].book_name);
}
del_pos = i;
break;
}
}
if (find == 0)
{
printf("\n\n未找到符合条件的信息!");
fflush(stdin);
getchar();
return;
}
while (1)
{
fflush(stdin);
printf("\n\n确认要删除该记录吗?(y/n):");
char t;
scanf("%c", t);
if (t == 'y' || t == 'Y')
{
if (strlen(user[del_pos].book_name)0)
{
printf("\n\n该用户尚有书籍未归还,不能删除!");
fflush(stdin);
getchar();
return;
}
strcpy(user[del_pos].name, "");
strcpy(user[del_pos].book_name, "");
write_file();
printf("\n\n删除成功!");
read_file();
fflush(stdin);
getchar();
break;
}
else if (t == 'N' || t == 'n')
{
printf("\n\n你选择了不删除,按任意键返回!");
fflush(stdin);
getchar();
break;
}
else
{
continue;
}
}
}
//请在回复后发余下部分