图书管理系统——皇帝的新衣

 

代码如下

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "string.h"
#include "windows.h"
#include "stdlib.h"
int i,j,bh,bh1;
 struct books{
    char name[20];
    double price;
    char introduce[100];
 }book1[3],book2[3],book3[3];
 void Init(){
         struct books book1[3]={
        {"红楼梦",25.05,"家境变迁的爱情故事"},
        {"白鹿原",15.25,"几个时代青年的世界"},
        {"西游记",25.26,"鬼怪魔神的奇幻之游"},
                        };
    struct books book2[3]={
        {"百年孤独",25.05,"rt"},
        {"我的大学",15.25,"托尔斯泰的传世之作"},
        {"傲慢与偏见",25.26,"rtgr"},
        };
    struct books book3[3]={
        {"诗经",25.05,"rtgh"},
        {"论语",15.25,"sry"},
        {"中庸",25.26,"er"},
        };
    printf("请输入功能编号\n");
    scanf("%d",&bh1);
    printf("  书名\t\t单价\t\t介绍\n");
    switch(bh1){
        case 1:    
            for(i=0;i<3;i++){
        printf("  %-12s%-15.2f%s\n",book1[i].name,book1[i].price,book1[i].introduce);
        
        }
        break;
        case 2:    
            for(i=0;i<3;i++){
        printf("  %-12s%-15.2f%s\n",book2[i].name,book2[i].price,book2[i].introduce);
        
        }
        break;
        case 3:    
            for(i=0;i<3;i++){
        printf("  %-12s%-15.2f%s\n",book3[i].name,book3[i].price,book3[i].introduce);
        
        }
        break;
        default :printf("您输入的编号有误!\n");break;
        
        }
       system("pause");
     }
void character(){
    char arr[50][50]={
         "==============",
         "=1.中文书籍  =",
         "=2.英文书籍  =",
         "=3.古文学    =",
         "==============",
    };
    for(i=0;i<5;i++){
        for(j=0;j<15;j++){
            printf("%c",arr[i][j]);
        }
        printf("\n");
    }
    Init();
    }
void menu();
void Openbook(){
    int booknum;
        FILE *fp;
        char aw[1500];  
    char c;  
    int n = 1;
   
    char crr[50][50]={
         "==============",
         "=1.百年孤独  =",
         "=2.白鹿原    =",
         "=3.古文学    =",
         "=4.教学资料  =",
         "==============",
    };
    
    for(i=0;i<6;i++){
        for(j=0;j<15;j++){
            printf("%c",crr[i][j]);
        }
        printf("\n");
    }
    printf("Choose number to open book\n");
    scanf("%d",&booknum);


    //EOF是文件结尾的标志,此处是判断是否到文件尾
    switch(booknum){
        case 1:
           system("cls");
                fp = fopen("test2.txt","r");
        if(fp == NULL)  
       {  
        printf("文件打开失败!\n");  
        exit(1);   
        }  
           while((fgets(aw,500,fp)) != NULL)  
         {  
             printf("%s",aw);  
            
         }  
        printf("\n"); 
        system("pause");         
        fclose(fp);   
        break;
        case 2:
         system("cls");
                fp = fopen("test3.txt","r");
        if(fp == NULL)  
       {  
        printf("文件打开失败!\n");  
        exit(1);   
        }  
           while((c = fgetc(fp)) != EOF)  
         {  
             printf("%c",c);  
            n++;  
         }  
        printf("\n"); 
        system("pause");         
        fclose(fp); 
        break;  
        case 3:
         system("cls");
                fp = fopen("test4.txt","r");
         if(fp == NULL)  
         {  
         printf("文件打开失败!\n");  
         exit(1);   
          }  
           while((c = fgetc(fp)) != EOF)  
         {  
             printf("%c",c);  
            n++;  
         }  
        printf("\n"); 
        system("pause");         
        fclose(fp);   
        break;
        case 4:
        system("cls");
        fp=fopen("test5.txt","r");
        if(fp==NULL){
            printf("文件打开失败!\n");  
         exit(1);   
        }
         while(( fgets(aw,1500,fp)) != NULL)  
         {  
             printf("%s",aw); 
         }  
        printf("\n"); 
        system("pause");         
        fclose(fp);   
     break;
        default:
        printf("请输入正确的数字\n");
    }
    
    }
void main(){
   system("color 61");
   for(;;){
       
    menu();
       printf("请输入功能编号\n");
    scanf("%d",&bh);
    switch(bh){
        case 1:character();break;
        case 2:Openbook();break;
        case 0:exit(0);
        default:printf("请输入正确编号\n");
        }
   }//for
}
void menu(){    
    char brr[50][50]={
         "==============",
         "=1.图书馆藏书=",
         "=2.打开书籍  =",
         "=0.退出      =",
         "==============",
    };
    
    system("title 图书系统");
    system ( "mode con cols=40 lines=28" );
    printf("\n\n");
    for(i=0;i<5;i++){
        for(j=0;j<15;j++){
            printf("%c",brr[i][j]);
        }
        printf("\n");
        }

    }

需要在同阶目录下存在文件test2.txt,test3.txt,test4.txt

可以自己新建,并往里面写内容。也可以下载这几个文件

https://files-cdn.cnblogs.com/files/TimVerion/%E5%9B%BE%E4%B9%A6%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F%E6%96%87%E4%BB%B6.rar

text2.txt:

text3.txt:

text4.txt:

皇帝的新衣游戏代码

/* Note:Your choice is C IDE */
#include "stdio.h"
#include "time.h"
#include "string.h"
#include "windows.h"
#include "mmsystem.h"
#pragma comment(lib,"Winmm.lib")
#define MAX 6
char errorname[20];
int i,j,k;//j代表天数
void menu(){
    printf("\t\t\t1.添加您的新妃子\n");
    printf("\t\t\t2.翻牌子\n");
    printf("\t\t\t3.打入冷宫\n");
    printf("\t\t\t4.召见妃子\n");
}


void main()
{
    int n=5,bh,bb;
    int bz;//牌子
    int rs=0;//不满的人数
    char temname[20];
    char name[MAX][20]={"西施","甄嬛","王昭君","杨玉环","郭德纲"};
    char title[MAX][20]={"贵人","妃子","正宫","娘娘","皇后"};
    int level[MAX]={1,0,1,1,1,-1};
    int love[MAX]={100,100,100,100,100};
    
    char  artile[6][50]={
        "啊!大海呀都是水",
        "红鲤鱼绿鲤鱼与驴",
        "这真是红旗招展,人山人海,锣鼓齐鸣",
        "寻寻觅觅冷冷清清凄凄惨惨戚戚",
        "对面的姑娘真是美,两个眼睛一张嘴",
        "智商二百五",
    };
    time_t t;
    struct tm *p;
    t=time(NULL);
    p=gmtime(&t);
    /*printf("time为%02d:%02d:%02d\n",p->tm_hour+8,p->tm_min,p->tm_sec);*/
        srand((unsigned)time(NULL));
        PlaySound(TEXT("sounds\\5287.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
    printf("\t\t\t请新登基皇帝留下名字:\n");
    fflush(stdin);
    gets(errorname);
    printf("%d年%02d月%02d日\n",1900+p->tm_year,p->tm_mon+1,p->tm_mday);
    printf("%s登基\n",errorname);
    for(j=0;j<10;j++){
    menu();
    printf("%-12s位置\t心情\n","姓名");
    for(i=0;i){
        printf("%-12s%s\t\t%d\n",name[i],title[level[i]],love[i]);
        }
    printf("第%d天\n欢迎%s活到晴朗的一天\n",j+1,errorname);                                  
    printf("请选择接下来的打算: \n");
    scanf("%d",&bh);
    switch(bh){
        case 1:
        PlaySound(TEXT("sounds\\5126.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        printf("闻说%s皇帝游历江南湖畔带来一位女子\n",errorname);
        printf("请写出新娘娘的芳名:");
        scanf("%s",&name[n]);
        level[n]=0;
        love[n]=100;
        for(i=0;i){
            love[i]-=10;//其他妃子扣10好感
            }
        n++;
        system("pause");
        system("cls");
        break;
        case 2:

        PlaySound(TEXT("sounds\\欢乐斗地主.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        printf("请您开始抽取您的幸运牌子\n");
        bb=rand()%9;
        bz=rand()%n;
        for(i=0;i<10;i++){
        printf("%d",bb);        
        system("cls");
        Sleep(100);
        }
        printf("%d",bz);
        for(i=0;i){
            if(i!=bz)
            love[i]-=20;//其他妃子扣20好感
            }
        printf("%s很荣幸和您相处\n",name[bz]);
        love[bz]+=20;
        level[bz]+=1;
        system("pause");
        system("cls");
        break;
        case 3:
        PlaySound(TEXT("sounds\\丧礼.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
        printf("%s请您决定要把谁给打入冷宫了:",errorname);
        fflush(stdin);
        gets(temname);
        for(i=0;i){
            if(strcmp(temname,name[i])==0){
                for(k=i;k){
                strcpy(name[k],name[k+1]);
                love[k]=love[k+1];
                level[k]=level[k+1];}
                break;
            }            
        }
        for(i=0;i1;i++){
            love[i]+=10;
        }
        n--;
        system("pause");
        system("cls");
        break;
        case 4:
        printf("%s您准备和那位妃子去游玩:",errorname);
        fflush(stdin);
        gets(temname);
        bz=rand()%6;
        printf("%s兴致大起吟诗道:%s\n",errorname,artile[bz]);
        for(i=0;i){
            if(strcmp(temname,name[i])==0){
               love[i]+=20;
                break;
            }            
        }
        for(i=0;i1;i++){
            love[i]-=20;
        }
        system("pause");
        system("cls");
        break;
        default :printf("输入错误");
    }
    for(i=0;i){
        if(love[i]<=60){
            rs++;
            }
    }
    if(rs>=3){
        printf("妃子们确定起义将皇帝杀死\n");
        printf("%s共执政%d天",errorname,i+1);
        break;
        }
    }
}

需要在同阶目录下:

在sounds下存在这几个文件,自己随便找文件也行

图书管理系统——皇帝的新衣_第1张图片

 

转载于:https://www.cnblogs.com/TimVerion/p/11193957.html

你可能感兴趣的:(图书管理系统——皇帝的新衣)