练手!图书管理系统!!大家来找茬鸭!
本帖最后由 认真学习的pea 于 2020-7-17 15:46 编辑/* 图书管理系统:
a.程序密码功能
b.用户名密码登录功能
(用户信息结构体:序号,用户名,密码)
c.登录后可进行图书的管理(修改下列图书信息)
(图书信息结构体:序号,书名,作者名,页数,定价,剩余数量...)
d.尝试添加多个用户、多本图书... */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct book {int num1;//序列号
int num2;//剩余数量
int book_page;//页数
float price;//定价
char book_name;//书名
char writer;};//作者名
struct user {char name;//用户名
char pwd;};//用户密码
struct book information={{1,10,256,99.99,"AAA","111"},
{2,12,266,16.65,"BBB","222"},
{3,20,169,19.99,"CCC","333"}};
struct user check={{"pea1","123456"},
{"pea2","1234567"},
{"pea3","12345678"}};//定义全局变量
int check_name_pwd(char a,char b)//检查用户名和密码是否匹配
{
int i;
int countx1=0;
int countx2=0;
for(i=0;i<3;i++)
{
if(strcmp(a,check.name)==0&&strcmp(b,check.pwd)==0)//检查用户名和密码是否匹配必须对应满足
{
countx1++;
countx2++;
}
}
return countx1+countx2;
}
int main(int argc,const char **argv)
{
// a.程序密码判断
if(argc != 2) //判断参数数量
{
printf("参数数量不正确,请重新运行!\n");
return -1; //结束程序
}
if(strcmp("654321", argv)) //判断密码
{
printf("密码不正确,请重新运行!\n");
return -2; //结束程序
}
float q;
int f,y;
int i=3;//初始用户数量
int t=3;//初始图书种类
int j=1;//控制密码输出次数变量
int k;//功能管理指令
int g;//子功能修改数据控制指令
int z;//图书管理功能选择指令
int x;//图书信息录入指令
char new_writer;//输入的新作者
char new_book_name;//新书名
char name1;//新用户名
char pwd1;//对应的新密码
char new_pwd;//再次输入对应的新密码
char user_;//输入的用户名
char pwd_;//输入的密码
while(1) //用户登录功能
{
printf("请输入用户名\n");
scanf("%s",user_);while(getchar()!='\n');
/* printf("%s\n",user_); */
printf("请输入密码\n");
scanf("%s",pwd_);while(getchar()!='\n');
/* printf("%s\n",pwd_); */
if(check_name_pwd(user_,pwd_)!=2)//调用函数判断用户名和密码是否匹配
{
printf("用户名或密码错误!请重新输入\n");
printf("第%d次错误\n",j);
printf("3次后退出\n");
if(j==3)//3次错误后退出程序
{
printf("第3次错误再见!\n");
return 0;
}
j++;
}
else
{
printf("欢迎进入图书管理系统\n");
break;
}
}
while(1)
{
printf("请输入指令\n");
printf("0查看所有用户\n1修改用户名\n2修改密码\n3添加用户\n4图书信息管理\n");
scanf("%d",&k);while(getchar()!='\n');
if(k==0)//查看所有用户
{
for(f=0;f<i;f++)
{
printf("%d:%s\n",f+1,check.name);
}
continue;
}
if(k==1)//修改指定用户名
{
printf("请输入指令修改对应的用户名\n");
for(f=0;f<i;f++)
{
printf("%d:%s\n",f,check.name);
}
scanf("%d",&g);while(getchar()!='\n');
printf("请输入用户名\n");
bzero(name1,sizeof(name1));
scanf("%s",name1);while(getchar()!='\n');
strncpy(check.name,name1,sizeof(name1));
continue;
}
if(k==2)//修改指定用户的密码
{
printf("请输入指令修改对应的用户名的密码\n");
for(f=0;f<i;f++)
{
printf("%d:%s\n",f,check.name);
}
scanf("%d",&g);while(getchar()!='\n');
printf("请输入新密码\n");
bzero(pwd1,sizeof(pwd1));
scanf("%s",pwd1);while(getchar()!='\n');
strncpy(check.pwd,pwd1,sizeof(pwd1));
continue;
}
if(k==3)//添加用户
{
printf("请输入用户名\n");
bzero(name1,sizeof(name1));
scanf("%s",name1);while(getchar()!='\n');
bzero(pwd1,sizeof(pwd1));
printf("请输入密码\n");
scanf("%s",pwd1);while(getchar()!='\n');
while(1)
{
printf("再次输入密码\n");
bzero(new_pwd,sizeof(new_pwd));
scanf("%s",new_pwd);while(getchar()!='\n');
if(strcmp(pwd1,new_pwd)==0)
{
i++;
break;
}
else
{
printf("密码错误重新输入\n");
continue;
}
}
bzero(check.name,sizeof(check.name));
strncpy(check.name,name1,sizeof(name1));
bzero(check.pwd,sizeof(check.pwd));
strncpy(check.pwd,pwd1,sizeof(pwd1));
printf("用户注册成功\n");
printf("用户名:%s",check.name);
printf("密码:%s",check.pwd);
}
if(k==4)//图书管理
{
while(1)
{
printf("请输入指令\n");
printf("0书的信息\n1序号\n2书名\n3作者名\n4页数\n5定价\n6剩余数量\n7添加图书\n8退出\n");
scanf("%d",&z);while(getchar()!='\n');
if(z==0)//书的信息
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
}
if(z==1) //序号
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的序号
printf("输入你要用来替换的序号\n");
scanf("%d",&y);while(getchar()!='\n');//替换的序号
information.num1=y;
continue;
}
if(z==2)//书名
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改书名\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的书名的序号
printf("输入你要用来替换的书名\n");
bzero(new_book_name,sizeof(new_book_name));
scanf("%s",new_book_name);while(getchar()!='\n');//替换的书名
strncpy(information.writer,new_book_name,sizeof(new_book_name));
continue;
}
if(z==3)//作者名
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改作者名\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的作者名的序号
printf("输入你要用来替换的作者名\n");
bzero(information.writer,sizeof(information.writer));
scanf("%s",new_writer);while(getchar()!='\n');//替换的作者名
strncpy(information.writer,new_writer,sizeof(new_writer));
continue;
}
if(z==4)//页数
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改页数\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的页数的序号
printf("输入你要用来替换的页数\n");
scanf("%d",&y);while(getchar()!='\n');//替换的页数
information.book_page=y;
continue;
}
if(z==5)//定价
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改价格\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的价格的序号
printf("输入你要用来替换的价格\n");
scanf("%f",&q);while(getchar()!='\n');//替换的价格
information.book_page=q;
continue;
}
if(z==6)//剩余数量
{
printf("序号\t书名\t作者名\t页数\t定价\t剩余数量\n");
for(f=0;f<t;f++)
{
printf("%d\t%s\t%s\t%d\t%f\t%d\n",information.num1,
information.book_name,information.writer,
information.book_page,information.price,
information.num2);
}
printf("输入对应的序号修改剩余数量\n");
scanf("%d",&g);while(getchar()!='\n');//被替换的剩余数量的序号
printf("输入剩余数量\n");
scanf("%d",&y);while(getchar()!='\n');//替换的剩余数量
information.num2=y;
continue;
}
if(z==7)//添加图书
{
while(1)
{
printf("输入序号\n");
scanf("%d",&y);while(getchar()!='\n');
information.num1=y;
printf("输入书名\n");
bzero(new_book_name,sizeof(new_book_name));
scanf("%s",new_book_name);while(getchar()!='\n');
strncpy(information.writer,new_book_name,sizeof(new_book_name));
printf("输入作者名\n");
bzero(new_book_name,sizeof(new_book_name));
scanf("%s",new_book_name);while(getchar()!='\n');
strncpy(information.book_name,new_book_name,sizeof(new_book_name));
printf("输入页数\n");
scanf("%d",&y);while(getchar()!='\n');
information.book_page=y;
printf("输入定价\n");
scanf("%f",&q);while(getchar()!='\n');
information.book_page=q;
printf("输入剩余数量\n");
scanf("%d",&y);while(getchar()!='\n');
information.num2=y;
printf("是否还要输入图书信息:按0退出1继续\n");
scanf("%d",&x);while(getchar()!='\n');
t++;
if(x==0)
{
break;
}
}
continue;
}
if(z==8)//退出图书管理
{
break;
}
}
continue;
}
}
return 0;
}
页:
[1]