用c++做图书馆管理系统Easyx并且有管理员和学生的登录代码
时间: 2023-06-17 14:05:06 浏览: 86
以下是一个简单的图书馆管理系统的示例代码,使用EasyX图形库,包括管理员和学生的登录功能。
管理员账号:admin
管理员密码:123456
学生账号:student
学生密码:123456
注意:此代码仅为示例,需要根据实际情况进行修改和完善。
```c++
#include <graphics.h>
#include <string.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#define WIDTH 600
#define HEIGHT 400
int login(); // 登录函数
void adminMenu(); // 管理员菜单函数
void studentMenu(); // 学生菜单函数
// 管理员账号密码
char adminUsername[] = "admin";
char adminPassword[] = "123456";
// 学生账号密码
char studentUsername[] = "student";
char studentPassword[] = "123456";
int main()
{
initgraph(WIDTH, HEIGHT);
// 登录验证
int userType = login();
// 根据用户类型显示不同的菜单
if (userType == 1)
{
adminMenu();
}
else if (userType == 2)
{
studentMenu();
}
closegraph();
return 0;
}
// 登录函数
int login()
{
char username[20];
char password[20];
int x = 0, y = 0;
int userType = 0; // 用户类型,1为管理员,2为学生
// 绘制登录界面
setbkcolor(RGB(245, 245, 245));
cleardevice();
settextcolor(BLACK);
settextstyle(20, 0, _T("微软雅黑"));
outtextxy(200, 50, _T("欢迎使用图书馆管理系统"));
// 用户名输入框
setfillcolor(WHITE);
setlinecolor(RGB(169, 169, 169));
fillrectangle(200, 120, 400, 150);
rectangle(200, 120, 400, 150);
settextstyle(16, 0, _T("微软雅黑"));
outtextxy(210, 125, _T("用户名:"));
// 密码输入框
setfillcolor(WHITE);
setlinecolor(RGB(169, 169, 169));
fillrectangle(200, 180, 400, 210);
rectangle(200, 180, 400, 210);
settextstyle(16, 0, _T("微软雅黑"));
outtextxy(210, 185, _T("密 码:"));
// 登录按钮
setfillcolor(RGB(70, 130, 180));
setlinecolor(RGB(70, 130, 180));
fillrectangle(250, 250, 350, 280);
rectangle(250, 250, 350, 280);
settextstyle(16, 0, _T("微软雅黑"));
settextcolor(WHITE);
outtextxy(285, 255, _T("登录"));
// 循环获取输入
while (true)
{
// 获取鼠标坐标
MOUSEMSG mouse = GetMouseMsg();
x = mouse.x;
y = mouse.y;
// 如果点击了登录按钮
if (x >= 250 && x <= 350 && y >= 250 && y <= 280 && mouse.uMsg == WM_LBUTTONDOWN)
{
// 获取输入框中的用户名和密码
GetWindowText(GetDlgItem(GetHWnd(), 1), username, 20);
GetWindowText(GetDlgItem(GetHWnd(), 2), password, 20);
// 判断用户类型
if (strcmp(username, adminUsername) == 0 && strcmp(password, adminPassword) == 0)
{
userType = 1;
break;
}
else if (strcmp(username, studentUsername) == 0 && strcmp(password, studentPassword) == 0)
{
userType = 2;
break;
}
else
{
// 显示错误提示信息
settextcolor(RED);
outtextxy(200, 300, _T("用户名或密码错误,请重新输入"));
Sleep(1000);
settextcolor(BLACK);
outtextxy(200, 300, _T("用户名或密码错误,请重新输入"));
}
}
}
return userType;
}
// 管理员菜单函数
void adminMenu()
{
// TODO: 实现管理员菜单功能
}
// 学生菜单函数
void studentMenu()
{
// TODO: 实现学生菜单功能
}
```