下载
加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 C语言随机点名

C语言随机点名.doc

C语言随机点名

我用命来换你的一世孤独
2019-01-11 0人阅读 举报 0 0 暂无简介

简介:本文档为《C语言随机点名doc》,可适用于IT/计算机领域

#include<stdioh>#include<stdlibh>#include<timeh>#defineSTUNUMMAX假设最多有个学生structStudent{charnameintstuID}stuSTUNUMMAXintexistSTUNUMMAX用以保存被点过名staticintindex=记住点名的次数voidIitialize(){for(inti=i<STUNUMMAXi)existi=}boolIsExist(intid){for(inti=i<STUNUMMAXi)if(existi==id)returntrue已存在returnfalse不存在}voidAdd()添加数据{FILE*fpintstunumprintf("ttYouwanttoinputthenumberofstudent:")scanf("d",stunum)for(inti=i<stunumi){printf("n")printf("ttPleaseinputstudentID:")scanf("d",stuistuID)printf("ttPleaseinputstudentname:")scanf("s",stuiname)fflush(stdin)}if((fp=fopen("studat","ab"))==){printf("Can'topenfilen")exit()}for(intj=j<stunumj){if(fwrite(stuj,sizeof(structStudent),,fp)!=)printf("Errorwritingfilen")}fclose(fp)}voidrollcall()随机点名{FILE*fpif((fp=fopen("studat","rb"))==){printf("Can'topenfilen")exit()}srand((unsigned)time())inti=intrandID=rand()()~printf("tt随机点到的学号为:dnttstsn",randID,"StuID","StuName")do{fseek(fp,i*sizeof(structStudent),SEEKSET)if(fread(stui,sizeof(structStudent),,fp)){if(stuistuID==randID!IsExist(randID)){printf("ttdtsn",stuistuID,stuiname)existindex=randIDbreak}}i}while(!feof(fp))fclose(fp)}intmain(){intselect=charanswer='y'Iitialize()do{printf("添加数据随机点名退出n请选择:")fflush(stdin)scanf("d",select)switch(select){case:Add()breakcase:rollcall()breakcase:return}fflush(stdin)printf("Youwanttocontinue:")scanf("c",answer)}while(answer=='y'||answer=='Y')return}#include<stdioh>#include<stdlibh>#include<stringh>#include<conioh>#include<timeh>structstudentinfo{charsNocharsxueNocharsname}stintmain(){inti=,j=,k,flag,RN,*aFILE*fpcharch,filename={},line={}printf("Pleaseinputfilename:")fflush(stdin)gets(filename)fp=fopen(filename,"r")printf("名单如下:n")while(fgets(line,sizeof(line),fp)){if(line!='n'line!=''){sscanf(line,"sssn",stisNo,stisxueNo,stisname)printf("snsnsn",stisNo,stisxueNo,stisname)i}}srand((unsigned)time())a=(int*)malloc(sizeof(int)*i)memset(a,,sizeof(a))printf("按任意键点名:")fflush(stdin)while(!(ch=getch())==){RN=rand()iflag=for(k=k<ik){if(RN==ak){flag=break}}if(flag){aj=RNjprintf("n~~~~~nsnsnsnn",stRNsNo,stRNsxueNo,stRNsname)}}}#include<stdioh>#include<stdlibh>#include<timeh>#defineSTUNUMMAXstructStudentInfo学生信息结构{charnameintstuid}stuSTUNUMMAXvoidWriteData()写入学生信息{FILE*fpintstunum=for(inti=i<stunumi){printf("请输入第d个学生的姓名:",i)scanf("s",stuiname)printf("请输入第d个学生的学号:",i)scanf("d",stuistuid)}if((fp=fopen("myfiledat","ab"))==){printf("Can'topenfilen")exit()}for(intj=j<stunumj){if(fwrite(stuj,sizeof(structStudentInfo),,fp)!=)printf("Errorwritingfilen")}fclose(fp)}voidTeacherDM(intstuID)教师点名{FILE*fpboolfindmark=falseprintf("ntsttsn","学号","姓名")if((fp=fopen("myfiledat","rb"))==){printf("Can'topenfilen")exit()}inti=do{fseek(fp,i*sizeof(structStudentInfo),SEEKSET)fread(stui,sizeof(structStudentInfo),,fp)if(stuistuid==stuID){printf("tdtsn",stuistuid,stuiname)printf("nnt请【s】同学回答某某问题n",stuiname)findmark=truebreak}i}while(!feof(fp))if(!findmark)printf("ntt未能找到学生号为:d的记录!n",stuID)fclose(fp)}voidmain(void){intstuID={,,,}WriteData()srand((unsigned)time())随机种子TeacherDM(stuIDrand()())}#include<stdlibh>#include<stdioh>#include<mathh>#defineSIZEstructstudent{charnumcharnameinttime}stdSIZEvoidsave(){intiFILE*fpif((fp=fopen("myfiledat","rb"))==){printf("文件打开失败n")exit()}for(i=i<SIZEi)沈阳航院设计用纸if(fwrite(stdi,sizeof(structstudent),,fp)!=)*将内存中的数据输出到磁盘文件中*printf("文件保存失败n")}voidmain(){intj,icharcFILE*fpif((fp=fopen("myfiledat","ab"))==){printf("文件打开失败n")exit()}for(i=i<SIZEi)fread(stdi,sizeof(structstudent),,fp)*将fp所指向的文件中的数据存储到数组std中*printf("*************欢迎使用上课随机点名程序**************n")printf("******输入a:显示所有同学名情况*********n")printf("******输入d:开始点名*********n")printf("******输入s:保存点名*********n")printf("******输入b:点名次数归零*********n")printf("******输入q:退出*********n")printf("******************************************n")while(){c=getchar()switch(c){case'a':for(i=i<SIZEi)printf("ttsttstt被点名d次n",stdinum,stdiname,stditime)breakcase's':save()printf("****文件保存成功!退出请输入q****n")breakcase'b':for(i=i<SIZEi)沈阳航院设计用纸stditime=printf("点名次数归dn",stditime)breakcase'q':exit()case'd':loop:j=rand()*调用rand的函数进行点名*if(j==){stdtimeprintf("ttsttsn",stdjnum,stdjname)}elseif(j==){stdtimeprintf("ttsttsn",stdjnum,stdjname)}elseif(j==){stdtimeprintf("ttsttsn",stdjnum,stdjname)}elseif(j==){stdtimeprintf("ttsttsn",stdjnum,stdjname)}elsegotoloopbreak}}fclose(fp)}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

文档小程序码

使用微信“扫一扫”扫码寻找文档

1

打开微信

2

扫描小程序码

3

发布寻找信息

4

等待寻找结果

我知道了
评分:

/16

C语言随机点名

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利