❶ 学生信息管理系统C++,使用Visual C++ 6.0编写。源代码参考
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedefstructlist{
structlist*next;
intnum;//学号
charname[30];//姓名
intage;//年龄
charsex;//性别
charaddr[50];//地址
charmobile[11];//号码
intdepartment;//寝室号
}user;
voidinsert(user*h);
voidedit(user*h);
voiddel(user*h);
voidS_byName(user*h);
voidS_byNum(user*h);
voiddisplay(user*h);
intmain()
{
intflag;
user*head=(user*)malloc(sizeof(user));
head->next=NULL;
while(1)
{
printf("1、添加新用户信息 ");
printf("2、修改用户信息 ");
printf("3、删除已有用户信息 ");
printf("4、根据用户名查询信息 ");
printf("5、根据学号查询信息 ");
printf("6、显示全部用户信息 "源咐兄);
printf("7、清屏 ");
printf("8、退出 ");
printf("请选择:");
scanf("%d",&flag);
if(flag==1)
雹袭insert(head);
elseif(flag==2)
edit(head);
elseif(flag==3)
del(head);
elseif(flag==4)
S_byName(head);
elseif(flag==5)
S_byNum(head);
elseif(flag==6)
display(head);
elseif(flag==7)
system("clear");
elseif(flag==8)
return0;
else
printf("输入有误,请重新选择! ");
}
}
voidinsert(user*h)
{
user*p=(user*)malloc(sizeof(user));
p->next=h->next;
h->next=p;
printf("请输入新增用户学号:"简键);
scanf("%d",&p->num);
printf("请输入新增用户名称(最多30个字):");
scanf("%s",p->name);
printf("请输入新增用户年龄:");
scanf("%d",&p->age);
printf("请输入新增用户性别:");
scanf("%c",&p->sex);
printf("请输入新增用户的家庭住址(最多50字):");
scanf("%s",p->addr);
printf("请输入新增用户的电话号码(11位数):");
scanf("%s",p->mobile);
printf("请输入新增用户寝室号:");
scanf("%d",&p->department);
printf("新用户记录成功添加:%d%s%d%c%s%s%d ",p->num,p->name,p->age,p->sex,p->addr,p->mobile,p->department);
}
voidedit(user*h)
{
intnum;
intflag=0;
user*lh=h->next;
printf("输入要修改用户的学号:");
scanf("%d",&num);
while(lh)
{
if(num==lh->num)
{
flag=1;
printf("请输入新增用户学号:");
scanf("%d",&lh->num);
printf("请输入新增用户名称(最多30个字):");
scanf("%s",lh->name);
printf("请输入新增用户年龄:");
scanf("%d",&lh->age);
printf("请输入新增用户性别:");
scanf("%c",&lh->sex);
printf("请输入新增用户的家庭住址(最多50字):");
scanf("%s",lh->addr);
printf("请输入新增用户的电话号码(11位数):");
scanf("%s",lh->mobile);
printf("请输入新增用户寝室号:");
scanf("%d",&lh->department);
printf("新用户记录成功添加:%d%s%d%c%s%s%d ",lh->num,lh->name,lh->age,lh->sex,lh->addr,lh->mobile,lh->department);
break;
}
lh=lh->next;
}
if(!flag)
printf("不存在这样的用户 ");
}
voidS_byName(user*h)
{
charname[30];
intflag=0;
user*lh=h->next;
printf("输入要查找的用户名称:");
scanf("%s",name);
while(lh)
{
if(strcmp(name,lh->name)==0)
{
flag=1;
printf("用户信息为:%d%s%d%c%s%s%d ",lh->num,lh->name,lh->age,lh->sex,lh->addr,lh->mobile,lh->department);
break;
}
lh=lh->next;
}
if(!flag)
printf("用户名不存在 ");
}
voidS_byNum(user*h)
{
intnum;
intflag=0;
user*lh=h->next;
printf("输入要查找的学号:");
scanf("%d",&num);
while(lh)
{
if(num==lh->num)
{
flag=1;
printf("用户信息:%d%s%d%c%s%s%d ",lh->num,lh->name,lh->age,lh->sex,lh->addr,lh->mobile,lh->department);
break;
}
lh=lh->next;
}
if(!flag)
printf("找不到匹配的号码 ");
}
voiddisplay(user*h)
{
user*lh=h->next;
inti=1;
while(lh)
{
printf("第%d条用户信息:%d%s%d%c%s%s%d ",i,lh->num,lh->name,lh->age,lh->sex,lh->addr,lh->mobile,lh->department);
lh=lh->next;
i++;
}
printf(" ");
}
voiddel(user*h)
{
intnum;
intflag=0;
user*lh=h;
printf("输入要删除的用户学号:");
scanf("%d",&num);
while(lh->next)
{
if(num==lh->next->num)
{
flag=1;
printf("删除用户成功:%d%s%d%c%s%s%d ",lh->num,lh->name,lh->age,lh->sex,lh->addr,lh->mobile,lh->department);
lh->next=lh->next->next;
break;
}
lh=lh->next;
}
if(!flag)
printf("用户名不存在 ");
}
❷ 急求C语言编写的图书管理系统源代码,具体要求如下
/*这有个以前用过的程序,你可以自己改改使用,但是有些功
能好像有问题,会中断运行。至于程序的缩进式格式就你自己
敲回车和退格解决吧,不然代码看起来会很乱不好看。*/
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define STACK_INIT_SIZE 10
#define OK 1
#define TRUE 1
#define FALSE 0
#define ERROR 0
struct student /*定义学生类型,用于存放借出的书籍*/
{
int carnum;
char lendbook[10];
}student[1000];
struct employ /*定义职工类型*/
{
int employnum;
char employname[15];
int employage;
char employsex[2];
char employleve[10];
long int employtage;
}employ[50];
struct book /*定义书的类型*/
{
int booknum;
char bookname[10];
char bookcreat[10];
int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/
}book[1000];
struct car /*借书卡的数据类型*/
{
int carnum;
char studentname[10];
int studentclass;
}car[100];
huanbook() /*还书函数*/
{
FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/
int i,n;
int carnum;
char lendbook[10];
printf("请你输入你的卡号\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r"); /*读取卡号记录*/
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/
{
if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/
{
n=i;
fclose(fp);
printf("请输入你要还的书的名字\n");
scanf("%s",lendbook);
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/
{
if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/
{
fclose(fp);
fp=fopen("record.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
if(strcmp(student[i].lendbook,lendbook)==0)
{
continue; /*删除还掉的书的借书记录*/
}
fwrite(&student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/
}
fclose(fp);
fclose(fp2);
fp=fopen("record.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp2)!=0;i++)
{
fwrite(&student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件的记录*/
fclose(fp2);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/
{
if(i==n)
{
book[i].turefalse=1;
fwrite(&book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp); /*将临时文件写回*/
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w"); /*清临时文件*/
fclose(fp2);
printf("还书完毕,按任意键返回\n");
getch();
return 1;
}
}
printf("你没有借这样的书,任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
return 0;
}
}
printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/
fclose(fp);
getch();
}
findbook()
{
FILE *fp;
char bookname[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的书名\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
findbook1()
{
FILE *fp;
char bookcreat[10];
int ture,i;
fp=fopen("book.txt","r");
printf("请输入你要查找的作者名\n");
scanf("%s",bookcreat);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookcreat,book[i].bookcreat)==0)
{
if(book[i].turefalse==1)
{
printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);
}
else {printf("这本书已经有人借出\n");fclose(fp);return 0;}
fclose(fp);
return FALSE;
}
}
printf("没有你要查询的书籍\n");
fclose(fp);
return FALSE;
}
lendcount()
{
FILE *fp;
int i,n=0;
fp=fopen("record.txt","r");
for(i=0;fread(&student[i],sizeof(struct student),1,fp)!=0;i++)
{
printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书借出\n",n);
printf("按任意键\n");
getch();
return n;
}
chabook()
{
char ch5;
do
{
printf("---------------欢迎进入图书查询系统!--------------\n");
printf(" 1:<按书名查找>\n");
printf(" 2:<按作者查找>\n");
printf(" 0:<返回>\n");
printf("请输入0--2,其他输入非法!\n");
scanf("%s",&ch5);
switch(ch5)
{
case '1':findbook();getch();break;
case '2':findbook1();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch5!='0');
return FALSE;
}
lendbook()
{
FILE *fp,*fp2;
int i,n;
int carnum;
printf("请你输入你的卡号\n");
scanf("%d",&carnum);
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum==carnum)
{
n=i;
fclose(fp);
printf("请输入你要借阅的书的名字\n");
scanf("%s",student[n].lendbook);
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
if(book[i].turefalse==0) {printf("对不起,此书有人借出,请借其他书\n");fclose(fp);getch();return;}
else
fclose(fp);
fp=fopen("record.txt","a+");
student[n].carnum=carnum;
fwrite(&student[n],sizeof(struct student),1,fp);
fclose(fp);
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,student[n].lendbook)==0)
{
book[i].turefalse=0;
fwrite(&book[i],sizeof(struct book),1,fp2);
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fopen("bookl.txt","w");
fclose(fp2);
printf("借书完毕,按任意键返回\n");
getch();
return;
}
}
printf("不存在这样的书,任意键返回\n");
fclose(fp);
getch();
return;
}
}
printf("你的卡号不存在,请申请新卡,按任意键返回\n");
fclose(fp);
getch();
}
carcount()
{
FILE *fp;
int i,n=0;
fp=fopen("car.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
printf("第%d张卡<卡号:%d 姓名:%s 班级:%d>\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);
n=n+1;
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
getch();
}
delcar()
{
FILE *fp,*fp2;
int i;
int carnum;
char choice;
fp=fopen("car.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的卡号\n");
printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%d",&carnum);
for(i=0;fread(&car[i],sizeof(struct car),1,fp)!=0;i++)
{
if(car[i].carnum!=carnum)
{
fwrite(&car[i],sizeof(struct car),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("car.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&car[i],sizeof(struct car),1,fp2)!=0;i++)
{
fwrite(&car[i],sizeof(struct car),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
addcar()
{
FILE *fp;
int i=0;
fp=fopen("car.txt","a+");
printf("请你输入卡号\n");
scanf("%d",&car[i].carnum);
printf("请你输入学生姓名\n");
scanf("%s",car[i].studentname);
printf("请你输入班级\n");
scanf("%d",&car[i].studentclass);
fwrite(&car[i],sizeof(struct car),1,fp);
fclose(fp);
printf("输入完毕,任意键返回\n");
getch();
}
changemploy()
{
FILE *fp,*fp2;
char employname[10],choice;
int i;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的职工的名字\n");
scanf("%s",employname);
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employ[i].employname,employname)==0)
{
printf("你所要修改的职工的资料如下,请选择你要修改的内容\n");
printf("<职工号:%d职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d>\n",employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
printf("2:修改职工名\n");
printf("3:修改职工年龄\n");
printf("4:修改职工工资\n");
printf("5:修改职工学历\n");
printf("请输入1-5:");
scanf("%s",&choice);
switch(choice)
{
case '1':
{
printf("请输入新的职工号\n");
scanf("%d",&employ[i].employnum);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '2':
{
printf("请输入新的职工姓名\n");
scanf("%s",employ[i].employname);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '3':
{
printf("请输入新的年龄\n");
scanf("%d",&employ[i].employage);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '4':
{
printf("请输入新的职工工资\n");
scanf("%d",&employ[i].employtage);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}break;
case '5':
{
printf("请输入新的职工学历\n");
scanf("%s",employ[i].employleve);
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
default:printf("没有这样的操作");break;
}
continue;
}
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(&employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
delemploy()
{
FILE *fp,*fp2;
int i;
char employname[10],choice;
fp=fopen("employ.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的职工名\n");
printf("如果你输入的职工存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",employname);
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
if(strcmp(employname,employ[i].employname)!=0)
{
fwrite(&employ[i],sizeof(struct employ),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该职工信息?删除后的所有信息将无法恢复《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("employ.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp2)!=0;i++)
{
fwrite(&employ[i],sizeof(struct employ),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return TRUE;
}
else
{
printf("按任意键返回\n");
getch();
return FALSE;
}
}
employcount()
{
FILE *fp;
int i,n=0;
fp=fopen("employ.txt","r");
for(i=0;fread(&employ[i],sizeof(struct employ),1,fp)!=0;i++)
{
printf("第%d职工的信息如下:\n<职工号:%d 职工名:%s 年龄:%d 性别:%s 学历:%s 工资:%d>\n",n+1,employ[i].employnum,employ[i].employname,employ[i].employage,employ[i].employsex,employ[i].employleve,employ[i].employtage);
n++;
}
fclose(fp);
printf("目前共有%d个职工\n",n);
printf("按任意键返回\n");
}
addemploy()
{
FILE *fp;
char choice='y';
int i=1;
fp=fopen("employ.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入职工号码\n");
scanf("%d",&employ[i].employnum);
printf("请你输入职工名\n");
scanf("%s",employ[i].employname);
printf("请输入职工年龄\n");
scanf("%d",&employ[i].employage);
printf("请你输入性别\n");
scanf("%s",employ[i].employsex);
printf("请你输入职工的学历水平\n");
scanf("%s",employ[i].employleve);
printf("请输入职工的工资\n");
scanf("%d",&employ[i].employtage);
fwrite(&employ[i],sizeof(struct employ),1,fp);
printf("是否要输入下个职工信息?\n");
scanf("%s",&choice);
}
printf("按任意键返回\n");
fclose(fp);
}
addbook()
{
FILE *fp;
int i=0;
char choice='y';
fp=fopen("book.txt","a+");
while(choice=='y'||choice=='Y')
{
printf("请你输入第%d本书的序号\n",i+1);
scanf("%d",&book[i].booknum);
printf("请你输入书名\n");
scanf("%s",book[i].bookname);
printf("请你输入书的作者\n");
scanf("%s",book[i].bookcreat);
printf("请设为1或0,1代表书还没人借,0表示书已经借出,设其他值,程序运行时无法得出正常结果\n");
printf("请你设定书的状态\n");
scanf("%d",&book[i].turefalse);
fwrite(&book[i],sizeof(struct book),1,fp);
printf("是否要输入下本书\n");
scanf("%s",&choice);
}
fclose(fp);
}
bookcount()
{
FILE *fp;
int i,n=0;
fp=fopen("book.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(book[i].booknum!=0&&strlen(book[i].bookname)!=0&&strlen(book[i].bookcreat)!=0)
{
printf("第%d本书<序号:%d 书名:%s 作者:%s 状态:%d>\n",i+1,book[i].booknum,book[i].bookname,book[i].bookcreat,book[i].turefalse);
n=n+1;
}
}
fclose(fp);
printf("目前共有%d本书\n",n);
printf("按任意键\n");
}
delbook()
{
FILE *fp,*fp2;
int i;
char bookname[10],choice;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请输入你要删除的书名\n");
printf("如果你输入的书名存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(bookname,book[i].bookname)!=0)
{
fwrite(&book[i],sizeof(struct book),1,fp2);
}
}
fclose(fp);
fclose(fp2);
printf("是否真的要删除该书籍?删除后该书籍的所有信息将无法恢复《Y/N》\n");
scanf("%s",&choice);
if(choice=='y'||choice=='Y')
{
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp);
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getch();
return;
}
else
{
printf("按任意键返回\n");
getch();
return;
}
}
changebook()
{
FILE *fp,*fp2;
char bookname[10],choice;
int i;
fp=fopen("book.txt","r");
fp2=fopen("bookl.txt","w");
printf("请你输入要修改的书籍的书字\n");
scanf("%s",bookname);
for(i=0;fread(&book[i],sizeof(struct book),1,fp)!=0;i++)
{
if(strcmp(book[i].bookname,bookname)==0)
{
printf("你所要修改的书的资料如下,请选择你要修改的内容\n");
printf("序号:〈%d〉 书名:〈%s〉 作者:〈%s〉 \n",book[i].booknum,book[i].bookname,book[i].bookcreat);
printf("1:修改书的序号\n");
printf("2:修改书名\n");
printf("3:修改作者\n");
printf("请输入1-3:");
scanf("%s",&choice);
switch(choice)
{
case '1':
{
printf("请输入新的序号\n");
scanf("%d",&book[i].booknum);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '2':
{
printf("请输入新的书名\n");
scanf("%s",book[i].bookname);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
case '3':
{
printf("请输入新的作者\n");
scanf("%s",book[i].bookcreat);
fwrite(&book[i],sizeof(struct book),1,fp2);
}break;
defaut:printf("没有这样的操作");break;
}
continue;
}
fwrite(&book[i],sizeof(struct book),1,fp2);
}
fclose(fp);
fclose(fp2);
fp=fopen("book.txt","w");
fp2=fopen("bookl.txt","r");
for(i=0;fread(&book[i],sizeof(struct book),1,fp2)!=0;i++)
{
fwrite(&book[i],sizeof(struct book),1,fp);
}
fclose(fp2);
fp2=fopen("bookl.txt","w");
fclose(fp2);
printf("按任意键返回\n");
getchar();
return;
}
main()
{
char ch1,ch2,ch3,ch4,ch5;
do
{
printf("\t\t请你选择操作类型:\n");
printf(" 1:<查阅图书>\n");
printf(" 2:<借阅图书>\n");
printf(" 3:<管理系统>\n");
printf(" 4:<还书>\n");
printf(" 0:<退出>\n");
printf("请输入0--4\n");
scanf("%s",&ch1);
switch(ch1)
{
case '1':chabook();break;
case '2':lendbook();;break;
case '3':{
do
{
printf("---------------欢迎进入管理系统!--------------\n");
printf(" 1:<增加图书>\n");
printf(" 2:<删除图书>\n");
printf(" 3:<修改图书资料>\n");
printf(" 4:<书籍统计>\n");
printf(" 5:<职工管理系统>\n");
printf(" 6:<学生管理系统>\n");
printf(" 0:<返回>\n");
printf("请输入0--6,其他输入非法!\n");
scanf("%s",&ch2);
switch(ch2)
{
case '1':addbook();
break;
case '2':delbook();break;
case '3':changebook();break;
case '4':bookcount();getch();break;
case '5':{do
{
printf("---------------欢迎进入职工管理系统!--------------\n");
printf(" 1:<增加员工>\n");
printf(" 2:<删除员工>\n");
printf(" 3:<修改员工资料>\n");
printf(" 4:<员工统计>\n");
printf(" 0:<返回>\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",&ch3);
switch(ch3)
{
case '1':addemploy();getch();break;
case '2':delemploy();break;
case '3':changemploy();break;
case '4':employcount();getch();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch3!='0');}break;
case '6':{
do
{
printf("---------------欢迎进入学生管理系统!--------------\n");
printf(" 1:<申请新卡>\n");
printf(" 2:<删除卡号>\n");
printf(" 3:<借书统计>\n");
printf(" 4:<卡号统计>\n");
printf(" 0:<返回>\n");
printf("请输入0--4,其他输入非法!\n");
scanf("%s",&ch4);
switch(ch4)
{
case '1':addcar();break;
case '2':delcar();break;
case '3':lendcount();break;
case '4':carcount();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch4!='0');}break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch2!='0');}break;
case '4':huanbook();break;
case '0':break;
default:printf("无此操作\n");getch();break;
}
}while(ch1!='0');
}
❸ 学生基本信息管理系统C++源代码
#include<iostream>
#include<iomanip>
#include<string>
usingnamespacestd;
typedefstructstudent{
unsignedm_id;
stringm_name;
unsignedm_age;
stringm_sex;
stringm_address;
stringm_contact;
stringm_dormitory;
structstudent*m_next;
}student;
classCStudent{
private:
student*head;
public:
CStudent(){
head=newstudent;
head->m_id=0;
head->m_name="noname";
head->m_next=NULL;
}
~CStudent(){
student*p=head,*q;
while(p){
q=p;
p=q->m_next;
deleteq;
}
}
studentreaddata(intmodel);//model=1:不读取学号,2:不读取姓名,其他,读取所有信息
voidentering();
boolinsert(conststudent&astu);
student*findid(unsignedid)const;
student*findname(conststring&name)const;
student*findsex(conststring&sex)const;
student*finddormitory(conststring&dormitory)const;
unsignedboys()const;
unsignedgirls()const;
unsignedheadcount()const;
booleraseid();
boolerasename();
boolmodifyid();
boolmodifyname();
voidShow()const;
voidquery()const;
voidfriendstatistics(constCStudent&aclss);
voidfrienderase(CStudent&aclss);
voidfriendmodify(CStudent&aclss);
};
stringreadstring(){
stringstr;
while(cin.get()!=' ');
cin>>str;
returnstr;
}
studentCStudent::readdata(intmodel){
studenttmp;
if(model!=1){cout<<"学号:";cin>>tmp.m_id;}
if(model!=2){cout<<"姓名:";tmp.m_name=readstring();}
cin>>tmp.m_age;
cout<<"性别:";
tmp.m_sex=readstring();
cout<<"住址:";
tmp.m_address=readstring();
cout<<"联系方式:";
tmp.m_contact=readstring();
cout<<"寝室:";
tmp.m_dormitory=readstring();
returntmp;
}
voidCStudent::entering(){
studenttmp;
cout<<"学号(0toreturn):";
cin>>tmp.m_id;
while(tmp.m_id){
if(findid(tmp.m_id)==NULL){
cout<<"姓名:";
tmp.m_name=readstring();
cout<<"年龄:";
cin>>tmp.m_age;
cout<<"性别:";
tmp.m_sex=readstring();
cout<<"住址:";
tmp.m_address=readstring();
cout<<"联系方式:";
tmp.m_contact=readstring();
cout<<"寝室:";
tmp.m_dormitory=readstring();
insert(tmp);
}
elsecout<<"重复的学号:"<<tmp.m_id<<endl;
cout<<"学号(0toreturn):";
cin>>tmp.m_id;
}
}
student*CStudent::findid(unsignedid)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_id==id)returnp;
returnNULL;
}
student*CStudent::findname(conststring&name)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_name==name)returnp;
returnNULL;
}
student*CStudent::findsex(conststring&sex)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_sex==sex)returnp;
returnNULL;
}
student*CStudent::finddormitory(conststring&dormitory)const{
student*p;
for(p=head;p->m_next;p=p->m_next)
if(p->m_next->m_dormitory==dormitory)returnp;
returnNULL;
}
boolCStudent::insert(conststudent&astu){
student*newnode,*p=head;
if(p->m_next==NULL){
p->m_next=newstudent(astu);
p->m_next->m_next=NULL;
returntrue;
}
while(p->m_next){
if(p->m_next->m_id==astu.m_id){
cout<<"重复的学号,插入失败! ";
returnfalse;
}
if(p->m_next->m_id>astu.m_id){
newnode=newstudent(astu);
newnode->m_next=p->m_next;
p->m_next=newnode;
returntrue;
}
p=p->m_next;
}
p->m_next=newstudent(astu);
p->m_next->m_next=NULL;
returntrue;
}
unsignedCStudent::boys()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next)
if(p->m_sex=="男")++cnt;
returncnt;
}
unsignedCStudent::girls()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next)
if(p->m_sex=="女")++cnt;
returncnt;
}
unsignedCStudent::headcount()const{
unsignedcnt=0;
student*p;
for(p=head->m_next;p;p=p->m_next,++cnt);
returncnt;
}
boolCStudent::eraseid(){
student*q,*p;
unsignedid;
cout<<"输入要删除的学号:";
cin>>id;
p=findid(id);
if(p==NULL){
cout<<"没有找到学号是""<<id<<""的学生,删除失败! ";
returnfalse;
}
q=p->m_next;
p->m_next=q->m_next;
deleteq;
returntrue;
}
boolCStudent::erasename(){
student*q,*p;
stringname;
cout<<"输入要删除人的姓名:";
name=readstring();
p=findname(name);
if(p==NULL){
cout<<"没有找到姓名是""<<name<<""的学生,删除失败! ";
returnfalse;
}
q=p->m_next;
p->m_next=q->m_next;
deleteq;
returntrue;
}
boolCStudent::modifyid(){
studenttmp,*p;
unsignedid;
cout<<"输入要修改的学号:";
cin>>id;
p=findid(id);
if(p==NULL){
cout<<"没有找到学号是""<<id<<""的学生,修改失败! ";
returnfalse;
}
tmp=readdata(1);
tmp.m_id=id;
*p=tmp;
returntrue;
}
boolCStudent::modifyname(){
student*p,tmp;
stringname;
cout<<"输入要修改人的姓名:";
name=readstring();
p=findname(name);
if(p==NULL){
cout<<"没有找到姓名是""<<name<<""的学生,修改失败! ";
returnfalse;
}
tmp=readdata(2);
tmp.m_name=name;
*p=tmp;
returntrue;
}
intmenu(){
intchoice;
do{
system("cls");
cout<<" **************************** ";
cout<<" *学生基本信息管理系统* ";
cout<<" *==========================* ";
cout<<" *1、录入学生信息* ";
cout<<" *2、显示学生信息* ";
cout<<" *3、查询学生信息* ";
cout<<" *4、添加学生信息* ";
cout<<" *5、统计学生信息* ";
cout<<" *6、删除学生信息* ";
cout<<" *7、修改学生信息* ";
cout<<" *0、退出管理系统* ";
cout<<" **************************** ";
cout<<" 请选择:";
cin>>choice;
}while(choice<0||choice>7);
returnchoice;
}
voidshow(student*p){
cout<<p->m_id<<""<<p->m_name<<""<<p->m_age<<"";
cout<<p->m_sex<<""<<p->m_address<<"";
cout<<p->m_contact<<""<<p->m_dormitory<<endl;
}
voidCStudent::Show()const{
student*p;
cout<<"---------------------------------------------------------- ";
for(p=head->m_next;p;p=p->m_next)show(p);
cout<<"---------------------------------------------------------- ";
system("pause");
}
voidCStudent::query()const{
intselect;
unsignedid;
stringname;
student*p;
cout<<"1、按学号查询 2、按姓名查询 0、返回 ";
cin>>select;
switch(select){
case1:cout<<"请输入学号:";cin>>id;
if(p=findid(id))show(p->m_next);
break;
case2:cout<<"请输入姓名:";name=readstring();
if(p=findname(name))show(p->m_next);
break;
case0:return;
default:cout<<"选择错误。 ";
}
system("pause");
}
voidstatistics(constCStudent&a){
unsignedtotal=a.headcount();
unsignedboys=a.boys();
unsignedgirls=a.girls();
cout<<"学生总数:"<<total<<"人。 ";
cout<<"其中,男生:"<<boys<<"名。";
cout<<"女生:"<<girls<<"名。 ";
system("pause");
}
voiderase(CStudent&a){
intselect;
unsignedid;
stringname;
student*p,*q;
cout<<"1、按学号删除 2、按姓名删除 0、返回 ";
cin>>select;
switch(select){
case1:cout<<"请输入学号:";cin>>id;
if(p=a.findid(id)){
q=p->m_next;
p->m_next=q->m_next;
deleteq;
cout<<"成功删除"<<id<<"的信息。 ";
}
break;
case2:cout<<"请输入姓名:";name=readstring();
if(p=a.findname(name)){
q=p->m_next;
p->m_next=q->m_next;
deleteq;
cout<<"成功删除"<<name<<"的信息。 ";
}
break;
case0:return;
default:cout<<"选择错误。 ";
}
system("pause");
}
voidmodify(CStudent&a){
intselect;
cout<<"1、按学号修改 2、按姓名修改 0、返回 ";
cin>>select;
switch(select){
case1:if(a.modifyid())cout<<"修改成功。 ";break;
case2:if(a.modifyname())cout<<"修改成功。 ";break;
case0:return;
default:cout<<"选择错误。 ";
}
system("pause");
}
intmain(){
CStudenta;
intan;
do{
an=menu();
switch(an){
case1:a.entering();break;
case2:a.Show();break;
case3:a.query();break;
case4:a.entering();break;
case5:statistics(a);break;
case6:erase(a);break;
case7:modify(a);break;
case0:break;
default:cout<<"选择错误。 ";break;
}
}while(an);
return0;
}