⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.cpp

📁 小程序应有如下功能: 1、登记。登记每位同学的上网卡号
💻 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 + -