?? 2.cpp
字號:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<string.h>
static float ave;
static float allm;
struct times{
int minut ;
int hours ;
};
typedef struct preson{
char numb[20] ; //上網卡號
struct times tim1 ;//上網時刻
struct times tim3 ;//skim time
int tim2 ;//上網的時間
float money ; //押金
struct preson * next ;
}* preson1 ;
void meun1();
void exit();
void registers(struct preson * * head); //登記
void settleac(struct preson * * head); //結帳
void sequel(struct preson * * head); //續費
void query(struct preson * headp); //查詢
void amend(); //修改費率
void generalledger(); //總收入
void anykey();
void refurbish(struct preson * * head); //提示下機
void skim(struct preson *headp); //瀏覽
int longc(char a[20]);
void main()
{
int n;
struct preson * head ;
head=NULL;
ave=0.5;
allm=0;
while(1)
{
system("cls");
refurbish(&head);
meun1();
printf("\t\tpleas chooes :");
scanf("%d",&n);
switch(n)
{
case 0 : skim(head); break ;
case 1 : registers(&head); break ;
case 2 : settleac(&head); break ;
case 3 : sequel(&head); break ;
case 4 : query(head); break ;
case 5 : amend(); break ;
case 6 : generalledger(); break ;
case 7 : exit(0) ; break ;
default: printf("\t\trewrite\n");
}
}
}
void meun1()
{
printf("\n\n\n\n\t*****************機房上網管理系統***************\n");
printf("\t\t\t0:\t瀏覽 ;\n");
printf("\t\t\t1:\t登記 ;\n");
printf("\t\t\t2:\t結帳 ;\n");
printf("\t\t\t3:\t續費 ;\n");
printf("\t\t\t4:\t查詢 ;\n");
printf("\t\t\t5:\t修改費率;\n");
printf("\t\t\t6:\t總帳 ;\n");
printf("\t\t\t7:\t退出 .\n");
}
void registers(struct preson * * head) //登記
{
char a[20];
int nm;
float e;
struct preson * p,*headp ,*test; //
headp=*head;
test=*head;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
p=(struct preson *)malloc(sizeof(struct preson ));
printf("\n\t\t登記帳號:");
scanf("%s",a);
nm=longc(a);
while(nm>=20)
{
printf("\t\t重新輸人帳號:") ;
scanf("%s",a);
nm=longc(a);
}
while(test)
{
while(nm>=20)
{
printf("\t\t重新輸人帳號:") ;
scanf("%s",a);
nm=longc(a);
}
if(strcmp(test->numb,a)==0)
{
printf("\n\t\t重新輸人帳號:");
test=*head;
scanf("%s",a);
}
else test=test->next;
}
strcpy(p->numb,a);
printf("\n\t\t押金(>=5rmb):");
scanf("%f",&e);
while(e<5)
{
printf("\n\t\t重新輸入:");
scanf("%f",&e);
}
p->money=e;
p->tim1.minut=timeinfo->tm_min;
p->tim1.hours=timeinfo->tm_hour;
p->tim3.minut=timeinfo->tm_min;
p->tim3.hours=timeinfo->tm_hour;
p->tim2=0;
p->next=NULL;
if(head)
{
p->next=*head;
*head=p;
}
else headp->next=p;
}
void settleac(struct preson * *head) //結帳
{
struct preson * before ,*headp;
int flag,a;
char n1[20];
float all;
flag=0;
headp=*head;
printf("\t\t輸入下機人的帳號:");
scanf("%s",n1);
while(headp)
{
if(strcmp(headp->numb,n1)==0)
{
a=(headp->tim2+30)/30;
all=a*ave;
allm=allm+all;
flag=1;
printf("\t\t應付%.1f元錢\n\t\t應找回%.1lf元錢\n",all,headp->money-all);
if(headp==*head) *head=headp->next;
else before->next=headp->next;
free(headp);
break;
}
before=headp;
headp=headp->next;
}
if(!flag) printf("\n\t\t無此帳號。\n");
anykey();
}
void sequel(struct preson * * head) //續費
{
struct preson *headp ;
char n1[20];
float n2;
int flag;
flag=0;
headp=*head;
printf("\t\t輸入帳號:");
scanf("%s",n1);
printf("\n\t\t續費金額:");
scanf("%f",&n2);
while(headp)
{
if(strcmp(headp->numb,n1)==0)
{
headp->money=headp->money+n2;
printf("\t\t帳號:%.0lf\n\t\t押金:%.1f",headp->numb,headp->money);
flag=1;
}
headp=headp->next;
}
if(!flag) printf("\n\t\t無此帳號。\n");
anykey();
}
void query(struct preson * headp) //查詢
{
struct preson * before;
char n1[20];
int flag ,h,m;
flag=0;
printf("\t\t輸入帳號:");
scanf("%s",n1);
while(headp)
{
if(strcmp(headp->numb,n1)==0)
{
h=headp->tim2/60;
m=headp->tim2%60;
printf("\t\t帳號:%8s\n\t\t押金:%.1f\n\t\t上網時間為:%d小時%d分",headp->numb,headp->money,h,m);
flag=1;
}
before=headp;
headp=headp->next;
}
if(!flag) printf("\n\t\t無此帳號。\n");
anykey();
}
void amend() //修改費率
{
float n4;
printf("\n\t\t輸人費率:");
scanf("%f",&n4);
ave=n4;
}
void generalledger() //總收入
{
printf("\n\t\t目前總收入為%.1f元",allm);
anykey();
}
void anykey() // ..........?
{
printf("\n\t\tpress Enter continue");
getchar();
getchar();
}
void refurbish(struct preson * * head) //提示下機
{
struct preson * headp;
int d,e,f;
headp=*head;
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
while(headp)
{
d=timeinfo->tm_hour-headp->tim3.hours;
e=timeinfo->tm_min-headp->tim3.minut;
headp->tim3.hours=timeinfo->tm_hour;
headp->tim3.minut=timeinfo->tm_min;
d=d*60+e;
headp->tim2=headp->tim2+d;
f=int((headp->tim2+1)*ave/60); //.....................................?
if(f>=headp->money)
{
printf("\n\t該帳號%8.0lf余額不足1分鐘了,請提示下機。",headp->numb);
anykey();
}
headp=headp->next;
}
}
void skim(struct preson *headp)
{
int i ,j ;
system("cls");
printf("\n\n上網卡號\t押金\t上網時刻\t上網的時間\n");
while(headp)
{
i=headp->tim2%60;
j=headp->tim2/60;
printf("%8s\t%4.1f\t%3d:%-4d\t%5d:%-4d\t\n",headp->numb,headp->money,headp->tim1.hours,
headp->tim1.minut,j,i);
headp=headp->next;
}
anykey();
}
int longc(char a[20])
{
int i ;
i=0;
while(a[i])
i++;
return(i);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -