完成java课设的经验_课设后的感想

今天课设答辩结束了,可以说是很圆满的成功了,我用了3天时间在我们班第一个完成答辩。

做的是简单的学生上机系统,在此之前,我从来不敢想象我可以做到,并完成得那么好。

记得刚拿到题目时就懵了,一时不知该怎么办。但是后来沉下心去,系统功能一个一个地实现,写完一部分就编译一次

第一天就实现了信息录入和保存功能,后面的越来越顺利,遇到的逻辑问题也一个一个的慢慢解决了。

最后终于完成了270多行的代码。

就连我自己都不相信我能独立完成,看到别人的课设都是借其他人或是上届学生的课设,我可以大声地说:“我的课设完全是自己写的。

laugh.gif

这次课设让我更加深刻的了解链表和熟悉了关于时间函数的操作,更大的收获是我明白了一个道理,写程序是不能急的,一步步来,一步步编译,一步步找错

一步步的解决逻辑问题,很快就能完成。

以下是代码,我想这值得我自己收藏。

#include

#include

#include

#include

#include

#define NAME_LEN 50

#define NUMBER_LEN 15

struct Student

{

char number[NUMBER_LEN]; //学号

char name[NAME_LEN]; //姓名

char department[20]; //院系

int time_left; //剩余机时,以分钟为单位

struct Student* pNext; //指向下一个结构

time_t machine_time; //记录学生的上机时间

int type; //记录学生的上机类型(1为课内上机,2为自由上机)

int machine_number; //记录学生的上机号

};

struct Student* first=NULL;

struct Student* Get_Student();

struct Student* enter(); //录入学生信息

void save(); //保存学生信息

struct Student* on_machine(struct Student*); //上机签到

void exit(struct Student*first,struct Student *current);//下机处理

void teacher_menu();

void student_menu();

void main()

{

int choice=0;

int count=0;

struct Student* current=NULL;

//老师的操作

for(;;)

{

teacher_menu();

printf("请输入你要执行的操作: ");

scanf(" %d",&choice);

if((choice==2)&&(count!=0)) //第一次选择保存操作视为非法输入

{

save();

break;

}

else if(choice==1)

{

first=enter();

count++;

}

else

printf("非法输入!\n");

}

fflush(stdin);

//学生的操作

student_menu();

for(;;)

{

printf("请输入你要执行的操作: ");

scanf(" %d",&choice);

if(choice==2)

{

printf("你没有上机!\n");

}

else if(choice==1)

{

current=on_machine(first);

break;

}

else

{

printf("非法输入!\n");

}

}

fflush(stdin);

for(;;)

{

printf("请输入你要执行的操作: ");

scanf(" %d",&choice);

if(choice==1)

{

printf("你已经上过机了!\n");

}

else if(choice==2)

{

exit(first,current);

break;

}

else

{

printf("非法输入!");

}

}

}

struct Student* Get_Student()

{

struct Student *pStudent;

//为结构体声明内存

pStudent=(struct Student*)malloc(sizeof(struct Student));

printf("-------学号-------姓名----系别--剩余机时----\n");

scanf("%s%s%s%d",pStudent->number,pStudent->name,pStudent->department,&pStudent->time_left);

fflush(stdin);

pStudent->machine_time=0; //对未输入项进行初始化

pStudent->type=0;

pStudent->machine_number=0;

pStudent->pNext=NULL;

return pStudent;

}

struct Student *enter()

{

struct Student *first=NULL; //指向第一个学生的指针

struct Student *current=NULL; //指向当前学生的指针

struct Student *last=NULL; //指向前一个学生的指针

struct Student *pcurrent=NULL; //检验学号是否相同时用到

char more='\0';

do

{

current=Get_Student();

if(NULL==first) //第一次录入信息时

{

first=current; //指向第一个学生

last=current;

}

else

{

pcurrent=first;

while(pcurrent!=NULL)

{

if(strcmp(pcurrent->number,current->number)==0)

{

printf("你输入了同样的学号!\n");

exit(0);

}

pcurrent=pcurrent->pNext;

}

last->pNext=current; //问题是如何保证学号唯一?

last=current;

}

printf("你想再录入另一个学生的信息吗?(y or n) ");

scanf(" %c",&more);

fflush(stdin);

}while(tolower(more)=='y');

return first;

}

void save() //保存函数还存在问题

{

struct Student *current=first;

FILE *pfile=NULL;

int i=0;

if((pfile=fopen("student.txt","wt"))==NULL)

{

printf("无法打开文件student.txt,程序终止!");

exit(1);

}

printf("\nSaving file\n");

while(current!=NULL)

{

fprintf(pfile,"%-20s%-20s%-20s%-8d\n",current->number,current->name,current->department,

current->time_left);

current=current->pNext;

}

fclose(pfile);

printf("*****************save sucess****************\n");

}

struct Student *on_machine(struct Student * first)

{

char number[NUMBER_LEN];

char name[NAME_LEN];

struct Student *current=NULL;

printf("********************欢迎来到机房**********************\n");

printf("请输入你的学号: ");

scanf(" %s",number);

fflush(stdin);

printf("请输入你的姓名: ");

scanf(" %s",name);

fflush(stdin);

current=first;

while(current!=NULL)

{

if(strcmp(number,current->number)==0)

{

break;

}

current=current->pNext;

}

if(current==NULL)

{

printf("没有你的学号,很抱歉你不能上机!\n");

exit(0);

}

else

{

if(strcmp(name,current->name)==0)

{

printf("请输入你的上机类型:(1是课内上机,2是自由上机) ");

scanf("%d",¤t->type);

current->machine_time=time(NULL);

printf("上机时间:%s\n",ctime(¤t->machine_time));

printf("上机类别:%s\n",(current->type==1)?"课内上机":"自由上机");

srand((int)current->machine_time); //初始化随机序列

current->machine_number=rand()%300+1; //随机生成1~300的机器号

printf("上机号码:%d\n",current->machine_number);

printf("剩余机时:%d分钟\n",current->time_left);

return current;

}

else

{

printf("你输入的学号与姓名不符,很抱歉你不能上机!\n");

exit(0);

}

}

}

void exit(struct Student *first,struct Student *current)

{

char answer='\0';

struct Student *pStudent=NULL;

struct Student *plast=NULL;

printf("你确定要下机(y or n)? ");

scanf(" %c",&answer);

if(tolower(answer)=='y')

{

if(current->type==1)

{

current->type=0;

current->machine_time=0;

printf("您还有%d分钟剩余机时\n",current->time_left);

while(pStudent!=NULL) //释放内存

{

plast=pStudent;

pStudent=pStudent->pNext;

free(plast);

}

}

else

{

current->time_left-=(int)difftime(time(NULL),current->machine_time)/60;

current->type=0;

current->machine_time=0;

printf("您还有%d分钟剩余机时\n",current->time_left);

while(pStudent!=NULL) //释放内存

{

plast=pStudent;

pStudent=pStudent->pNext;

free(plast);

}

}

}

}

void teacher_menu()

{

printf("*************************************************\n");

printf("* 1、录入学生信息 *\n");

printf("* 2、保存学生信息 *\n");

printf("*************************************************\n");

}

void student_menu()

{

printf("*************************************************\n");

printf("* 1、上机签到 *\n");

printf("* 2、下机 *\n");

printf("*************************************************\n");

}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值