#include<stdio.h>
#include<conio.h>                                      /*清屏*/
#include <stdlib.h>                                    /*显示目录*/
#include<string.h>
#define NUM 100
struct node
{
 int jcbh;      //教材编号
 char jcmc[100];  //教材名称
 char zz[100];    //作者
 char cbs[100];    //出版社
 float cbsj;    //出版时间
 float dj;    //单价
 int dgsl;   //订购数量
}stu[NUM];
struct node temp;  //临时结构体变量
int c=0;    //c是结构体数组的下标 在此为全局变量

void menu();  //定义menu菜单
void input(); //输入数据函数
void sort();  //排序
void find();  //查找(教材编号查找)
void xiugai(); //修改
void del();    //删除
void print(int i);  //输出具体信息

void main()
{
    int h,flag1,flag2,i;	
    char name[20]="xiehu",password[10]="12345";
    char person[20],password1[10];
	system("color 4F");                                                                        /*控制板颜色*/
   printf("     \n");
	printf("     \n");
	printf("     \n");
	printf("         *******************欢迎来到学校教材信息管理系统!********************\n\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
	printf("         -----------------------------------------------------------------------\n");
    printf("                                   制作成员                                     \n");
	printf("                                   组长:曾志豪                                 \n");
	printf("                                   组员:谢虎                                   \n");
	printf("                                         肖开文                                 \n");
	printf("                                         陈亭旭                                 \n");
	printf("                                         陈雨晴                                 \n");
	printf("                                         夏荫荫                                 \n");
	printf("         -----------------------------------------------------------------------\n");

	printf("                                   用户名登陆                                   \n");	
    for(h=0;h!=5;)	
	{
        printf("\t\t\t\t       用户名:");	
        gets(person);
        flag1=strcmp(person,name);
        printf("\t\t\t\t         密码:")
      	for (i=0;i<9;i++)
{
		password1[i]=getch();                /*从控制台读取一个字符,但不显示在屏幕上*/
       
		if (password1[i]==8) 
		{  i=i-2;
			printf("\b \b");
		}
    else
	{
		if(password1[i]==13) break;
        printf("*");
	}
} 
        password1[i]='\0';                   /*字符串的结束符*/
        printf("\n");
        flag2=strcmp(password,password1);
        if(flag1==0 && flag2==0)
		{
			printf("     \n");
			printf("     \n");
			printf("     \n")
          printf("\t\t\t\t   登陆成功!\n\n");
			printf("\t\t\t欢迎进入学校教材信息管理系统\n\n");
			menu();
            break;
		}
        else	
		{
            printf ("\t\t\t      用户名或密码错误!\n\n");	
			printf ("\t\t\t      请注意:您还剩%d次机会!\n\n",4-h);
            h++;
		}
	}
	if (h==5)	
		printf ("对不起,您输入的用户名或密码有误,已被强制退出。\n");
}
void menu()
{
 int select;  //选择标志(1--6间)
 system("cls");
 printf("\t\t\t学员成绩管理系统\n");
 printf("***************************\n");
 printf("*             *            \n");
 printf("*[1]输入数据               \n");
 printf("*[2]查找数据               \n");
 printf("*[3]修改数据               \n");
 printf("*[4]删除数据               \n");
 printf("*[5]数据排序               \n");
 printf("*[6]退出                   \n");
 printf("*             *            \n");
 printf("***************************\n");
 printf("请输入你的选项(1--6):");
 scanf("%d",&select);
 switch(select)  //判断选择
 {
  case 1:input();break;
  case 2:find();break;
  case 3:xiugai();break;
  case 4:del();break;
  case 5:sort();break;
  case 6:exit(0);break;
 }
}
  
void sort()
{
	char r3[8],r4[4],r5[6];
int	i,j,r6,r2;
float r1,r7;
system("cls");
printf("\n\n\n");
printf("\t\t\t************************\n");
printf("\n");
printf("\t\t\t欢迎进入教材单价排序系统\n");
printf("\n");
printf("\t\t\t************************\n");
printf("\n\n\n");
printf("\t\t排序结果如下(单价由低到高):\n");
for(j=0;j<c;j++)
{
	for(i=0;i<(c)-j;i++)
if(stu[i].dj>stu[i+1].dj)
{
	r1=stu[i].dj; stu[i].dj=stu[i+1].dj; stu[i+1].dj=r1;
r6=stu[i].dgsl; stu[i].dgsl=stu[i+1].dgsl; stu[i+1].dgsl=r6;
r2=stu[i].jcbh; stu[i].jcbh=stu[i+1].jcbh; stu[i+1].jcbh=r2;
r7=stu[i].cbsj; stu[i].cbsj=stu[i+1].cbsj; stu[i+1].cbsj=r7;
strcpy(r3,stu[i].cbs); strcpy(stu[i].cbs,stu[i+1].cbs); strcpy(stu[i+1].cbs,r3);
strcpy(r4,stu[i].zz); strcpy(stu[i].zz,stu[i+1].zz); strcpy(stu[i+1].zz,r4);
strcpy(r5,stu[i].jcmc); strcpy(stu[i].jcmc,stu[i+1].jcmc); strcpy(stu[i+1].jcmc,r5);
}
}
for(i=0;i<=c;i++)
{   printf("单价:%.1f\n",stu[i].dj);
	printf("作者:%s\n",stu[i].zz);
	printf("出版社:%s\n",stu[i].cbs);
	printf("教材编号:%d\n",stu[i].jcbh);
    printf("教材名称:%s\n",stu[i].jcmc);
    printf("出版时间:%.1f\n",stu[i].cbsj);
	printf("订购数量:%d\n",stu[i].dgsl);
	printf("\n");}
printf("\n按回车键返回菜单……\n");
getchar();
getchar();
 menu();  
}

void input()  
{
 int i;  //循环变量 
 system("cls");  //清屏
 printf("请输入教材的数量:");
 scanf("%d",&c);  //下标C保存多本教材
 c--;
 if(c>NUM)
 {
  printf("最多输入%d本\n",NUM);
  printf("按任意键返回");
  getchar();
  getchar();
  input();  //递归调用
 }
 
 for(i=0;i<=c;i++)  //NUM是一个常量
 {
  printf("\n第%d本教材的编号:",i+1);
  scanf("%d",&stu[i].jcbh);
  printf("第%d本教材的名称:",i+1);
  scanf("%s",stu[i].jcmc);
  printf("第%d本教材的作者:",i+1);
  scanf("%s",stu[i].zz);
  printf("第%d本教材的出版社:",i+1);
  scanf("%s",&stu[i].cbs);
  printf("第%d本教材的出版时间:",i+1);
  scanf("%f",&stu[i].cbsj);
  printf("第%d本教材的单价:",i+1);
  scanf("%f",&stu[i].dj);
  printf("第%d本教材的数量:",i+1);
  scanf("%d",&stu[i].dgsl);
 }
 printf("\n按回车键返回主菜单……\n");
 getchar();
 getchar();
 menu();  
}
void find()
{int jcbh1; //教材的编号
 int flag;  //选择标志
 int i;  //循环变量 
	 system("cls");  //清屏
	printf("\t\t\t****************^*^**************\n");
    printf("\n");
	printf("\t\t\t﹌﹌﹌﹌﹌⊙·⊙﹌﹌⊙·⊙﹌﹌﹌﹌﹌\n");
    printf("\n");
	printf("\t\t\t¤     欢迎来到信息查找系统        ¤\n");
	printf("\t\t\t    ●         ◇◇           ● \n");
	printf("\t\t\t  ╱▇╲     来找我吧!     ╱▇╲\n");
    printf("\n");
	printf("\t\t\t************************************\n");
	printf("\n\n\n"); 
  printf("请输入你要查找的教材的编号:");
  scanf("%d",&jcbh1);
  for(i=0;i<=c;i++)
  {if(stu[i].jcbh==jcbh1)
   
   {
    printf("\n==**==**==** %s的教材信息 **==**==**==**==**\n",stu[i].jcmc);
  printf("编号:   %d\n",stu[i].jcbh);
  printf("作者:   %s\n",stu[i].zz);
  printf("出版社:   %s\n",stu[i].cbs);
  printf("出版时间:  %.1f\n",stu[i].cbsj);
  printf("单价:  %.1f\n",stu[i].dj);
  printf("数量:  %d\n",stu[i].dgsl);
   }
  } 
 printf("\n按回车键返回主菜单……\n");
 getchar();
 getchar();
 menu();  
}
void xiugai()                                          /*修改数据函数*/ 
{ 
  int i,x; 
  system("cls");  //清屏
   printf("输入要修改的教材编号:"); 
  fflush(stdin); 
 scanf("%d",&x);
  for(i=0;i<NUM;i++) 
  { 
     if(stu[i].jcbh==x) 
        { 
        system("cls"); 
        printf("\n\t\t输入修改后教材信息\n"); 
        printf("\n输入教材的编号:"); 
        fflush(stdin); 
        scanf("%u",&stu[i].jcbh); 
        printf("\n输入教材的名称:"); 
        fflush(stdin); 
        gets(stu[i].jcmc); 
        printf("\n输入教材的作者:"); 
        fflush(stdin); 
        scanf("%f",&stu[i].zz); 
        printf("\n输入教材的出版社:"); 
        fflush(stdin); 
        scanf("%f",&stu[i].cbs); 
        printf("\n输入教材的出版时间:"); 
        fflush(stdin); 
        scanf("%f",&stu[i].cbsj); 
printf("\n输入教材的单价:"); 
        fflush(stdin); 
        scanf("%f",&stu[i].dj); 
printf("\n输入教材的数量:"); 
        fflush(stdin); 
        scanf("%f",&stu[i].dgsl); 
        printf("\n\n"); 
        menu(); 
        break; 
       } 
  } 
  printf("\n按回车键返回主菜单……\n");
 getchar();
 getchar();
 menu();
}
void del()//删除的功能
{  int n,j;
   system("cls");  //清屏
   printf("\t\t\t\t    Welcome!\t\t\t\t\t\t\t\n");
    printf("\t\t\t\t▽▽△△△▽▽\t\t\t\t\t\t\n");
    printf("\t\t\t\t☆信息删除系统☆\t\t\t\t\t\n");
	printf("\t\t\t\t▽▽△△△▽▽\t\t\t\t\t\t\n");
    printf("\n\n");
	printf("\t\t\t\t\t\t\t\t\t\t\n");
    printf("\t\t      ○      ○      ○      ○      ○    \n");
    printf("\t\t    ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  \n"); 
    printf("\t\t  ○  请  ○  认  ○  真  ○  思  ○  考  ○\n");
    printf("\t\t    ●  ●  ●  ●  ●  ●  ●  ●  ●  ●  \n");
	printf("\t\t      ○      ○      ○      ○      ○    \n");
 printf("请输入教材编号:\n");
 scanf("%d",&n);
 
 for( j=0;j<=c;j++)
 {
  if (stu[j].jcbh==n)
  {
   int i=j;
      while(i++!=c)
   stu[i-1]=stu[i];
  }
 }
 --c;
 menu();//返回主菜单
}