@
前言
这是我大一用c写的一个小项目《网吧的管理系统的实现》,在这里提供大家学习和使用
主要知识:
- 链表的创建与使用
- 文件的操作
- 各种c语句的运用
tips:使用时,记得在c文件中添加一个 Account library.txt 文档
一、设计任务
如今现在的网络非常的发达,各种软件、游戏、媒体等对网络的要求也非常的高,所以为了满足消费者,网吧必须改建,建立一个以网路技术、计算机技术与现代信息技术为支撑的娱乐、管理平台、将现行以游戏网为主的活动发展到多功能娱乐这个平台上来,既以大幅度提高网吧的竞争和盈利能力,建设成为一流的高档网吧,以吸引高端消费群体打下强由刘的基础。这就是我们要达到的目标。由此分析一个合理、简单、规范的网吧管理系统符合目前需求形势。
二、程序设计与实现
本程序面向两类用户即vip和管理员,有两个入口,vip可以注册然后进行登录,管理员有固定的账号和密码(隐秘的入口)。Vip有上下机和修改密码功能
管理员拥有会员信息的查看和充值等陆续开发的功能。如下图所示
1.数据描述
(1)会员信息存储
typedef struct
{
char vipAccount[MAX]; //会员账号(身份证号)
char vipPassword[MIN]; //会员密码
char vipPhoneNum[11]; //会员绑定手机号
int vipAmount; //会员剩余金额
} VIP;
(2)时间信息存储
typedef struct clock
{
int hour; 小时
int minute; 分钟
int second; 秒
}Clock;
(3)全局变量设计
定义全局变量MAX、 MIN 限制账号、密码长度
2.功能模块设计
(1)函数名:void signUp()
函数功能:登录账号
输 入:
输 出:
算法描述:
(2)函数名:void enroll()
函数功能:注册
输 入:
输 出:
算法描述:
(3)函数名:void getPassBack()
函数功能:密码找回
输 入:
输 出:
算法描述:
(4)函数名:void GetPassword()
函数功能:密码回显‘*’
输 入:密码
输 出:无
算法描述:
(5)函数名:void vipMenu()
函数功能:会员界面
输 入:
输 出:
算法描述:
(6)函数名:void maMenu()
函数功能:管理员界面
输 入:
输 出:
算法描述:
(7)函数名:void getOn()
函数功能:用户上机
输 入:
输 出:
算法描述
(8)函数名:void changePass()
函数功能:密码修改
输 入:
输 出:
算法描述:
(9)函数名:void preservation(double money)
函数功能:更新用户信息
输 入:已用金额
输 出:
算法描述:
(10)函数名:void manage()
函数功能:管理员登录
输 入:
输 出:
算法描述:
(11)函数名:void inforSheet()
函数功能:会员信息查看
输 入:无
输 出:无
算法描述:
(12)函数名:void recharge()
函数功能:充值
输 入:无
输 出:无
算法描述:
(13)函数名:void Begin()
函数功能:过场动画
输 入:无
输 出:无
算法描述:
(14)函数名:void menu()
函数功能:
输 入:
输 出:
算法描述:
三、UI设计效果
1.启动界面:一个简单的进场动画。
2.开始界面:几个功能展示。
3.用户界面:有会员的基本信息。
4.信息打印界面:
5.项目到目前为止存在的不足及改正措施:
(1)界面显示不够美观。
(2)数据打印不够整齐。
(3)没能完成在计时的同时进行游戏(在里面添加c语言小游戏)功能实现(大二的我现在也解决不了,大一本心是想把用c写的一些小游戏,用上去)
四、代码实现(记得添加一个Account library.txt 文本文档)
tips:管理员系统进入方法:在用户菜单下输入“管理员登录”。账号默认为(账号:admin 密码:1111)
验证码查看方法:打开c文件--->打开vercode.txt
用户注册:账号是身份证号,初始密码:123456(可修改)
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include<time.h>
#include<stdint.h>
#include <stdlib.h>
#define MAX 19
#define MIN 16
#define MIN_INPUT 0x20
#define MAX_INPUT 0x7e
time_t timer;
struct tm *tblock;
int userPrint;//用于用户输入验证码
typedef struct
{
char vipAccount[MAX]; //会员账号(身份证号)
char vipPassword[MIN]; //会员密码
char vipID[17]; //未知错误(1)
char vipPhoneNum[11]; //会员绑定手机号
double vipAmount; //会员剩余金额
} VIP;
VIP user;//便于操作
typedef struct clock
{
int hour; //小时
int minute; //分钟
int second; //秒
} Clock;
Clock startime;//用于存储上机开始时间
Clock endtime;//用于存储下机时间
Clock temptime;//用于存储临时时间
void vipMenu()//会员界面ui
{
system("cls");
printf("_________________________________________\n");
printf("|*会员信息 |\n");
printf("|*账号:%c%c%c%c%c%c%c%c%c%c%c%c%c%c**** |\n",user.vipAccount[0],user.vipAccount[1],user.vipAccount[2],user.vipAccount[3],user.vipAccount[4],user.vipAccount[5],user.vipAccount[6],user.vipAccount[7],user.vipAccount[8],user.vipAccount[9],user.vipAccount[10],user.vipAccount[11],user.vipAccount[12],user.vipAccount[13]);
printf("|*手机号:%c%c%c****%c%c%c%c |\n",user.vipPhoneNum[0],user.vipPhoneNum[1],user.vipPhoneNum[2],user.vipPhoneNum[7],user.vipPhoneNum[8],user.vipPhoneNum[9],user.vipPhoneNum[10]);
printf("|*余额:%lf |\n",user.vipAmount);
printf("| |\n");
printf("|===========会员界面====================|\n");
printf("|=======================================|\n");
printf("|======上机===========下机==============|\n");
printf("|======使用帮助=======密码修改==========|\n");
printf("|_______________________________________|\n");
if(user.vipAmount<0)
{
printf("余额不足,请充值");
system("pause");
menu();
}
else
{
userChoices();
}
}
void GetPassword(char* pszPw)//密码回显“*”
{
char ch;
int i=0;
int flag=1;
while( ( ch = (char)getch() ) )
{
flag=1;
if ( ch == 13)
{
pszPw[i++]=0;
break;
}
else if ( ch >= MIN_INPUT && ch <= MAX_INPUT) /*所有可打印字符*/
{
pszPw[i++]=ch;
}
else if ( ch == 8 && i> 0 ) //退格键
{
pszPw[i--] = 0;
flag = 0;
putchar( ch );
putchar( ' ' );
putchar( ch );
}
else
flag= 0;
if(flag)
putchar('*');
}
pszPw[i]=0;
}
void manage()//管理员登录
{
char userAccount[5];
char userPass[5];
printf("账号:");
scanf("%s",userAccount);
printf("密码:");
scanf("%s",userPass);
if(strcmp(userAccount,"admin")==0 && strcmp(userPass,"1111")==0)
{
maMenu();
}
}
void maMenu()//管理员界面
{
system("cls");
printf("_________________________________________\n");
printf("|===========管理员界面==================|\n");
printf("|=======================================|\n");
printf("|======会员信息总览========会员充值=====|\n");
printf("|======使用帮助=========================|\n");
printf("|_______________________________________|\n");
maChoice();
}
void maChoice()//管理员选择
{
char choice[20];
scanf("%s",choice);
if(strcmp(choice,"会员信息总览")==0)
{
memberInfor();
}
else if(strcmp(choice,"会员充值")==0)
{
memberRecharge();
}
}
void memberInfor()//会员信息总览
{
int i = 0;
VIP mangePass;
FILE *fpp = fopen("Account library.txt","r+");
printf("|NO| |account number| |password| |Binding| |balance|\n");
printf("------------------------------------------------------------------------------\n");
while(!feof(fpp))
{
i++;
fscanf(fpp,"%s",mangePass.vipAccount);
printf("%04d %s ",i,mangePass.vipAccount);
fscanf(fpp,"%s",mangePass.vipPassword);
printf("%s ",mangePass.vipPassword);
fscanf(fpp,"%s",mangePass.vipPhoneNum);
printf("%s ",mangePass.vipPhoneNum);
fscanf(fpp,"%s",mangePass.vipID);
printf("%s\n",mangePass.vipID);
}
maChoice();
}
void memberRecharge()//会员充值
{
int i = 3;
int condiTime = 0;
int flag = 0;
char key[MAX];//用于转移数据
char account[MAX];//充值账户
double reMoney;
while(1)
{
rename("Account library.txt","Accountlibrary.txt");
FILE *fp = fopen("Accountlibrary.txt","r+");
FILE *fpp = fopen("Account library.txt","wt+");
printf("输入充值账号:");
scanf("%s",account);
printf("输入充值金额:");
scanf("%lf",&reMoney);
while(fscanf(fp,"%s",key)!=EOF)
{
fprintf(fpp,"%s",key);
condiTime++;
if(condiTime%4!=0)
{
fprintf(fpp," ");
}
else
{
fprintf(fpp,"\n");
}
if(strcmp(account,key)==0)
{
flag = 1;
double balance;
fscanf(fp,"%s",key);
fprintf(fpp,"%s ",key);
fscanf(fp,"%s",key);
fprintf(fpp,"%s ",key);
fscanf(fp,"%lf",&balance);
balance = balance + reMoney;
fprintf(fpp,"%lf\n",balance);
condiTime = 0;
}
}
fclose(fpp);
fclose(fp);
system("del Accountlibrary.txt");
if(!flag)
{
printf("账户不存在,请重新输入:");
}
else
{
printf("账户信息已更新\n");
while(i>1)
{
printf("返回用户界面中.......%ds",i--);
printf("\r");
Sleep(1000);
}
system("pause");
maMenu();
}
}
}
void enroll()//注册
{
char choice;
int flag ;//用于判断是否重复手机号的标志
VIP user;
printf("正在注册...\n");
while(1)
{
char account[MAX];
char phoneNum[12];
printf("身份证号:");
scanf("%s",user.vipAccount);
//身份证号查重
FILE *pf = fopen("Account library.txt","r+");
while(fscanf(pf,"%s",account)!=EOF)
{
if(strcmp(account,user.vipAccount)==0)
{
printf("账号已被注册,请重新输入:");
enroll();
}
}
fclose(pf);
if(strlen(user.vipAccount)!=18)
{
continue;
}
else if(strlen(user.vipAccount)==18)
{
unsigned long curTime;
time(&timer);
tblock = gmtime(&timer);
curTime = (tblock->tm_year+1900)*10000+(tblock->tm_mon+1)*100+tblock->tm_mday;
//printf("%ld",curTime);
unsigned long tempTime;
tempTime = (user.vipAccount[6]-'0')*10000000+(user.vipAccount[7]-'0')*1000000+(user.vipAccount[8]-'0')*100000+(user.vipAccount[9]-'0')*10000+(user.vipAccount[10]-'0')*1000+(user.vipID[11]-'0')*100+(user.vipID[12]-'0')*10+(user.vipID[13]-'0');
//printf("%ld",tempTime);
if(curTime-tempTime>180000)
{
int flag = 0;//用于判断
//printf("通过");
while(1)
{
flag = 0;
printf("输入手机号:");
scanf("%s",user.vipPhoneNum);
//手机号查重
FILE *pf = fopen("Account library.txt","r+");
while(fscanf(pf,"%s",phoneNum)!=EOF)
{
if(strcmp(phoneNum,user.vipPhoneNum)==0)
{
printf("手机号已被注册,请重新输入:");
flag = 1;
break;
}
}
fclose(pf);
if(flag)
{
continue;
}
if(strlen(user.vipPhoneNum)!=11)
{
printf("输入有误,重新输入\n");
continue;
}
else
{
int j;
//读取文件中验证码
while(1)
{
int i = 3;
j = verCode();
printf("请输入验证码:");
scanf("%d",&userPrint);
if(userPrint==j)
{
FILE *fp = fopen("Account library.txt","a+");
fprintf(fp,"%s 123456 %s 0.000000\n",user.vipAccount,user.vipPhoneNum);
fclose(fp);
printf("成功注册,请记住你的账号(身份证号)和密码(默认:123456)\n");
printf("》》》请求发送中》》》》》\n");
while(i>1)
{
printf(".......%d",i--);
printf("\r");
Sleep(1000);
}
system("pause");
signUp();
}
else
{
printf("验证码错误,是否重新输入手机号(Y/N):");
scanf("\n");
scanf("%c",&choice);
if(choice == 'Y')
{
break;
}
else
{
printf("已经重新发送验证码,");
continue;
}
}
}
}
}
}
else
{
printf("未成年人禁止上网\n");
continue;
}
}
}
}
void signUp()//登录
{
int flag = 0;//账号正确的标志
int count = 0;
FILE *fp;
char userAccount[18];
char userPass[16];
while(1)
{
printf("账号:");
scanf("%s",userAccount);
fp = fopen("Account library.txt","r");
while(!feof(fp))
{
fscanf(fp,"%s",user.vipAccount);
if(strcmp(userAccount,user.vipAccount)==0)
{
flag = 1;
fscanf(fp,"%s",user.vipPassword);
fscanf(fp,"%s",user.vipPhoneNum);
fscanf(fp,"%lf",&user.vipAmount);
while(count<3)
{
printf("密码:");
GetPassword(userPass);
if(strcmp(userPass,user.vipPassword)==0)
{
fclose(fp);
//printf("登录成功");
vipMenu();
}
else if(count<3)
{
printf("密码有误请重新输入:");
count++;
}
}
while(1)
{
int j = verCode();
int userVerify;
printf("验证码:%d\n请输入以上验证码:",j);
scanf("%d",&userVerify);
if(userVerify==j)
{
printf("重新输入密码:");
GetPassword(userPass);
if(strcmp(userPass,user.vipPassword)==0)
{
fclose(fp);
// printf("登录成功");
vipMenu();
}
}
}
}
else
{
fscanf(fp,"%s",user.vipPassword);
fscanf(fp,"%s",user.vipPhoneNum);
fscanf(fp,"%lf",&user.vipAmount);
}
}
if(!flag)
{
fseek(fp,0L,0);
printf("账号不存在,请重新输入\n");
fclose(fp);
}
}
}
int verCode()//发送验证码
{
int i;
int j;
srand((int)time(0));//初始化时间
j = rand()%9999;
FILE *fp = fopen("vercode.txt","w+");
//printf("%d",j);//需要写入文件
fprintf(fp,"%d",j);
fclose(fp);
return j;
}
void Begin()//开始ui
{
printf("正在启动网吧管理系统 请您遵守网吧管理规定,看好随身物品。\n");
char str[100] = ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>";
int i,j;
for(i = 0; i<strlen(str); i++)
{
printf("%c",str[i]);
Sleep(10);
}
printf("\n加载完成\n");
system("pause");
system("cls");
}
void menu()//菜单界面ui
{
system("cls");
printf("==================================\n");
printf("===========网吧管理系统===========\n");
printf("==================================\n");
printf("======会员登录=======成为会员=====\n");
printf("======使用帮助=======找回密码=====\n");
printf("==================================\n");
userChoice();
}
void userChoice()//用户选择1
{
while(1)
{
char userchoice[20];
scanf("%s",userchoice);
if(strcmp(userchoice,"会员登录")==0)
{
// printf("登录");
signUp();
}
else if(strcmp(userchoice,"成为会员")==0)
{
printf("注册");
enroll();
}
else if(strcmp(userchoice,"使用帮助")==0)
{
printf("帮助");
//userMal();
}
else if(strcmp(userchoice,"管理员登录")==0)
{
manage();
}
else if(strcmp(userchoice,"找回密码")==0)
{
getPassBack();
}
else
{
printf("输入有误,请重新输入");
}
}
}
void getPassBack()
{
int j,i;
int flag = 0; //是否有对应账号的标签
char key[11];
while(1)
{
printf("输入绑定手机号:");
scanf("%s",key);
if(strlen(key)!=11)
{
printf("输入有误,重新输入\n");
continue;
}
VIP mangePass;
FILE *fpp = fopen("Account library.txt","r+");
while(!feof(fpp))
{
fscanf(fpp,"%s",mangePass.vipAccount);
fscanf(fpp,"%s",mangePass.vipPassword);
fscanf(fpp,"%s",mangePass.vipPhoneNum);
fscanf(fpp,"%s",mangePass.vipID);
if(strcmp(key,mangePass.vipPhoneNum)==0)
{
flag = 1;
break;
}
}
if(flag)
{
printf("已经发送验证码,请输入:");
j = verCode();
while(1)
{
scanf("%d",&userPrint);
if(userPrint==j)
{
printf("|NO| |account number| |password| |Binding| |balance|\n");
printf("------------------------------------------------------------------------------\n");
printf("%04d %s ",i,mangePass.vipAccount);
printf("%s ",mangePass.vipPassword);
printf("%s ",mangePass.vipPhoneNum);
printf("%s\n",mangePass.vipID);
}
else
{
printf("输入有误!!重新输入");
}
}
}
}
}
void userChoices()//用户选择2
{
char userchoice[10];
while(1)
{
scanf("%s",userchoice);
if(strcmp(userchoice,"上机")==0)
{
getOn();
}
else if(strcmp(userchoice,"下机")==0)
{
printf("尚未上机");
}
else if(strcmp(userchoice,"使用帮助")==0)
{
}
else if(strcmp(userchoice,"密码修改")==0)
{
changePass();
}
}
}
void getOn()//上机
{
int endWhile = 0;//用于下机结束循环
int vipChoice;//区域选项
int upOdown;//是否下机的选项
double money;//单价
while(1)
{
Clock a;
printf("选择区域:1.VIP区\n2.游戏区\n3.普通区");
scanf("%d",&vipChoice);
switch(vipChoice)
{
case 1:
money = 0.25;
break;
case 2:
money = 0.16;
break;
case 3:
money = 0.05;
break;
default:
getOn();
}
while(!kbhit())
{
printf("\r");
if(endWhile == 0)
{
timestar();
endWhile = 1;
}
timeend();
Sleep(1000);
a.second = temptime.second - startime.second;
if(a.second<0)
{
a.second = a.second + 60;
temptime.minute--;
}
a.minute = temptime.minute - startime.minute;
if(a.minute<0)
{
a.minute = a.minute + 60;
temptime.hour--;
}
a.hour = temptime.hour - startime.hour;
printf("%02d:%02d:%02d", a.hour, a.minute,a.second);
if(a.minute%15==0 && a.minute!=0 && a.second==0)
{
//自动保存
money = money*15;
preservation(money);
}
}
printf("是否下机?(1/0)");
scanf("%d",&upOdown);
if(upOdown==1)
{
if(vipChoice == 1)
{
//自动保存
money = money *((a.hour*60+a.minute)%15);
preservation(money);
break;
}
else if(vipChoice == 2)
{
//自动保存
money = money *((a.hour*60+a.minute)%15);
preservation(money);
break;
}
else if(vipChoice == 3)
{
//自动保存
money = money *((a.hour*60+a.minute)%15);
preservation(money);
break;
}
}
else
{
printf("重新");
}
}
}
void preservation(double money)//更新用户信息
{
int i = 3;
int condiTime = 0;
double balance;
char key[19];//用于文件数据的转移
rename("Account library.txt","Accountlibrary1.txt");
FILE *fp = fopen("Accountlibrary1.txt","r+");
FILE *fpp = fopen("Account library.txt","wt+");
while(fscanf(fp,"%s",key)!=EOF)
{
fprintf(fpp,"%s",key);
condiTime++;
if(condiTime%4!=0)
{
fprintf(fpp," ");
}
else
{
fprintf(fpp,"\n");
}
if(strcmp(user.vipPhoneNum,key)==0)
{
double balance;
fscanf(fp,"%lf",&balance);
balance = balance - money;
fprintf(fpp,"%lf\n",balance);
condiTime++;
}
}
fclose(fpp);
fclose(fp);
system("del Accountlibrary1.txt");
printf("账户信息已更新\n");
while(i>1)
{
printf("返回用户界面中.......%ds",i--);
printf("\r");
Sleep(1000);
}
system("pause");
}
void changePass()//密码修改
{
int i = 3;
int j;
char phone[11];
while(1)
{
printf("输入绑定手机号:");
scanf("%s",phone);
if(strcmp(phone,user.vipPhoneNum)==0)
{
printf("已经发送验证码,请输入:");
j = verCode();
while(1)
{
scanf("%d",&userPrint);
if(userPrint==j)
{
int condiTime = 0;
char key[19];//用于文件数据的转移
printf("输入新密码:");
scanf("%s",user.vipPassword);
rename("Account library.txt","Accountlibrary1.txt");
FILE *fp = fopen("Accountlibrary1.txt","r+");
FILE *fpp = fopen("Account library.txt","wt+");
while(fscanf(fp,"%s",key)!=EOF)
{
condiTime++;
if(strcmp(key,user.vipAccount)!=0)
{
fprintf(fpp,"%s ",key);
}
else
{
fprintf(fpp,"%s ",key);
fprintf(fpp,"%s ",user.vipPassword);
fscanf(fp,"%s",key);
condiTime++;
}
if(condiTime%4==0)
{
fprintf(fpp,"\n");
}
}
fclose(fpp);
fclose(fp);
system("del Accountlibrary1.txt");
printf("成功修改密码,请记住你的账号(身份证号)和新密码\n");
printf("》》》请求发送中》》》》》\n");
while(i>1)
{
printf(".......%d",i--);
printf("\r");
Sleep(1000);
}
system("pause");
vipMenu();
}
else
{
printf("验证码错误,重新输入:");
}
}
}
else
{
printf("手机号输入错误");
}
}
}
void timestar()//记录开始时间
{
time_t now ;
struct tm *p ;
time(&now) ;
p = localtime(&now) ;
startime.hour = p->tm_hour;
startime.minute = p->tm_min;
startime.second = p->tm_sec;
}
void timeend()//记录结束时间
{
time_t now ;
struct tm *p ;
time(&now) ;
p = localtime(&now) ;
temptime.hour = p->tm_hour;
temptime.minute = p->tm_min;
temptime.second = p->tm_sec;
}
int main()
{
Begin();
menu();
return 0;
}