C语言机房收费_c语言机房收费系统

2020-02-28 其他范文 下载本文

C语言机房收费由刀豆文库小编整理,希望给你工作、学习、生活带来方便,猜你可能喜欢“c语言机房收费系统”。

机房收费管理系统

(1)输入功能:输入30名学生的学号、班级、姓名、上机起始时间。

(2)计算功能:计算每个下机学生的上机费用,每小时1元。

(上机费用=上机时间* 1.0/h,不足一小时按一小时计算)

(3)查询功能:按条件(班级、学号、姓名)显示学生的上机时间。

(4)机器使用情况的显示(显示方式不限但要一目了然)

#include

#include

#include

#define NULL 0

#define LEN sizeof(struct student)

struct student

{

long num;

long cla;

char name[15];

int hour1;

int min1;

int hour2;

int min2;

struct student *next;

};

int n;

#include“file1.h”

#include“insert.c”

#include“creat.c”

#include“time.c”

#include“del.c”

#include“save.c”

#include“copy.c”

#include“print.c”

#include“swit.c”

void main()

{char c;

int flag,k;

struct student *head,*stu;

printf(“one hour 1.0 yun!n”);

printf(“Infed information---------->1n”);

printf(“Search expense------------->2n”);

printf(“delet the information------>3n”);

printf(“=============================================n”);

printf(“!!Example!!n”);//例子示范//

printf(“###*************Infed information**********##n”);

printf(“ number cla name 12:30-14:21n”);//注意号输入//head=creat();//使head=调用返回“头指针”//

for(flag=1;flag;)//flag为真,操作//

{

printf(“Will you ? :”);//输入相应的数值,做相应的操作//

scanf(“%d”,&k);

swit(head,stu,k);

printf(“go on ? y/n:”);

getchar();

c=getchar();

if(c=='N'||c=='n')flag=0;

//如果输入'n'or'N'则退出使用本软件,否则继续相应操作//

}

}

void swit(struct student *head,struct student *stu,int k)

{

long dele,number;

struct student *p1;

switch(k)

{

case 1:

{

printf(“!!Example!!n”);//例子示范//

printf(“##*********Infed information**********##n”);

printf(“number cla name 12:30-14:21n”);//注意号输入

printf(“=>:”);

stu=(struct student *)malloc(LEN);//添加信息时必须开

scanf(“%ld%ld%s%d:%d-%d:%d”,&stu->num,&stu->cla,stu->name,&stu-

>hour1,&stu->min1,&stu->hour2,&stu->min2);

while(stu->num!=0)//作用为多次输入后,多次开辟空间//{ head=insert(head,stu);printf(“=>:”);

stu=(struct student *)malloc(LEN);

//添加信息时必须开辟空间//scanf(“%ld%ld%s%d:%d-%d:%d”,&stu->num,&stu->cla,stu->name,&stu->hour1,&stu->min1,&stu->hour2,&stu->min2);}

copy(head);

print(head);

}break;

case 2:

{ printf(“##*************Search.expense*************##n”);printf(“search number :”);

//输入要找的号码“number->num”//

scanf(“%ld”,&number);

while(number!=0)//输入0,则结束擦找//{ time(head,number);

printf(“search number :”);

scanf(“%ld”,&number);

}

}break;

case 3:

{printf(“##**********delet.the.information*********##n”);

printf(“input the deleted number:”);//输入删除号码//

scanf(“%ld”,&dele);

while(dele!=0)////输入0,则结删除//

{ head=del(head,dele);

print(head);

copy(head);

printf(“input the deleted number:”);

scanf(“%ld”,&dele);

}

}break;

}

}

struct student *creat(void)//1

{struct student *head;

struct student *p1,*p2;

n=0;

p1=p2=(struct student *)malloc(LEN);

//创建空间为“LEN”,强转换为结构型,第一次输入//

printf(“=>:”);

scanf(“%ld%ld%s%d:%d-%d:%d”,&p1->num,&p1->cla,p1->name,&p1->hour1,&p1->min1,&p1->hour2,&p1->min2);

head=NULL;

while(p1->num!=0)//号码不为0,可继续输入//

{ n=n+1;//输入一个,节点加一//

if(n==1)head=p1;//有一个用户//

else p2->next=p1;//多个用户,p1将指向下一个节点//

p2=p1;

p1=(struct student *)malloc(LEN);

//将创建下一个空间,创建下一个空间后,输入信息//

printf(“=>:”);

scanf(“%ld%ld%s%d:%d-%d:%d”,&p1->num,&p1->cla,p1->name,&p1->hour1,&p1->min1,&p1->hour2,&p1->min2);

}

p2->next=NULL;//表尾//

return(head);

}

struct student * insert(struct student * head,struct student * stud)//stud是添加的用户// {struct student *p0,*p1,*p2;

p1=head;

p0=stud;

if(head==NULL)//如果没有任何用户,添加为第一//

{head=p0;p0->next=NULL;}

else

{while((p0->num>p1->num)&&(p1->next!=NULL))

//按号码小到大排列,并寻找添加节点//

{p2=p1;p1=p1->next;}//p1将指向下一个节点//

if(p0->numnum)

{if(head==p1)head=p0;//恰好最小//

else p2->next=p0;//在中间//

p0->next=p1;}

else

{p1->next=p0;p0->next=NULL;}//在末尾//

}

n=n+1;//添加后接点数//

return(head);

}

struct student *del(struct student *head,long num)

{

struct student *p1,*p2;

if(head==NULL){printf(“NO list!n”);} //如果没有任何用户,不商除//p1=head;

while(num!=p1->num&&p1->next!=NULL)//寻找符合节点//

{p2=p1;p1=p1->next;}//p1将指向下一个节点//

if(num==p1->num)

{if(p1==head)head=p1->next;//恰好最小//

else p2->next=p1->next;//在中间,便指向尾接点//

printf(“delete %ld succe!n”,num);//输出商除用户

n=n-1;//商除后接点数//

}

else printf(“%ld not been found!n”,num);//当找不到时//

return(head);

}

void print(struct student * head)

{struct student *p;

printf(“Now %d person!!n”,n);//当前用户//

p=head;

if(head!=NULL)//要有用户//

do

{

printf(“%ld%ld%s%d:%d-%d:%dn”,p->num,p->cla,p->name,p->hour1,p->min1,p->hour2,p->min2);

time(p,p->num);

p=p->next;//指向下一个节点//

}while(p!=NULL);

else printf(“NO one!n”);

}

void time(struct student *head,long number){struct student *p=head;

int i,a,b;

float c;

if(p==NULL){printf(“NO list!n”);}

else

{

for(i=0;i

{

if(p->num==number)break;

else p=p->next;

}

a=(p->hour2)-(p->hour1);

b=fabs((p->min2)-(p->min1));

c=(a+b/60.0)*1.0;

printf(“ %ld Money is :%fn”,number,c);}

}

void copy(struct student *head)

{

save(head);

}

void save(struct student *head)

{

struct student *p;

FILE *fp;

int i;

p=head;

if((fp=fopen(“list.c”,“w”))==NULL)

{

printf(“cannot open list.cn”);

return;

}

do

{

if(fwrite(p,sizeof(struct student),1,fp)!=1)

printf(“list write errorn”);

p=p->next;

}while(p!=NULL);

fclose(fp);

}

《C语言机房收费.docx》
将本文的Word文档下载,方便收藏和打印
推荐度:
C语言机房收费
点击下载文档
相关专题 c语言机房收费系统 机房 语言 c语言机房收费系统 机房 语言
[其他范文]相关推荐
    [其他范文]热门文章
      下载全文