不过要求使用文件的话也是可以的
首先要创建一个用于保存用户信息的文件(用户名和密码等信息)
程序运行时可以将该文件数据读取到一个链表中
注册时通过查找该链表中是否有对应用户名来确定是否会重复
注册成功后可以为用户自动生成一个保存数据的文件名
然后该用户的日程信息保存在该文件名所指向的文件中
登陆时只要打开该文件并将数据读取到一个链表中进行 *** 作即可
如果代码不想自己写的话
我可以有偿代劳
#include"stdio.h"#include"stdlib.h"#include"string.h"intshoudsave=0/**/structstudent{char()num[10]/*学号*/char()name[20]char()sex[4]intcgradeintmgradeintegradeinttotleintavecharneartime[10]/*最近更新时间*/}typedefstructnode{structstudentdatastructnode*next}Node,*Linkvoidmenu(){printf("********************************************************************************")printf("\t1登记学生资料\t\t\t\t\t2删除学生资料\n")printf("\t3查询学生资料\t\t\t\t\t4修改学生资料\n")printf("\t5保存学生资料\t\t\t\t\t0退出系统\n")printf("********************************************************************************\n")}voidprintstart(){printf("-----------------------------------------------------------------------\n")}voidWrong(){printf("\n=====>提示:输入错误!\n")}voidNofind(){printf("\n=====>提示:没有找到该学生!\n")}voidprintc()/*本函数用于输出中文*/{printf("学号\t姓名性别英语成绩数学成绩C语言成绩总分平均分\n")}voidprinte(Node*p)/*本函数用于输出英文*/{printf("%-12s%s\t%s\t%d\t%d\t%d\t%d\t%d\n",p->data.num,p->data.name,p->data.sex,p->data.egrade,p->data.mgrade,p->data.cgrade,p->data.totle,p->data.ave)}Node*Locate(Linkl,charfindmess[],charnameornum[])/*该函数用于定位连表中符合要求的接点,并返回该指针*/{Node*rif(strcmp(nameornum,"num")==0)/*按学号查询*/{r=l->nextwhile(r!=NULL){if(strcmp(r->data.num,findmess)==0)returnrr=r->next}}elseif(strcmp(nameornum,"name")==0)/*按姓名查询*/{r=l->nextwhile(r!=NULL){if(strcmp(r->data.name,findmess)==0)returnrr=r->next}}return0}voidAdd(Linkl)/*增加学生*/{Node*p,*r,*scharnum[10]r=ls=l->nextwhile(r->next!=NULL)r=r->next/*将指针置于最末尾*/while(1){printf("请你输入学号(以'0'返回上一级菜单:)")scanf("%s",num)if(strcmp(num,"0")==0)breakwhile(s){if(strcmp(s->data.num,num)==0){printf("=====>提示:学号为'%s'的学生已经存在,若要修改请你选择'4修改'!\n",num)printstart()printc()printe(s)printstart()printf("\n")return}s=s->next}p=(Node*)malloc(sizeof(Node))strcpy(p->data.num,num)printf("请你输入姓名:")scanf("%s",p->data.name)getchar()()printf("请你输入性别:")scanf("%s",p->data.sex)getchar()()printf("请你输入c语言成绩:")scanf("%d",&p->data.cgrade)getchar()()printf("请你输入数学成绩:")scanf("%d",&p->data.mgrade)getchar()printf("请你输入英语成绩:")scanf("%d",&p->data.egrade)getchar()p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgradep->data.ave=p->data.totle/3/*信息输入已经完成*/p->next=NULLr->next=pr=pshoudsave=1}}voidQur(Linkl)/*查询学生*/{intselcharfindmess[20]Node*pif(!l->next){printf("\n=====>提示:没有资料可以查询!\n")return}printf("\n=====>1按学号查找\n=====>2按姓名查找\n")scanf("%d",&sel)if(sel==1)/*学号*/{printf("请你输入要查找的学号:")scanf("%s",findmess)p=Locate(l,findmess,"num")if(p){printf("\t\t\t\t查找结果\n")printstart()printc()printe(p)printstart()}elseNofind()}elseif(sel==2)/*姓名*/{printf("请你输入要查找的姓名:")scanf("%s",findmess)p=Locate(l,findmess,"name")if(p){printf("\t\t\t\t查找结果\n")printstart()printc()printe(p)printstart()}elseNofind()}elseWrong()}voidDel(Linkl)/*删除*/{intselNode*p,*rcharfindmess[20]if(!l->next){printf("\n=====>提示:没有资料可以删除!\n")return}printf("\n=====>1按学号删除\n=====>2按姓名删除\n")scanf("%d",&sel)if(sel==1){printf("请你输入要删除的学号:")scanf("%s",findmess)p=Locate(l,findmess,"num")if(p){r=lwhile(r->next!=p)r=r->nextr->next=p->nextfree(p)printf("\n=====>提示:该学生已经成功删除!\n")shoudsave=1}elseNofind()}elseif(sel==2){printf("请你输入要删除的姓名:")scanf("%s",findmess)p=Locate(l,findmess,"name")if(p){r=lwhile(r->next!=p)r=r->nextr->next=p->nextfree(p)printf("\n=====>提示:该学生已经成功删除!\n")shoudsave=1}elseNofind()}elseWrong()}voidModify(Linkl){Node*pcharfindmess[20]if(!l->next){printf("\n=====>提示:没有资料可以修改!\n")return}printf("请你输入要修改的学生学号:")scanf("%s",findmess)p=Locate(l,findmess,"num")if(p){printf("请你输入新学号(原来是%s):",p->data.num)scanf("%s",p->data.num)printf("请你输入新姓名(原来是%s):",p->data.name)scanf("%s",p->data.name)getchar()printf("请你输入新性别(原来是%s):",p->data.sex)scanf("%s",p->data.sex)printf("请你输入新的c语言成绩(原来是%d分):",p->data.cgrade)scanf("%d",&p->data.cgrade)getchar()printf("请你输入新的数学成绩(原来是%d分):",p->data.mgrade)scanf("%d",&p->data.mgrade)getchar()printf("请你输入新的英语成绩(原来是%d分):",p->data.egrade)scanf("%d",&p->data.egrade)p->data.totle=p->data.egrade+p->data.cgrade+p->data.mgradep->data.ave=p->data.totle/3printf("\n=====>提示:资料修改成功!\n")shoudsave=1}elseNofind()}voidDisp(Linkl){intcount=0Node*pp=l->nextif(!p){printf("\n=====>提示:没有资料可以显示!\n")return}printf("\t\t\t\t显示结果\n")printstart()printc()printf("\n")while(p){printe(p)p=p->next}printstart()printf("\n")}voidTongji(Linkl){Node*pm,*pe,*pc,*pt,*pa/*用于指向分数最高的接点*/Node*r=l->nextif(!r){printf("\n=====>提示:没有资料可以统计!\n")return}pm=pe=pc=pt=pa=rwhile(r!=NULL){if(r->data.cgrade>=pc->data.cgrade)pc=rif(r->data.mgrade>=pm->data.mgrade)pm=rif(r->data.egrade>=pe->data.egrade)pe=rif(r->data.totle>=pt->data.totle)pt=rif(r->data.ave>=pa->data.ave)pa=rr=r->next}printf("------------------------------统计结果--------------------------------\n")printf("总分最高者:\t%s%d分\n",pt->data.name,pt->data.totle)printf("平均分最高者:\t%s%d分\n",pa->data.name,pa->data.ave)printf("英语最高者:\t%s%d分\n",pe->data.name,pe->data.egrade)printf("数学最高者:\t%s%d分\n",pm->data.name,pm->data.mgrade)printf("c语言最高者:\t%s%d分\n",pc->data.name,pc->data.cgrade)printstart()}voidSort(Linkl){LinkllNode*p,*rr,*sll=(Link)malloc(sizeof(Node))/*用于做新的连表*/ll->next=NULLif(l->next==NULL){printf("\n=====>提示:没有资料可以排序!\n")return}p=l->nextwhile(p){s=(Node*)malloc(sizeof(Node))/*新建接点用于保存信息*/s->data=p->datas->next=NULLrr=llwhile(rr->next!=NULL&&rr->next->data.totle>=p->data.totle)rr=rr->nextif(rr->next==NULL)rr->next=selse{s->next=rr->nextrr->next=s}p=p->next}free(l)l->next=ll->nextprintf("\n=====>提示:排序已经完成!\n")}voidSave(Linkl){FILE*fpNode*pintflag=1,count=0fp=fopen("c:\\student","wb")if(fp==NULL){printf("\n=====>提示:重新打开文件时发生错误!\n")exit(1)}p=l->nextwhile(p){if(fwrite(p,sizeof(Node),1,fp)==1){p=p->nextcount++}else{flag=0break}}if(flag){printf("\n=====>提示:文件保存成功.(有%d条记录已经保存.)\n",count)shoudsave=0}fclose(fp)}voidmain(){Linkl/*连表*/FILE*fp/*文件指针*/intselcharchcharjianintcount=0Node*p,*rprintf("\t\t\t\t学生成绩管理系统\n\t\t\t\t-------福建农业职业学院计应0501黄欢(32号)\n")l=(Node*)malloc(sizeof(Node))l->next=NULLr=lfp=fopen("C:\\student","rb")if(fp==NULL){printf("\n=====>提示:文件还不存在,是否创建?(y/n)\n")scanf("%c",&jian)if(jian=='y'||jian=='Y')fp=fopen("C:\\student","wb")elseexit(0)}printf("\n=====>提示:文件已经打开,正在导入记录\n")while(!feof(fp)){p=(Node*)malloc(sizeof(Node))if(fread(p,sizeof(Node),1,fp))/*将文件的内容放入接点中*/{p->next=NULLr->next=pr=p/*将该接点挂入连中*/count++}}fclose(fp)/*关闭文件*/printf("\n=====>提示:记录导入完毕,共导入%d条记录.\n",count)while(1){menu()printf("请你选择 *** 作:")scanf("%d",&sel)if(sel==0){if(shoudsave==1){getchar()printf("\n=====>提示:资料已经改动,是否将改动保存到文件中(y/n)?\n")scanf("%c",&ch)if(ch=='y'||ch=='Y')Save(l)}printf("\n=====>提示:你已经退出系统,再见!\n")break}switch(sel){case1:Add(l)break/*增加学生*/case2:Del(l)break/*删除学生*/case3:Qur(l)break/*查询学生*/case4:Modify(l)break/*修改学生*/case5:Save(l)break/*保存学生*/case9:printf("\t\t\t==========帮助信息==========\n")breakdefault:Wrong()getchar()break}}}/**/帮你解决了!选手只要是偶数就行 所以2k和2^k 都行!希望你能 采纳和加分!呵呵。。。。#include <stdio.h>
#include <stdlib.h>
#define FALSE 0
#define TRUE 1
#define Maxplayers 20
#define MaxCombinations (Maxplayers/2)*(Maxplayers-1)
struct game { int one, two}
int players /* 选手总数 */
int z = 4
long combinations/* 比赛场数,一场有两人参加,故起名combinations */
int a, b, c, i, m,
startC,
matchCount,
roundCount,
index
long round_set /*轮次选择的标志,如果某位被置1则相应的选手已经被加入当前轮次 */
long totalChecks
struct game tourn[1+MaxCombinations] /* 单循环比赛tournament */
intmList[1+Maxplayers/2]/* matches */
struct game cList[1+MaxCombinations] /* 所有比赛的对战组(一组两人) */
intcUsed[1+MaxCombinations] /* 已经使用的对战组 */
void ShowSchedule(int event)//显示日程表
{
int index, r, m
fprintf( stdout, "共有\n%d 个选手", players-event )
fprintf( stdout, "\n")
for (r=1r <= players/2r++) fprintf( stdout, " 好戏%d ", r)
fprintf( stdout, "\n" )
fprintf( stdout, "+-")
for (r=1r <= (players/2)*6-2r++) fprintf( stdout, "-" )
fprintf( stdout, "\n" )
index = 1
for (r=1r <= players-1r++) {
fprintf( stdout, "第%2d轮 |", r)
for (m=1m <= players/2m++) {
fprintf( stdout, " %2d vs%2d ", tourn[index].one, tourn[index].two )
index++
}
fprintf( stdout, "\n" )
}
fprintf( stdout, "\n%d 次尝试对战分组\n\n", totalChecks )
}
void ClearArrays()//清除以前的标记
{
int i
for (i=0i <= MaxCombinationsi++) { tourn[i].one = 0tourn[i].two = 0}
for (i=0i <= Maxplayers/2i++) mList[i] = 0
for (i=0i <= MaxCombinationsi++) { cList[i].one = 0cList[i].two = 0}
for (i=0i <= MaxCombinationsi++) cUsed[i] = 0
}
void doSchedule(int flag)//安排比赛日程
{
players = 4
if (z != players)
players = z
while (players <= Maxplayers) {
combinations = players/2 * (players-1)
totalChecks = 0
ClearArrays()
/* 初始化所有比赛对战图 */ /* a */
m = 1 /* b 1 2 3 4 5 */
for (a=1 a <playersa++)/* 1 */
for (b=a+1b <=playersb++) { /* 2 . */
cList[m].one = a /* 3 . . */
cList[m].two = b /* 4 . . . */
m++ /* 5 . . . . */
}
roundCount = 1
index = 1
while (roundCount <= players-1) {
matchCount = 1
round_set = 0
for (i=0i <= Maxplayers/2i++) mList[i] = 0
startC = roundCount
/* 开始查找,找到合适的对战组加入当前的比赛轮次*/
/*
注:因为算法已经被验证对任何一个选手数目,总会有一个解决方案,所以这里不怕会有死循环
*/
while (matchCount <= players/2) {
c = combinations + 1
while (c >combinations) {
c = startC
/* 查找下一个可以加入当前轮次的对战组 */
while ((c <= combinations) &&
((round_set &(1 <<cList[c].one)) ||
(round_set &(1 <<cList[c].two)) ||
(cUsed[c])
)
)
c++
if (c >combinations) {
/* 没有找到合适的对战组,故回 */
do {
mList[matchCount] = 0
matchCount--
index--
round_set &= ~(1 <<cList[mList[matchCount]].one)
round_set &= ~(1 <<cList[mList[matchCount]].two)
cUsed[mList[matchCount]] = FALSE
tourn[index].one = 0
tourn[index].two = 0
/*cList:已经使用的组,mList:合适的对战组*/
} while (cList[mList[matchCount] ].one !=
cList[mList[matchCount]+1].one)
startC = mList[matchCount] + 1
}
}
/* 找到一个合适的对战组,并放到当前比赛轮次中
*/
tourn[index] = cList[c]
totalChecks++
/*动态显示进度*/
if ((totalChecks % 1000) == 0) fprintf( stdout, "%d/033A/n", totalChecks )
cUsed[c] = TRUE
mList[matchCount] = c
startC = 1
round_set |= (1 <<cList[c].one)
round_set |= (1 <<cList[c].two)
index++
matchCount++
}
/* 进入下一轮比赛的安排 */
roundCount++
}
fprintf( stdout, " " )
ShowSchedule( flag )
break
}
void main()
{
printf("请输入参赛队员的个数 n =2k= ")
scanf("%d",&z)
if(z%2 == 0) {
doSchedule(0)
}
else printf("输入参赛队员的个数 要为偶数! ")
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)