源码C语言 + 图形库 = 简单又好看的图书管理系统!
Posted C语言编程俱乐部
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码C语言 + 图形库 = 简单又好看的图书管理系统!相关的知识,希望对你有一定的参考价值。
直接上代码,就是这么任性!
各位小伙伴也都可以去运行一下,之前也弄了一个图书管理系统,但是今天加了个界面,需要注意的是记得安装好图形库哦!
————————————
#include <stdio.h>
#include <graphics.h>
#pragma comment(lib,"winmm.lib")
IMAGE BD,TAB;
FILE* fp;
void Image(); //背景
void Save_Data(); //保存
void Delete_Data(); //删除
int n = 0;
typedef struct book
char num[4];
char price[4];
char name[10];
BOOK;
BOOK bk[20];
void Add()
fp = fopen("./BOOK.txt", "a+");
cleardevice();
loadimage(&BD, "./2008071502334265.jpg", 640, 480);
putimage(0, 0, &BD);
char ch;
int ih;
int num;
char *ar[] = "请输入序号:", "请输入书名:", "请输入价格:" ;
setbkmode(TRANSPARENT);
settextcolor(RED);
settextstyle(50, 20, "华文彩云");
outtextxy(250, 10, "添加书籍");
setfillcolor(RGB(180, 180, 180));
fillrectangle(100, 60, 580, 450);
settextcolor(BLACK);
settextstyle(20, 0, "楷体");
outtextxy(100, 70, *ar);
int i = 0;
while ((num = getch()) != VK_RETURN)
outtextxy(100 + 10 * i, 100,num);
*(bk[n].num + i) = num;
i++;
outtextxy(100, 150, *(ar + 1));
i = 0;
while ((ch = getch()) != VK_RETURN)
outtextxy(100 + 10 * i, 180, ch);
*(bk[n].name + i) = ch;
i++;
outtextxy(100, 230, *(ar + 2));
i = 0;
while ((ih = getch()) != VK_RETURN)
outtextxy(100 + 10 * i, 260,ih);
*(bk[n].price + i) = ih;
i++;
outtextxy(250, 400, "正在保存...");
Sleep(2000);
fprintf(fp, "%s %s %s ", bk[n].num, bk[n].name, bk[n].price);
n++;
fclose(fp);
cleardevice();
void Scan()
cleardevice();
loadimage(&BD, "./2008071502334265.jpg", 640, 480);
putimage(0, 0, &BD);
setbkmode(TRANSPARENT);
settextcolor(RED);
settextstyle(50, 20, "华文彩云");
outtextxy(250, 10, "浏览书籍");
setfillcolor(RGB(180, 180, 180));
fillrectangle(100, 60, 580, 450);
for (int i = 0; i <= 7; i++)
line(100, 60 + i * 50, 580, 60 + i * 50);
fp = fopen("./BOOK.txt", "r");
settextcolor(BLACK);
settextstyle(20, 0, "楷体");
for (int i = 0; fscanf(fp, "%s %s %s ", bk[i].num, bk[i].name, bk[i].price)!=EOF; i++,n++)
outtextxy(100, 70 + i * 50, bk[i].num);
outtextxy(150, 70 + i * 50, bk[i].name);
outtextxy(200, 70 + i * 50, bk[i].price);
fclose(fp);
void Delete_Data()
int x = 0;
int b;
int arr[4];
fp = fopen("./BOOK.txt","r+");
cleardevice();
loadimage(&BD, "./2008071502334265.jpg", 640, 480);
putimage(0, 0, &BD);
setbkmode(TRANSPARENT);
settextcolor(RED);
settextstyle(50, 20, "华文彩云");
outtextxy(250, 10, "删除书籍");
setfillcolor(RGB(180, 180, 180));
fillrectangle(100, 60, 580, 450);
settextstyle(20, 0, "楷体");
outtextxy(100,70,"请输入需要删除书籍的序号:");
for (int i = 0; i <= 7; i++)
line(100, 60 + i * 50, 580, 60 + i * 50);
int a = 0;
while ((b = getch()) != VK_RETURN)
outtextxy(100 + 10 * a, 130, b);
*(arr + a) = b;
a++;
for (int i = 0; fscanf(fp, "%s %s %s ", bk[i].num, bk[i].name, bk[i].price) != EOF; i++, x++)
;
for (int i = 0; i < x; i++)
for (int a = 0; a < 4; a++)
if (bk[i].num[a] == arr[a])
for (int v = i; v <= x; v++)
for (int z = 0; z < 4;z++)
*(bk[v].num+z) = *(bk[v + 1].num+z);
for (int z = 0; z < 10; z++)
*(bk[v].name+z) = *(bk[v + 1].name+z);
for (int z = 0; z < 4; z++)
*(bk[v].price+z) = *(bk[v + 1].price+z);
break;
x--;
fclose(fp);
fopen("./BOOK.txt", "w+");
for (int i = 0; i < x; i++)
fprintf(fp, "%s %s %s ", bk[i].num, bk[i].name, bk[i].price);
fclose(fp);
void MouseMg()
MOUSEMSG m;
while (MouseHit())
m = GetMouseMsg();
switch (m.uMsg)
case WM_LBUTTONDOWN:
if (m.x >= 220 && m.y >= 100 && m.x <= 440 && m.y <= 140)
Add();
else if (m.x >= 220 && m.y >= 180 && m.x <= 440 && m.y <= 220)
Scan();
getch();
else if (m.x >= 220 && m.y >= 260 && m.x <= 440 && m.y <= 300)
Delete_Data();
getch();
else if (m.x >= 220 && m.y >= 340 && m.x <= 440 && m.y <= 380)
exit(0);
break;
void Image()
BeginBatchDraw();
loadimage(&BD, "./2008071502334265.jpg", 640, 480);
putimage(0, 0, &BD);
loadimage(&TAB,"./258PICg58PICzAJ_1024.jpg",220,40);
putimage(220, 100, &TAB);
loadimage(&TAB, "./258PICg58PICzAJ_1024.jpg", 220, 40);
putimage(220, 180, &TAB);
loadimage(&TAB, "./258PICg58PICzAJ_1024.jpg", 220, 40);
putimage(220, 260, &TAB);
loadimage(&TAB, "./258PICg58PICzAJ_1024.jpg", 220, 40);
putimage(220, 340, &TAB);
setbkmode(TRANSPARENT);
settextcolor(RED);
settextstyle(50, 20, "华文彩云");
outtextxy(200, 10, "图书管理系统");
settextcolor(BLACK);
settextstyle(17, 17, "华文新魏");
outtextxy(250, 115,"添加书籍");
settextstyle(17, 17, "华文新魏");
outtextxy(250, 195, "浏览书籍");
settextstyle(17, 17,"华文新魏");
outtextxy(250, 275, "删除书籍");
settextstyle(17, 17,"华文新魏");
outtextxy(250, 355,"退出系统");
EndBatchDraw();
int main()
PlaySound("05-夜的钢琴曲(五).wav", NULL, SND_FILENAME | SND_LOOP | SND_ASYNC);
initgraph(640, 480);
while (1)
Image();
MouseMg();
return 0;
————————————
弄了一个好看的界面,顺带也加上了音乐也感觉还不错吧,而且也比较基础的!加油~
第一个图是主要界面以及功能方面,然后就是后面两个图,两个功能一个是添加功能,一个是浏览,涉及到的知识点也并不是很多。
1、文件操作;
2、graphics.h头文件以及图形界面库函数;
3、C语言基本语法与控制结构。
其实的话,编程是很有乐趣的,前提是你得喜欢这个,但是也不要局限在知识点里面了,编程思维是很重要的。
最后,不管你是转行也好,初学也罢,进阶也可,如果你想学编程~
【值得关注】我的 C/C++编程学习交流俱乐部!【点击进入】
问题答疑,学习交流,技术探讨,还有超多编程资源大全,零基础的视频也超棒~
以上是关于源码C语言 + 图形库 = 简单又好看的图书管理系统!的主要内容,如果未能解决你的问题,请参考以下文章