second commit

master
Luminous 6 years ago
parent 4ac39e605c
commit f708b22a12

Binary file not shown.

@ -1,6 +1,7 @@
#include<stdio.h>
#include<string.h>
struct book
#include<stdlib.h>
struct book //
{
char name[100];
char writer[20];
@ -10,53 +11,74 @@
int place;
int number;
};
struct book a[5]={
struct book a[10]=
{
{"dujie","dujie","hunangongyedaxue",20180104,20.00,1,50},
{"lingyu","lingyu","hunangongyedaxue",20181220,38.00,2,38},
{"zhoutao","zhoutao","hunangongyedaxue",20181010,27.00,3,27},
{"liuyan","liuyan","hunangongyedaxue",20180308,1.00,4,100},
{"liubo","liubo","hunangongyedaxue",20180502,20.00,5,38},
{"lukebing","lukebing","hunangongyedaxue",20170506,6,320},
{"xiangyunfan","xiangyunfan","hunnangongyedaxue",20190321,7,50},
{"西游记","吴承恩","中国",10001010,66.00,8,900},
{"水浒传","施耐庵","中国",10201127,56.00,9,600},
{"红楼梦","曹雪芹","中国",20150325,47.00,10,200},
};
int main()
{
int i,n,m,j;
char name[100],writer[100];
flag:;
gets(name);
gets(writer);
for(i=0;i<5;i++)
printf("********************======================书店存货清单=====================******************");
printf("\n");
printf("请输入搜索内容\n");
system("color A5");
int i=0,n;
char m,name[100],writer[100];
flag:printf("书名");
scanf("%s",name);
printf("作者名");
scanf("%s",writer);
do
{
j=0;
j++;
if(strcmp(name,a[i].name)==0 && strcmp(writer,a[i].writer)==0)
{
printf("书名");
printf("书名 ");
puts(a[i].name);
printf("作者");
printf("作者 ");
puts(a[i].writer);
printf("出版社");
printf("出版社 ");
puts(a[i].pulish);
printf("日期 %d",a[i].date);
printf("价格 %.2f",a[i].price);
printf("日期 %d\n",a[i].date);
printf("价格 %.2f\n",a[i].price);
printf("位置 %d\n",a[i].place);
printf("请输入所需数量\n");
scanf("%d",&n);
if(n<=a[i].number)
printf("%f",(n*a[i].price));
{
printf("%.2f\n",(n*a[i].price));
a[i].number-=n;
}
else
printf("所需数量不在库存范围内\n");
printf("是否还想买其他书籍 是 y或Y否 双击回车键\n");
scanf("%d",&m);
printf("是否还想买其他书籍 是 y或Y按任意键返回\n");
scanf("%s",&m);
if(m=='y'||m=='Y')
j=0;
{
i=0;
goto flag;
}
if(j=5)
else
{
j=0;
printf("谢谢,再见!");
break;
}
}
i++;
if(i==10)
{
printf("你想买的书籍不存在!\n");
printf("谢谢,再见!");
}
}while(i<10);
}

Binary file not shown.

@ -0,0 +1,295 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define N 2
struct student
{
char name[10];
char no[100];
char sex;
int age;
char bnote[100];
};
void print(bool menu)//打印基本信息
{
if (!menu)
{
printf(" \t \t \t (欢迎使用本班级档案管理系统)\t\t\t\t\n");
printf("★*★*★*★*★*★*★*★*★*★ 欢迎进入我们的系统 ★*★*★*★*★*★*★*★*★*★\n\n");
printf("学生基本信息录入 ,press 1\n");
}
else
{
printf("学生基本信息显示 ,press 2\n");
printf("学生基本信息保存 ,press 3\n");
printf("学生基本信息删除 ,press 4\n");
printf("学生基本信息修改 ,press 5\n");
printf("学生基本信息查询 ,press 6\n");
}
printf("退出学生信息系统 ,press 7\n");
}
bool Check(char pas[6])//密码验证
{
FILE *fp;
char ch;
char a[7]={" "};
int i = 0;
if ((fp=fopen("D:\\1.txt","r"))==NULL)
{
printf("打开文件失败!\n");
exit(0);
}
ch=fgetc(fp);
while (ch!=EOF&&i<6)
{
a[i] = ch;
ch=fgetc(fp);
i++;
}
a[6] = '\0';
if (!strcmp(pas,a))
{
return true;
}
else
{
printf("密码错误\n");
return false;
}
fclose(fp);
}
void GetInfo(struct student *arr,int n)//学生基本信息录入
{
for (int i = 0;i<n;i++)
{
printf("输入学生的基本信息:name no sex age bnote\n");
scanf("%s %s %c %d %s",arr[i].name,arr[i].no,&arr[i].sex,&arr[i].age,arr[i].bnote);
}
}
void Display(struct student* arr,int n)//学生基本信息显示
{
printf("学生信息: Name NO Sex age Note\n");
for (int i = 0;i<n;i++)
{
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
}
}
void Save(struct student* arr,int n)//学生基本信息保存保存在c:\\student.txt
{
FILE * fp;
fp= fopen("student.txt","w+");
if (fp == NULL)
{
printf("文件不存在!\n");
exit(0);
}
fwrite(arr,sizeof(struct student)*n,n,fp);
fclose(fp);
}
void Modfiy(struct student* arr,int n)//学生基本信息修改
{
char number[100];
bool flag=false;
char pass[6];
printf("请输入密码:\n");
scanf("%s",pass);
if (Check(pass))
{
printf("修改学生信息:\n");
printf("请输入学号:\n");
scanf("%s",number);
for (int i =0;i<n;i++)
{
if (!strcmp(number,arr[i].no))
{
printf("infor: name no sex age note\n");
printf("%s %s %c %d %s\n",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
printf("please input information:\n");
scanf("%s%s%c%d%s",arr[i].name,arr[i].no,&arr[i].sex,&arr[i].age,arr[i].bnote);
Save(arr,n);
flag = true;
}
}
if (flag == false)
{
printf("该学生不存在!:\n");
}
}
}
void Delete(struct student* arr,int n)//学生基本信息删除
{
char number[100];
bool flag=false;
printf("Delete information:\n");
printf("请输入学号:\n");
scanf("%s",number);
for (int i =0;i<n;i++)
{
if (!strcmp(number,arr[i].no))
{
strcpy(arr[i].name," ");
strcpy(arr[i].no," ");
strcpy(arr[i].bnote," ");
arr[i].sex = ' ';
arr[i].age =0;
Save(arr,n);
flag = true;
}
}
if (flag == false)
{
printf("该学生不存在!:\n");
}
}
void Search(struct student* arr,int n)//学生基本信息查询
{
int temp,i;
bool flag=false;
printf("--------------通过学号查询,press 1-------------\n");
printf("---------------通过姓名查询,press 2-----------\n");
printf("---------------通过性别查询,press 3------------\n");
printf("---------------通过年龄查询,press 4------------\n");
printf("---------------退出,press 5 ------------\n");
scanf("%d",&temp);
switch (temp)
{
case 1://按照学号查询
{
char num[100];
printf("请输入学号:\n");
scanf("%s",num);
for ( i =0;i<n;i++)
{
if (!strcmp(num,arr[i].no))
{
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf("该学生不存在.\n");
}
}
break;
case 2://按照名字查询
{
char num[10];
printf("please input name:\n");
scanf("%s",num);
for ( i =0;i<n;i++)
{
if (!strcmp(num,arr[i].name))
{
printf("%-12s%-12s%-12c%-12d%-12s",arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf("该学生不存在.\n");
}
}
break;
case 3://按照性别查询
{
char ch;
printf("请输入性别:\n");
//scanf("%c",&ch);
ch = getch();
for ( i =0;i<n;i++)
{
if (ch == arr[i].sex)
{
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf("t该学生不存在.\n");
}
}
break;
case 4://按照年龄查询
{
char num_age;
printf("请输入年龄:\n");
scanf("%d",&num_age);
for ( i =0;i<n;i++)
{
if (num_age == arr[i].age)
{
printf("%12s%12s%12c%12d%12s\n",arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf("该学生不存在.\n");
}
}
break;
default:
break;
}
}
int main()
{
struct student arr[N];
char ps[6];
bool flag =false;
printf("请输入密码:\n");
scanf("%s",ps);
flag = Check(ps);
if (flag)
{
int select;
print(false);
scanf("%d",&select);
while (0<select && select <7 )
{
switch (select)
{
case 1:
GetInfo(arr,N);
print(true);
break;
case 2:
Display(arr,N);
print(true);
break;
case 3:
Save(arr,N);
print(true);
break;
case 4:
Delete(arr,N);
print(true);
break;
case 5:
Modfiy(arr,N);
print(true);
break;
case 6:
Search(arr,N);
print(true);
break;
default:
break;
}
printf("请选择:\n");
scanf("%d",&select);
}
}
}

Binary file not shown.
Loading…
Cancel
Save