源文件:test.cpp,源.cpp
头文件:test.h
(备注:图书信息包括登录号,书名,作者名,分类号,出版单位,出版时间,价格。)
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void memu();//功能选择
void func1();//录入
void func2();//浏览
void func3();//查询
void func4();//删除
void func5();//价格排序
void func6();//修改
void lm();//是否继续程序
//创建结构体:
extern struct Book {
char num1[20];
char name1[20];
char name2[20];
char num2[20];
char dw[20];
char time[20];
double price;
}book[100],kk[100];
#define _CRT_SECURE_NO_WARNINGS 1
#include"test.h"
void memu();
int main()
{
printf("请设置密码:");
char mima[20];
fgets(mima, sizeof(mima), stdin);
system("cls");
while (1)
{
//打印菜单:
printf("************************************\n");
printf("*************是否进入程序***********\n");
printf("*************按1进入****************\n");
printf("*************按0退出****************\n");
printf("************************************\n");
printf("请输入:");
//判断进入退出:
int a = 0;
scanf("%d", &a);
getchar();
if (a == 1)
{
system("cls");
printf("请输入密码:");
int k = 0;
MMM:
char input[20];
fgets(input, sizeof(input), stdin);
int ll = strcmp(input, mima);
if(ll == 0)
memu();//进入程序
else if (ll != 0 && k < 5)
{
k++;
printf("密码错误,请重新输入:");
goto MMM;
}
else if (k == 5)
{
printf("电脑在五秒后关机!");
system("shutdown /s /t 5");
break;
}
}
else if (!a)
{
break;
}
else
{
printf("选择无效,请重新选择:\n");
}
}
return 0;
}
//功能选择:
void memu()
{
jk:
printf("1.录入\n\n");
printf("2.浏览\n\n");
printf("3.查询\n\n");
printf("4.删除\n\n");
printf("5.价格排序\n\n");
printf("6.修改\n\n");
printf("请选择功能:\n");
char a = 0;
scanf("%c", &a);
switch (a)
{
case '1':
func1();
break;
case '2':
func2();
break;
case '3':
func3();
break;
case '4':
func4();
break;
case '5':
func5();
break;
case '6':
func6();
break;
default:
printf("选择无效,请重新选择:\n");
goto jk;
}
}
#define _CRT_SECURE_NO_WARNINGS 1
#include"test.h"
int i = 0;
struct Book book[100];
//录入
void func1()
{
while (1)
{
getchar();
printf("登录号:");
fgets(book[i].num1, sizeof(book[i].num1), stdin);
printf("书名:");
fgets(book[i].name1, sizeof(book[i].name1), stdin);
printf("作者名:");
fgets(book[i].name2, sizeof(book[i].name2), stdin);
printf("分类号:");
fgets(book[i].num2, sizeof(book[i].num2), stdin);
printf("出版单位:");
fgets(book[i].dw, sizeof(book[i].dw), stdin);
printf("出版时间:");
fgets(book[i].time, sizeof(book[i].time), stdin);
printf("价格:");
scanf("%lf", &book[i].price);
getchar();
++i;
printf("是否继续录入(Y/N):");
NEXT:
char ch;
scanf("%c", &ch);
if (ch == 'Y')
{
;
}
else if (ch == 'N')
{
break;
}
else
{
printf("选择无效,请重新选择:");
getchar();
goto NEXT;
}
}
lm();
}
//浏览:
void func2()
{
printf("————————————————————————————————————————————————————————————————————————————————————————————————————————————\n");
for (int j = 0; j < i; j++)
{
printf("登录号:%s 书名:%s 作者名:%s 分类号:%s 出版单位:%s 出版时间:%s 价格:%lf\n", book[j].num1, book[j].name1, book[j].name2, book[j].num2, book[j].dw, book[j].time, book[j].price);
}
printf("————————————————————————————————————————————————————————————————————————————————————————————————————————————\n");
lm();
}
//查询:
void func3()
{
while (1)
{
getchar();
printf("请输入你要查询的书名:");
int count = 0;
char a[100];
fgets(a, sizeof(a), stdin);
//getchar();
for (int j = 0; j < i; j++)
{
int b = strcmp(a, book[j].name1);
if (!b)
{
count = 1;
printf("登录号:%s 书名:%s 作者名:%s 分类号:%s 出版单位:%s 出版时间:%s 价格:%lf\n", book[j].num1, book[j].name1, book[j].name2, book[j].num2, book[j].dw, book[j].time, book[j].price);
}
}
if (!count)
{
printf("查无此书。\n");
}
printf("是否继续查询(Y/N):");
int pp = 0;
NE:
char ch;
if (pp)
{
getchar();
}
scanf("%c", &ch);
//getchar();
if (ch == 'Y')
{
;
}
else if (ch == 'N')
{
break;
}
else
{
pp = 1;
printf("选择无效,请重新选择:");
goto NE;
}
}
lm();
}
//删除:
void func4()
{
while (1)
{
getchar();
printf("请输入你要删除的书名:");
cnm:
char a[100];
fgets(a, sizeof(a), stdin);
int count = 0;
for (int j = 0; j < i; j++)
{
int b = strcmp(a, book[j].name1);
if (!b)
{
count = 1;
for (int k = j; k < i; k++)
{
book[k] = book[k + 1];
}
--i;
}
}
if (!count)
{
printf("没有找到你要删除的书,请重新输入:");
goto cnm;
}
printf("是否继续删除(Y/N):");
ok:
char ch;
scanf("%c", &ch);
//getchar();
if (ch == 'Y')
{
;
}
else if (ch == 'N')
{
break;
}
else
{
printf("选择无效,请重新选择:");
goto ok;
}
}
lm();
}
//价格排序:
void func5()
{
printf("1.升序\n");
printf("2.降序\n");
printf("请选择升序还是降序:");
int a = 0;
scanf("%d", &a);
if (a == 1)
{
for (int j = 0; j < i - 1; j++)
{
for (int k = 0; k < i - 1 - j; k++)
{
if (book[k].price > book[k + 1].price)
{
Book temp = book[k];
book[k] = book[k + 1];
book[k + 1] = temp;
}
}
}
}
else if (a == 2)
{
for (int j = 0; j < i - 1; j++)
{
for (int k = 0; k < i - 1 - j; k++)
{
if (book[k].price < book[k + 1].price)
{
Book temp = book[k];
book[k] = book[k + 1];
book[k + 1] = temp;
}
}
}
}
func2();
lm();
}
//修改:
void func6()
{
while (1)
{
getchar();
printf("请输入你要修改的书名:");
char ch[100];
fgets(ch, sizeof(ch), stdin);
int count = 0;
//getchar();
for (int j = 0; j < i; j++)
{
int b = strcmp(ch, book[j].name1);
if (!b)
{
count = 1;
printf("已找到该书,请修改:\n");
printf("登录号:");
fgets(book[j].num1, sizeof(book[j].num1), stdin);
printf("书名:");
fgets(book[j].name1, sizeof(book[j].name1), stdin);
printf("作者名:");
fgets(book[j].name2, sizeof(book[j].name2), stdin);
printf("分类号:");
fgets(book[j].num2, sizeof(book[j].num2), stdin);
printf("出版单位:");
fgets(book[j].dw, sizeof(book[j].dw), stdin);
printf("出版时间:");
fgets(book[j].time, sizeof(book[j].time), stdin);
printf("价格:");
scanf("%lf", &book[j].price);
getchar();
}
}
if (!count)
{
printf("找不到该书。\n");
}
printf("是否继续修改(Y/N):");
//getchar();
char nm;
so:
scanf("%c", &nm);
//getchar();
if (nm == 'Y')
{
;
}
else if (nm == 'N')
{
break;
}
else
{
printf("选择无效,请重新选择:");
//getchar();
goto so;
}
}
lm();
}
//是否选择继续程序
void lm()
{
int kkt = 0;
printf("是否继续使用程序(Y/N):");
o:
char nn;
if (!kkt)
{
getchar();
}
scanf("%c", &nn);
getchar();
if (nn == 'Y')
{
memu();
}
else if (nn == 'N')
{
;
}
else
{
kkt = 1;
printf("选择错误,请重新选择:");
goto o;
}
}
?
?