A program written by myself when i was learning c.
C 语言大作业报告
200530212043 8/31/06
09:15:13.PM 作业题目:
按给定的数据结构设计一个具有下面功能的菜单通信录。 要求:能显示菜单,并且能进行选择以及完成相应的功能。 数据结构:学号、姓名、性别、家庭住址、邮编、电话。 功能:
1.数据录入--按顺序录入特定的学生成绩; .2.删除特定的记录; .3.修改特定的记录; .4.查询特定的记录; .5.退出。 提示:参考教材的第十一章和第十三章有关内容。 解题的基本算法和基本架构:
1. 为了符合书本知识的应用和使程序得到简化,本程序使用单链来储存数据(即姓名、学号等)。 2.由于成绩具有同类的特性,所以相应地建立一个结构体来存放,也因此产生了复合的结构体, 但是在显示、储存、载入链表的时候,如果每个数据都要显示的话,会很占屏幕,所以可 可能显示方面有一些不整齐,然而,那个对人接收数据不会产生影响。 3.为程序能够简单的运行,使用了一个head_ptr.指针来贯穿整个程序,每个功能的实现都会由 这个指针参数来提供接口,当然函数的返回值也会是个指针参数,它会提供下一个功能的入口 4.本程序提供了一个主菜单,大多数的功能都会在这里得到实现,但同时,也相应的做了几个子菜 单,它们主要用来进行一些日常信息的管理,如登录日志,密码更改等。 5.为了是功能得到强化,特意增加了成绩统计功能,同时把数据的管理分为创建链表,删除链表中 的某个条目,增加条目,载入链表,保存链表,显示链表,按学号搜索条目等,而且每个功能都会 有相应的菜单来选择执行, 6.为了方便程序的维护和管理,把程序分为了3 个模块:主函数模块负责菜单的显示,功能 显示;链表操作模块,实现数据的操作;登录模块,负责登录事项的管理。 7. 根据题目的要求搜索功能只是实现了按学号搜索的功能。 8.为了使程序更加人性化,几乎每个菜单都会进行表格化,方便操作。 9.程序的可扩张性是根据结构化的设计的原理来实现的,对于链表的操作扩展性应该很大, 整个程序所用的算法都是以基本的循环,条件语句来实现。 10. 为了使程序可以在多个平台运行,方便实现,所以没有使用特定的系统函数,这样程序的 适应能力,或者说是可移植性就大大提高,经测试可以在Ubuntu 上运行。 11. 为了方便编译,写了几个makefile ,分别对应不同的编译器,它们主要有Microsoft.Visual.C...++,Borland.c++,Turbo.c++,GNU.gcc 等。 源代码: 注意:本程序纯属用作本次大作业的报告,任何人用作其它用途,不管褒贬,请保留本人的 小名,还有,任何软件或者他人代码发现与本程序有一点点相同,纯属巧合,与本人无关, 敬请留意。
1.sys_log.h— 系统日志实现头文件. /*************************************************************** .*system_loglogin.system, loginout.system,.add.a.password,..* .*.edit.password,.save.password...* .* .*.* .*Functions:.* .* passwdthe.password.to.login.system. ..* .*.save_loginsave.the.login..record..* .*.in.the.log.txt.* .*.save_logoutsave.the.logout.record. ..*
.*.chg_passwdchange.the.password. .* add_passwdadd.a.password. ..* .*.dellfiledelete.the.log.history.file. ..* .*.view_logview.the.log.history.file. ..* .**************************************************************/ /************************************************************* .*passwdthe.password.to.login.system. .*************************************************************/ .extern.void.passwd(void);
/************************************************************* .*save_loginopen.the.log.record.file.and.save.infomation. ..* .*.* .*Parameters.* .* nameName.of.disk.file.which.stored.the.* .*.log.record...* .*Returns.* .*.0open.secceeded. ..* .*.nozeroopen.failed. ..* .**************************************************************/
..extern.int.save_login(const.char.name[]);
/************************************************************* .*save_logoutsave.the.log.record.file. ..* .*************************************************************/ .extern.int.save_logout(const.char.name[]);
/************************************************************ .*add_chg_passwdadd.orchange.the.password. ..* .*Returns.* ochange.sucessfully. ..* .*.nozerofailed.to.change. ..*
.************************************************************/
.extern.void.add_chg_passwd(void);
/************************************************************* .*del_lfiledelete.the.log.file. ..* .*************************************************************/ .extern.int.del_lfile(const.char.name[]);
/************************************************************** .*view_logview.the.log.record.file. .**************************************************************/ .extern.int.view_log(const.char.name[]);
2.sys_log.c— 系统日志的实现文件。 /*************************************************************** .*system.log.module.* .* Handles.the.login.and.logout.* .*.do.with.the.password.matters...* .*Functions.* .* passwdthe.password.to.login.system. ..* .*.save_loginsave.the.login..record..* .*.in.the.log.txt...*
.*.save_logoutsave.the.logout.record.file .*.in.the.log.txt...* .* add_chg_passwdadd.or.change.a.password. ..* .*.view_logview.the.log.history.file. ..* .*.del_lfiledelete.the.log.history.file. ..* .**************************************************************/ .#include.
.struct.log_file{ FILE.*file;........../*file.used.to.record*/ char.time[STRING_MAX];........./*login.date.and.time*/ char.usr_name[STRING_MAX];...../*user.who.login*/ char.state[8];......../*log.state.*/
.};
.struct.log_file.log; /* .*.passwdthe.password.to.login.system. ..* .*/ .void.passwd(void) .{ .char.line[STRING_MAX]; .char.string_pw[STRING_MAX];...../*the.array.to.store.password*/
.FILE.*ptr;.................../*the.password.file*/ .char.string_in[STRING_MAX];........../*the.string.input*/ .ptr.=.fopen("pwd.dat","rb"); .if.(ptr.==.NULL).{
.printf("Memory.Error!\n"); .} .fscanf(ptr,."%s",.string_pw); .while(1){
.printf("Please.Enter.Your.Password:"); .fgets(line,sizeof(line),stdin); .sscanf(line,"%s",string_in); .if(strcmp(string_pw,string_in)==.0)
.break;
else.printf("Error!\n"); .} .fclose(ptr); .printf("Welcome.back!Master\n");
.}
/* .*add_chg_passwdadd.or.change.a.password. .*/ .void.add_chg_passwd(void) .{
.char.line[STRING_MAX]; .FILE.*pwd_ptr; .char.str1[STRING_MAX]; .char.str2[STRING_MAX]; .printf("Atttion.:.if.you.have.an.old.password,.it.will.be.lay.over!\n"); .pwd_ptr.=.fopen("pwd.dat","wb"); .if(pwd_ptr.==.NULL)
.printf("There.is.something.wrong!");../*memory.error*/
.while(1){ .printf("Please.Enter:"); .fgets(line,sizeof(line),stdin); .sscanf(line,"%s",str1); .printf("Enter.Again.To.Confirm:."); .fgets(line,sizeof(line),stdin);
.sscanf(line,"%s",str2);
.if(strcmp(str1,str2).==.0.){ .printf("PASSWORD.CHANGED.SUCESSFULL\n"); .break;
.}
.else.printf("ERROR,NOT.THE.SAME!\n"); .} .fprintf(pwd_ptr,."%s",.str1); .fclose(pwd_ptr);
}
/* .*save_loginsave.the.login.record.. .*/ .int.save_login(const.char.name[]) .{
.time_t.td; .time(&td); .log.file.=.fopen(name,"a+"); .if(log.file.==.NULL)../*failed.to.open.file*/
return.(errno);
./* ..*get.the.date.and.time.from.system. .*/
.strcpy.(log.time,asctime(localtime(&td))); .log.time[strlen(log.time)1] .=.'\0'; .strcpy.(log.usr_name,."Administrator");...../*define.the.usr's.name*/ .strcpy.(log.state,."login");................/*system.state*/ .fprintf(log.file,"\t\tTIME\t\tUSER\t.STATE\n"); .fprintf(log.file,".%s..%s.%s\n",log.time,log.usr_name,log.state); .fclose(log.file); .return.(0);
.}
/*
.*.save_logoutsave.the.logout.record. .*/ .int.save_logout(const.char.name[]) .{ .time_t.td; .time(&td); .log.file.=.fopen(name,."a+");..../*open.log.fiel*/ .if(log.file.==.NULL)../*failed.to.open*/
return.(errno);
.strcpy(log.state,."logout");.........../*system.state*/
./* ..*get.the.date.and.time.from.system. .*/
.strcpy.(log.time,asctime(localtime(&td))); .log.time[strlen(log.time)1] .=.'\0'; .strcpy.(log.usr_name,"Administrator"); .fprintf(log.file,"\t\tTIME\t\tUSER\t.STATE\n"); .fprintf(log.file,".%s..%s.%s\n",log.time,log.usr_name,log.state); .fclose(log.file); .return.(0);
.}
./* ..*del_lfiledelete.the.log.record. .*/
.int.del_lfile(const.char.name[])
.{ .FILE.*fp; .fp.=.fopen(name.,."w"); .if(fp.==.NULL)
return.(errno); .fclose(fp); .return.(0);
.}
/* .*view_logview.the.history.record. .*/ .int.view_log(const.char.name[]) .{
.char.ch; .FILE.*fp; .fp.=.fopen(name.,."r"); .if(fp.==.NULL){
printf("failed.to.open.file"); return.(errno); .}
.ch.=.fgetc(fp); .while(ch.!=.EOF){................/*output.the.char.until.the.end.of.file.*/
.putchar(ch); .ch.=fgetc(fp);
.} .fclose(fp); .return.(0);
.}
3.record_manage.h— 链表数据头文件。 /************************************************************* .*define.the.structure.of.student. .*************************************************************/
..struct.grade{ float.Maths;.............../*mathematical.analysis.score*/ float.English;............./*English.score*/ float.Advan_lang_progr;...../*C.Programming.score*/
.};
.struct.student{ int.rno;.................../*student.number*/ char.name[50];............./*student.name*/ char.sex[10];.............../*student.sex*/ char.clas[50];............./*student.class*/ char.address[100];........./*strdent.home.address*/
....int..zip_code;......../*home's.postalcode*/ long.int.homei;............/*home's.telephone.number*/ struct.grade.score;......../*student.score.*/ struct.student.*next_ptr;.../*next.item*/
.};
/************************************************************** .*cre_reccreate.student.record. .***********************************************************/ .extern.struct.student.*cre_rec(void);
./************************************************************* .*add_recadd.a.student's.infomation. ..* .**************************************************************/ .extern.struct.student.*add_rec(struct.student.*head_ptr);
/************************************************************** .*delete_recdelete.a.student's.infomation. ..* .**************************************************************/ .extern.struct.student.*delete_rec.(struct.student.*head_ptr);
/**************************************************************
.*load_recload.all.students'.record.from.file. ..* .**************************************************************/
.extern.struct.student.*load_rec.(struct.student.*head_ptr);
/************************************************************* .*save_recsave.students'.information.in.a.file. ..* .*************************************************************/
.extern.int.save_rec(struct.student.*head_ptr);
./********************************************************** .*searchThis.is.designed.to.search.record.by..* .*...student.G.R.NO.or.by.name...* .*Parameters.* .* head_ptrthe.pointer.to.the.linked.head. ..* .*Returns .*.head_ptrthe.same.to.parameters. ..* .**********************************************************/ .extern.struct.student.*search(struct.student.*head_ptr);
/************************************************************* .*printprint.the.student.record. .*************************************************************/ .extern.void.print(struct.student.*head_ptr);
/************************************************************ .*statisticsprint.a.statistics. .************************************************************/ .extern.struct.student.*statistics(struct.student.*head_ptr);
4.record_manage.c— 链表数据实现文件. /************************************************************** .*record_manage...* .*This.module.is.used.to.manage.the.students'.information,..* .*such.as,.editing.,.adding,.deleting,.reviewing...* .*Public.Functions.* .*.struct.student.*cre_rec.(void);.* .*.struct.student.*add_rec.(struct.student.*head_ptr);.* .*.strutct.student.*delete_rec.(struct.student.*head_ptr);.* .*.struct.student.*load_rec.(void);.* .*.void.save_rec(struct.student.*head_ptr);.*
.*.struct.student.*search(struct.student.*head_ptr); .*.void.print(struct.student.*head) .**************************************************************/ .#include.
.#include.
.#include."record_manage.h"
.int.node_num;................./*node.counter.*/
/* .*cre_reccreate.students'.record. .*/ .struct.student.*cre_rec(void)../*This.will.return.a.pointer.*/ .{
.struct.student.*head_ptr; .struct.student.*ptr1,.*ptr2; .node_num.=.0;
./* ..*initialize.linked. .*/
./* ..*allocate.space. .*/
.ptr1.=.ptr2.=.(struct.student.*)malloc(sizeof(struct.student)); .printf("Enter.a.G.R.NO(above.0):"); .scanf("%d",&ptr1> rno); .while.(ptr1> rno.<.0).{
.printf("\nThe.number.must.above.zero\n"); .printf("Enter.again:"); .scanf("%d",.&ptr1> rno.);
.} .printf("Enter.Name:"); .scanf("%s",.ptr1> name.); .printf("Enter.SEX(M.OR.F):"); .scanf.("%s",ptr1> sex); .printf("Enter.Class:"); .scanf.("%s",.ptr1> clas.); .printf("Enter.Address:"); .scanf.("%s",.ptr1> address.); .printf("Enter.Postalcode:"); .scanf("%d",.&ptr1> zip_code.); .printf("Enter.Telephone.Number:"); .scanf.("%ld",&ptr1> homei.); .printf("Enter.Maths.Score:"); .scanf.("%f",.&((*ptr1).score.Maths).);
.printf("Enter.English.Score:"); .scanf.("%f",.&((*ptr1).score.English).); .printf("Enter.Advanced.Programming.Languge:."); .scanf("%f",.&((*ptr1).score.Advan_lang_progr)..); .head_ptr.=.NULL; .while.(1){
.node_num.=.node_num.+.1; .if.(node_num.==.1)
head_ptr.=.ptr1; .else.ptr2> next_ptr.=.ptr1; .ptr2.=.ptr1; .ptr1.=.(struct.student.*)malloc(sizeof(struct.student)); .if.(ptr1.==.NULL).{
printf("out.of.memory\n"); exit(0); .}
./* ..*continue.to.initialize. .*/
.printf("Enter.G.R.NO(above.0.or.0.to.exit):"); .scanf("%d",&ptr1> rno); .if.(ptr1> rno.<.0).{
.printf("\nThe.number.must.above.zero\n"); .printf("Enter.again:"); .scanf("%d",.&ptr1> rno.);
.} .else.if(ptr1> rno.==.0)
.break; .else{ .printf("Enter.Name:"); .scanf("%s",.ptr1> name.); .printf("Enter.sex(M.OR.W):"); .scanf("%s",.ptr1> sex.); .printf("Enter.Class:"); .scanf("%s",.ptr1> clas.); .printf("Enter.Address:"); .scanf("%s",.ptr1> address.); .printf("Enter.Postalcode:"); .scanf("%d",.&ptr1> zip_code.); .printf("Enter.Telephone.Number:"); .scanf("%ld",.&ptr1> homei.); .printf("Enter.Maths.Score:"); .scanf("%f",.&((*ptr1).score.Maths).); .printf("Enter.English.Score:"); .scanf("%f",.&((*ptr1).score.English).);
.printf("Enter.Advanced.Programming.Languge:."); .scanf("%f",.&((*ptr1).score.Advan_lang_progr)..);
.} .} .ptr2> next_ptr.=.NULL;.............../*the.end.of.linked*/ .return.(head_ptr); .}; /*
.*add_recadd.student.record. .*/ .struct.student.*add_rec(struct.student.*head_ptr) .{
struct.student.*stu; struct.student.*ptr1,*ptr2,*ptr3; ptr1.=.head_ptr;................/*point.to.the.first.node*/ stu.=.(struct.student.*)malloc(sizeof(struct.student));
.../*point.to.the.insert.node*/ printf("INPUT.THE.INSERT.ITEM:\n"); printf("Enter.G.R.NO:"); scanf("%d",.&stu> rno); printf("Enter.Name:"); scanf("%s",.stu> name.); printf("Enter.sex(M.OR.W):"); scanf("%s",.stu> sex.); printf("Enter.Class:"); scanf("%s",.stu> clas.); printf("Enter.Address:"); scanf("%s",.stu> address.); printf("Enter.Postalcode:"); scanf("%d",.&stu> zip_code.); printf("Enter.Telephone.Number:"); scanf("%ld",&stu> homei.); printf("Enter.Maths.Score:"); scanf("%f",.&((*stu).score.Maths).); printf("Enter.English.Score:"); scanf("%f",.&((*stu).score.English).); printf("Enter.Advanced.Programming.Languge:."); scanf("%f",.&((*stu).score.Advan_lang_progr)..);
ptr2.=.stu;
if.((head_ptr.==.NULL)).{......./*NO.original.linked*/ head_ptr.=.ptr2;............/*ptr2.point.to.the.head*/ ptr2> next_ptr.=.NULL.;
} else{ while.((ptr2> rno.>.ptr1> rno.).&&.(ptr1> next_ptr.!=.NULL)){
ptr3.=.ptr1;............/*ptr3.point.to.the.same.with.ptr1*/
ptr1.=.ptr1> next_ptr.;./*ptr1.point.to.next*/ } if.(ptr2> rno.<=.ptr1> rno.).{
if(head_ptr.==.ptr1)head_ptr.=.ptr2;./*insert.to.the.first*/ else.ptr3> next_ptr.=.ptr2;../*insert.to.center*/ ptr2> next_ptr.=.ptr1;
}else{ ptr1> next_ptr.=.ptr2; ptr2> next_ptr.=.NULL;......./*insert.to.the.last*/
}
} node_num.=.node_num.+.1;.........................../*add.1.to.node.counter*/ return.(head_ptr);
.}
/* .*delete_recdelete.a.item.from.the.record. .*/ .struct.student.*delete_rec(struct.student.*head_ptr) .{
.struct.student.*ptr1,*ptr2; .int.num; .printf("Enter.the.G.R.NO.to.delete(Enter.0.to.exit):"); .scanf("%d",&num); .while(num.!=.0){
if(head_ptr.==.NULL){ printf("\nthere.is.no.record\n"); return.(0);
} ptr1.=.head_ptr; /*
.*ptr1.is.not.the.node.we.want. .*/
while(num.!=.ptr1> rno.&&.ptr1> next_ptr.!=.NULL){ ptr2.=.ptr1; ptr1.=.ptr1> next_ptr;
}./*goto.next.node*/
/* .*found.the.item. .*/
if(num.==.ptr1> rno){
if(ptr1.==.head_ptr)../*the.head.item.is.the.target*/ head_ptr=ptr1> next_ptr;
else.ptr2> next_ptr.=.ptr1> next_ptr;./*current.point.to.next.next.item*/
printf("delete:%d",num); node_num.=.node_num.1; ................/*decrease.one.item*/ } /*
.*item.not.found*
.*/ else.printf("there.is.no.%d.in.the.record\n",.num); printf("Enter.the.G.R.NO(0.for.exit):"); scanf("%d".,.&num);
.} .return.(head_ptr); .}
/* .*load_recload.all.record.from..file. .*/ .struct.student.*load_rec(struct.student.*head_ptr) .{
.char.fileop[20]; .struct.student.*ptr1,*ptr2; .int.m.=.0; .FILE.*in_file; .printf("Enter.File.Path.and.Name,please!~$"); .scanf("%s",fileop); .in_file.=.fopen(fileop,."r+"); .if.(in_file.==.NULL).{
.printf("cannot.open.file\n");............/*file.to.read*/
.return.(0); .} ./*
..*read.form.
.*/ .fscanf(in_file,."********************************************************\n"); .fscanf(in_file,."*...Communication.Book..*\n"); .fscanf(in_file,."*..AUTHOR:HUZHILI.CLASS:1.MAJOR:ELECTRONICENGINEER
*\n"); .fscanf(in_file,."********************************************************\n"); .fscanf(in_file,"\ n"); .fscanf(in_file,"NO.\tNAME\tSEXCLA\t\tADDRESS\t\tPOCO\tHTN\tMATHS.ENG.CP
\n"); .fscanf(in_file,"\ n"); ./*
..*print.form.
.*/ .printf("********************************************************\n"); .printf("*...Communication.Book..*\n"); .printf("*..AUTHOR:HUZHILI.CLASS:1.MAJOR:ELECTRONICENGINEER..*\n"); .printf("********************************************************\n"); .printf("\ n"); .printf("NO.\tNAME\tSEXCLA\t\tADDRESS\t\tPOCO\tHTN\tMATHS.ENG.CP\n"); .printf("\ n"); .m.=.m.+.1; .if(m.==.1){
ptr1.=.(struct.student.*)malloc(sizeof(struct.student));./*new.item*/
fscanf(in_file,"%d%s%s%s%s%d%ld%f%f%f",&ptr1> rno,.ptr1> name, ptr1> sex,.ptr1> clas,.ptr1> address,&ptr1> zip_code, &ptr1> homei,&ptr1> score.Maths,&ptr1> score.English, &ptr1> score.Advan_lang_progr);
./*read.and.print*/ .head_ptr.=.NULL; .do{
node_num.=.node_num.+.1; if(node_num.==.1)head_ptr.=.ptr1; else.ptr2> next_ptr.=.ptr1; ptr2.=.ptr1; ptr1.=.(struct.student.*)malloc(sizeof(struct.student));../*new.item*/ fscanf(in_file,"%d%s%s%s%s%d%ld%f%f%f",&ptr1> rno,.ptr1> name,
ptr1> sex,.ptr1> clas,.ptr1> address,&ptr1> zip_code, &ptr1> homei.,&ptr1> score.Maths,&ptr1> score.English, &ptr1> score.Advan_lang_progr);
/* .*Print.form.. .*/
printf("%d\t%s\t%s.%s\t%s.%d.%ld\t%.1f\t%.1f\t%.1f\t\n",ptr1> rno, ptr1> name,ptr1> sex,ptr1> clas,ptr1> address,ptr1> zip_code,ptr1> homei, ptr1> score.Maths,ptr1> score.English,ptr1> score.Advan_lang_progr);
.}while(!feof(in_file)); .ptr2> next_ptr.=.ptr1; .ptr1> next_ptr.=.NULL; .node_num.=.node_num.+.1; .} .printf("\ n"); .fclose(in_file);/*end.load,.close.file*/ .return.(head_ptr);
.};
/* .*save_recsave.record.to.a.file. .*/ .int.save_rec(struct.student.*p1) .{
.FILE.*fp;
.char.filepn[20];
.printf("Please.Enter.File.Path.and.Name:~$"); .scanf("%s",filepn); .if((fp=fopen(filepn,"w+"))==NULL){
.printf("Fail.to.open.file!\n");
.return.0; .} .fprintf(fp,."********************************************************\n"); .fprintf(fp,."*...Communication.Book..*\n"); .fprintf(fp,."*..AUTHOR:HUZHILI.CLASS:1.MAJOR:ELECTRONICENGINEER..*\n"); .fprintf(fp,."********************************************************\n"); .fprintf(fp,"\ n"); .fprintf(fp,"NO.\tNAME\tSEXCLA\t\tADDRESS\t\tPOCO\tHTN\tMATHS.ENG.CP\n"); .fprintf(fp,"\ n"); ./*PRINT.FORM.AREA*/ .while(p1!=NULL){
.fprintf(fp,"%d\t%s\t%s.%s\t%s.%d.%ld\t%.1f\t%.1f\t%.1f\t\n",p1> rno, .p1> name,p1> sex,p1> clas,p1> address,p1> zip_code,p1> homei, .p1> score.Maths,p1> score.English,p1> score.Advan_lang_progr);
.p1=p1> next_ptr;/*NEXT.NODE*/
.} .fclose(fp); .printf("FILE.SAVED!\n"); .return.0;
.}
/* .*searchdesigned.to.make.a.quick.search. .*/ .struct.student.*search(struct.student.*head_ptr) .{
.int.number; .struct.student.*ptr1,*ptr2; .printf("Enter.the.student's.G.R.NO(o.for.exit):"); .scanf("%d",&number.);
.while(number.!=.0) .{
.if(head_ptr.==.NULL){ printf("\nThere.is.no.record.here\n"); return.(head_ptr);
.} .printf("\ n"); .printf("NO.\tNAME\tSEXCLA\t\tADDRESS\tPOCO\tHTNMATHSENGCP\n"); .printf("\ n"); .ptr1=head_ptr; .while(number.!=.ptr1> rno.&&.ptr1> next_ptr.!=.NULL){
ptr2.=.ptr1;
ptr1.=.ptr1> next_ptr; .} .if(number.==.ptr1> rno)
printf("..%d.%s..\t%s.%s...\t%s\t.%d.%ld.%.1f.%.1f.%.1f", .ptr1> rno,.ptr1> name,.ptr1> sex,ptr1> clas, .ptr1> address,.ptr1> zip_code,.ptr1> homei, .ptr1> score.Maths,head_ptr> score.English, .ptr1> score.Advan_lang_progr.);
.else.printf("%there.is.no.%d",number); .printf("Enter.number.(Enter.0.to.exit)"); .scanf("%d",&number); .} .printf("STATE:exited\n"); .return.(head_ptr);
.}
/* .*printprint.the.record. .*/ .void.print(struct.student.*head_ptr) .{
.struct.student.*ptr; .if(head_ptr.==.NULL) printf("THERE.IS.NO.RECORD!\n");
.else{ printf("These.%d.records.are:\n",node_num); printf("\ n"); printf("NO.\tNAME\tSEXCLA\t\tADDRESS\tPOCO\tHTNMATHSENGCP\n");
ptr=head_ptr; do{
printf("..%d.%s..\t%s.%s...\t%s\t%d.%ld.%.1f.%.1f.%.1f\n", .ptr> rno,.ptr> name,.ptr> sex,ptr> clas, .ptr> address,.ptr> zip_code,.ptr> homei,
.ptr> score.Maths,ptr> score.English, .ptr> score.Advan_lang_progr.); .printf("\ n");
.ptr=ptr> next_ptr;../*go.to.next.item*/
}while(ptr.!=.NULL);./*END.PRINT*/ .} .}
/* .*statisticscomputer.single.person.average.score., .single.subject.average
.*...MAX.total.score,.and.Min.total.score. .*/ .struct.student.*statistics(struct.student.*head_ptr)
.{ .float.sum1.=.0,.sum2.=.0,.sum3.=.0; .float.ave1.=.0,.ave2.=.0,.ave3.=.0; .float.max.=0,.min.=0; .struct.student.*ptr; .int.y.=.0,.i.=.0; .int.x; .int.j.=.0; .ptr.=.head_ptr; .while(j.<.80){
.printf("*");
.j++; .} .printf("1.SINGLE.STATISTICS.\t2.SINGLE.SUBJUCT.AVERAGE.\n"); .printf("3.HIGHEST.TOTAL\t\t4.LOWEST.TOTAL.\n"); .printf("0.ENTER.O.TO.EXIT\t\n"); .while(j.>.0){
.printf("*");
.j; .} .printf("Please.Choose.one.item:"); .scanf("%d",&x); .getchar(); .switch(x){ .case.0:break; .case.1:if(head_ptr.==.NULL){
...printf("\nThere.is.NO.record.now!\n"); ...return.(head_ptr); }/*NO.linked*/ ....else.{
printf("\ n"); printf("NO.\tNAME\tMATHS\tENG\tCP\tTOTAL\tAVEREGE\t\n"); printf("\ n"); while.(ptr.!=.NULL){
/*caculate.single*/ sum1.=.ptr> score.Maths.+.ptr> score.English.+.ptr
>score.Advan_lang_progr; ave1.=.sum1/3; printf("%d\t%s\t%.1f\t%.1f\t%.1f\t%.1f\t%.1f\t",ptr> rno,
ptr> name,ptr> score.Maths,ptr> score..English,
ptr> score..Advan_lang_progr,sum1,ave1.); /*PRINT.RESULT*/ printf("\ n"); ptr.=.ptr> next_ptr;
} } return.(head_ptr); break;
.case.2:if(head_ptr.==.NULL){ printf("\nThere.is.NO.record.now!\n"); return.(head_ptr);
}/*NO.LINKED*/
while(ptr.!=.NULL){ sum1.=.sum1.+.ptr> score.Maths; sum2.=.sum2.+.ptr> score.English; sum3.=.sum3.+.ptr> score..Advan_lang_progr.;/*Caculate.total*/ y.=.y.+.1; ave1.=.sum1/y; ave2.=.sum2/y; ave3.=.sum2/y;......../*Caculate.average*/ ptr.=.ptr> next_ptr;../*Next.node*/
} printf("AVERAGE.OF.MATHS:%.1f\n",ave1); printf("AVERAGE.OF.ENGLISH:%.1f\n",ave2); printf("AVERAGE.OF.CP:%.1f\n",ave3); return.(head_ptr); break;
.case.3:if(head_ptr.==.NULL){ printf("\nThere.is.NO.record.now!\n"); return.(head_ptr);
} max.=.ptr> score..Maths.+.ptr> score..English.+ptr> score..Advan_lang_progr.; while(i.<.node_num){
i.=.i.+.1; sum1.=.ptr> score..Maths.+.ptr> score..English.+.ptr> score
.Advan_lang_progr.; if(max.<.sum1) max.=.sum1;
ptr.=.ptr> next_ptr.; } printf("HIGHEST.TOTAL.SCORE:%.1f\n",max); return.(head_ptr); break;
.case.4:if(head_ptr.==.NULL){ printf("\nThere.is.NO.record.now\n!"); return.(head_ptr);
} while(ptr.!=.NULL){ min.=.ptr> score..Maths.+.ptr> score..English.+.ptr> score .Advan_lang_progr.; while(ptr.!=.NULL){ sum2.=.ptr> score..Maths.+.ptr> score..English.+.ptr> score .Advan_lang_progr.; if(min.>.sum2) min.=.sum2; ptr.=.ptr> next_ptr;
} } printf("LOWEST.OF.TOTAL:%.1f\n",min); return.(head_ptr); break;
.default:printf("Error!Try.again,please!\n"); .} .return.(head_ptr);
.}
5.COMBK.c— 主文件. /************************************************************** .*This.is.the.main.function.of.the.project...* .*It.will.display.a.menu.to.choose...* .*By.that,it.can.complete.some.* .*managemet.of.Communication.book...* .* .*Functions
.* menudisplay.a.menu. .* mainno.need.to.say. .************************************************************/ .#include.
.#include."record_manage.h"
/* .*log_managemanage.the.log.infomation. .*/ .void.log_manage(int.opera) .{
.int.i; .printf("\t\tWELCOME.TO.LOG.PART\n");
.while.(opera){
.for.(i.=.0;.i.<=.50;.i++.){
.printf("*"); .} .printf("\n\t1.Add.or.change.password\n"); .printf("\t2.View.log.infomation\n"); .printf("\t3.Delete.the.log.file\n"); .printf("\t4.Enter.0.to.exit\n"); .for.(i.=.0;.i.<=.50;.i++).{
.printf("*"); .} .printf("\nPlease.choose.an.item:"); .scanf("%d",.&opera); .switch(opera){
.case.0:break; .case.1:add_chg_passwd(); break; .case.2:view_log("log.txt"); break; .case.3:del_lfile("log.txt"); break; .default:printf("Enter.error!\nTry.again,please!"); .} .} .}
/* .*menudisplay.a.menu.to.choose.operetion. .*/ .int.menu(int.opera) .{
.struct.student.*head_ptr.=.0; .struct.student.*stud.=.0;
.int.i; .while(opera){ ./*
..*Give.an.operation.info.
.*/ .printf("\t\t\t\tCommunication.Book\n"); .printf("\t\t\t\t.Author:HUZHILI\n"); .for.(i.=.0;.i.<80;..i++){
.printf("*"); .} .printf.("\n\t\t\t\tWELCOME.TO.COM_BOK!\n"); .printf.("\t1.Enter.student.Info\t\t\t2.Load.From.File\n"); .printf.("\t3.Search.Student.Info\t\t\t4.Delete.Student.Info\n"); .printf.("\t5.Add.Student.Info\t\t\t6.Display.Student.Info\n"); .printf.("\t7.Statistics\t\t\t\t8.Log.Management\t\t"); .printf.("\t9.Save.Changes.\t\t\t\t10.EXIT\n"); .for.(i.=.0;.i.<.80;.i++).{
.printf("*"); .} .printf("\nPlease.choose.an.operation:"); .scanf("%d",&opera); ./*completement.the.operetion*/ .switch(opera){
.case.1:head_ptr.=.cre_rec();............../*create.linked*/ break; .case.2:head_ptr.=.load_rec(head_ptr);...../*load.linked*/ break; .case.3:head_ptr.=.search(head_ptr);......./*search.linked*/ break; .case.4:head_ptr.=.delete_rec(head_ptr);.../*delete.item*/ break; .case.5:head_ptr.=.add_rec(head_ptr);....../*add.an.item*/ break; .case.6:print(head_ptr);.................../*print.the.linked*/
break; .case.7:statistics(head_ptr);............../*.Give.a.statistics*/ .case.8:log_manage(opera);....................../*manipulate.log.info.*/
break; .case.9:save_rec(head_ptr);.............../*save.changes*/ .break; .case.10:save_logout("log.txt");............/*logout.system*/ exit.(8);
.default:printf("Enter.error\nTry.again,.please!"); .} .}
.return.(0);
.} /*
.*mainthe.main.function.of.the.project.
.*/
.int.main(void)
.{
.int.opera.=.1;
.FILE.*ptr;
.ptr.=.fopen("pwd.dat","rb");
.if(.ptr.==.NULL){
printf("There.is.no.password,Please.add.one\n");
add_chg_passwd();
.}
.else.passwd();
.save_login("log.txt");
.menu(opera);
.return.(0);
.}
主要心得与体会:
这是第一次做程序设计,根据实际问题进行分析求解,而且初次使用了模块化设计,大大的方便 了实际工作,根据所学的的C 语言知识,加上自己的思考,设计出一点东西,感觉真不錯,在分析问 题时,要想象实际的工作生活需要,进行改进,使这个程序更加符合要求。在求解问题的时候, 运用自顶至下,逐步求精的方法,首先设计好具体那个模块实现那些功能以及相应的数据要 求,写出初次企划方案,要后根据这个方案进行初步的代码设计,实现部分功能,在实际编 码的过程中,取得要领,根据实际进行改进,在初步实现了某些功能的时候,就进行全面的 编码工作,同时,这时也想到了,一些可以实现的额外功能,就开始有意识的猜想,然后就 就加的功能写代码,最终完成初始代码编辑工作,从而开始测试,在测试的过程中发现漏洞 和错误,同时这时也开始了漫长的DEBUG 阶段,由于初次做这样的大作业,对C 语言也是 才学了半个学期,完全没有什么程序设计经验,这时的工作对我来说就变得很漫长的拉,这 时候,这是不明白怎么会有这么多的错误呀!真是想一脚把它们踢开,想到BUG 真是是一些 讨厌的东西!不过在这段过程中,我认为自己是学到最多的时候,正所谓要在困难中成长, 迎难而上,这些错误,真是可爱有可恨,以前从来没有想到DEBUG 会是这么神奇的事,它 们就像一群寄生虫一样,程序的产生,成长,发展,它们也跟着产生,成长,发展,对于我 的小程序,它们可是无孔不入呀!刚刚改完这里,哪里又不知不觉产生了BUG 了,真是够意 思的家伙。好在,在长思漫想中,它们初步清除了,起码我的程序可以运行了,通过了编 译,在往后的测试中,又有很多的东东需要改进,然而,这是挺那个的,就像在对它们说: “来呀,小弟,等着你们这群家伙哟”。在多次的测试中,感觉对自己的基础有了很大坚固, 这就是还得要感谢它们的原因了。另外,自己也发现了几个不會的问题,没有能够解决,这 就要在以后的学习中努力了。对于简化代码,觉得有时候,清晰点也不错的,不是很大的影 响效率,应该没有什么问题吧。最后,注明一下,之所以用英文写程序,是自己不想经常换 切换输入法,加上这样能练练英语,虽然,有错误这是一定的啦,但是起码比不敢写好点, 这是自己的个人观点,呵呵。
Entry for November 19, 2006
Jan302007
KARPAR
Subscribe to:
Post Comments (Atom)
0 评论: (+add yours?)
Post a Comment