A. c语言课堂随机点名
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#defineMAXSTUDENT100
charName[MAXSTUDENT][16];
//读文件内保存的学生姓名
intreadName(constchar*fileName)
{
intpos,slen;
FILE*fp=fopen(fileName,"r");
if(fp==NULL)return0;
memset(Name,0,sizeof(Name));
pos=0;
while(!feof(fp)&&pos<MAXSTUDENT)
{
fgets(Name[pos],16,fp);
slen=strlen(Name[pos]);
if(slen>0)
{
slen--;
while(Name[pos][slen]==10||Name[pos][slen]==13)Name[pos][slen--]=0;//去掉字符串后的换行符
pos++;
}
}
printf("读入%d人姓名 ",pos);
fclose(fp);
returnpos;
}
voidmain()
{
charfileName[32];
intn,pos,loop;
charflag[100];
srand(time(NULL));
printf("请输入学生姓名文件名:");
scanf("%s",fileName);
n=readName(fileName);
if(n==0)
{
printf("读取错误,请确认文件%s是否名是否正确,文件的格式是否正确! ",fileName);
return;
}
getchar();
memset(flag,0,sizeof(flag));
while(1)
{
pos=rand()%n;
loop=0;
while(flag[pos])//可以保证每个人都点到一次
{
if(++loop>n)memset(flag,0,sizeof(flag));
pos=rand()%n;
}
flag[pos]=1;
printf("点%s",Name[pos]);
if(getchar()!=10)break;
}
}
B. 用c语言编一个上课点名系统
是作业吗?
如果不是作业的话,建议还是别这么麻烦,弄一张表把。
现在外国都流行用EXCEL抽人,EXCEL(新版本的,好像2010里面有),有一个 抽样的类型,能够从表中随机抽出数据。。
然后在用VLOOKUP显示人名就好了。。。
如果是作业的话。。。用C++,面向对象,秒杀级别的作业。。
新建一个STUDENT类,然后将学好和姓名设置成PUBLIC成员。
然后再新建一个STUDENT类数组,然后读入文件即可。。。关键还是在于TXT文件格式怎么分割的问题。。其实也不难,CSTRING里面有很丰富的成员方法,用一些来拼接就好。
最后再找在VC的库里面找一个随机函数,或者自己写一个也行。。。
秒杀级别的作业。。。。自己动手把楼主,很简单的说。。。
C. 随机点名程序设计 C语言编程
设置一个足够大的随机池,给每一个学生分配相同的空间,然后利用随机数来选取被点名的学生,同时对该学生所分配的空间和其他学生的空间进行缩减或增加。然后执行下一轮。
大致思路就是这样,希望能够帮到你哦~
D. c语言 课堂随机点名程序 跪求大神帮我修改正确!
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
#include <time.h>
func1(char stubuff[100][100],int stucnt);
func2(char stubuff[100][100],int stucnt);
struct Student
{
int stdno;
char name[20];
char sex[20];
};
int main()
{
FILE *fp;
int stucnt=0,x;
char line[100]="\0",stubuff[100][100];
char filename[20];
struct Student *st;
printf("\t\t\t欢迎使用课堂随机点名程序!\n\n");
printf("点名前请输入您要点名的班级:");
scanf("%s",filename);
fp=fopen(filename,"r");
while (fgets(line,99,fp)!=NULL)
{
strcpy(stubuff[stucnt++],line);
}
printf("该班一共有%d个学生\n",stucnt);
srand((unsigned)time(NULL));
printf("请选择:\n");
printf("1:开始点名\n2:查看全班具体情况\n3:结束程序\n");
printf("请输入您的选择:");
scanf("%d",&x);
switch(x)
{
case 1:
func1(stubuff[100][100],stucnt);break;
case 2:
func2(stubuff[100][100],stucnt);break;
case 3:
printf("\t\t\t谢谢使用!\n");
}
fclose(fp);
return 0;
}
func1(char stubuff[100][100],int stucnt)
{
int i,j,chou,tmp,sel[100]={0},flag;
do
{
printf("请输入这次要点名的人数:");
scanf("%d",&chou);
if (chou>stucnt)
{
printf("这个班没有这么多学生\n");
}
} while(chou>stucnt ||chou<0);
for (i=0;i<chou;i++)
{
flag=0;
tmp=rand()%stucnt+1;
for (j=0;j<i;j++)
{
if (sel[j]==tmp)
{
flag=1;
break;
}
}
if (flag==1)
{
i--;
}else
{
sel[i]=tmp;
}
}
printf("点名情况如下:\n");
printf("学号\t\t姓名\t性别\n");
for (i=0;i<chou;i++)
{
fflush(stdin);
getchar();
printf("%s",stubuff[sel[i]-1]);
}
}
func2(char stubuff[100][100],int stucnt)
{
int i;
for (i=0;i<stucnt;i++)
{
fflush(stdin);
getchar();
printf("%s",stubuff[i]);
}
}
E. 求c语言班级点名程序,高手们来帮帮忙啊
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct Student
{
char name[20];
bool IsRead;
}Student;
int main()
{
int i;
int select;
int mark=1;
//下面中你还可以加入一些学生,记得初始化的IsRead都是false
Student student[]=
{
{"张三",false},
{"李四",false},
{"王五",false},
{"刘六",false},
{"赵七",false}
};
printf("欢迎进入点门系统,以下是全班的花名册:\n");
for (i=0;i<sizeof(student)/sizeof(Student);i++)
printf("%s ",student[i].name);
printf("\n");
do
{
printf("请选择:\n1.点名\n2.显示没有点到的学生名字\n3.退出点名系统\n");
scanf("%d",&select);
system("cls");//如果是Linux系统,把cls改成clear。如果是其他系统请把这行注释掉,清频
if(1==select)
{
mark = 1;
while (1)
{
for(i=0;i<sizeof(student)/sizeof(Student);i++)
mark=mark*(student[i].IsRead? 1:0);
if(mark)
{
printf("你已经把全班点了个遍\n");
break;
}
srand(time(NULL));
i = rand()%(sizeof(student)/sizeof(Student));
if(!student[i].IsRead)
{
printf("点名:%s\n",student[i].name);
student[i].IsRead = true;
break;
}
}
}
else if (2==select)
{
for(i=0;i<sizeof(student)/sizeof(Student);i++)
{
if(!student[i].IsRead)
printf("%s ",student[i].name);
}
printf("\n");
}
else if(3==select)
{
printf("谢谢使用\n");
return 0;
}
}while(true);
return 0;
}
这可是我一个字一个字的打出来的,专门为你写的!~
F. 用C语言编写一个随机点名程序
例:
#include<stdio.h>/*standardinput&output*/
#include<stdlib.h>/*standardlibary*/
#include<string.h>/*string*/
#include<conio.h>/*ConsoleInput/Output*/
#include<time.h>
structstudentinfo/*学生信息的结构体*/
{
charsNo[5];/*学生编号*/
charsxueNo[14];/*学号*/
charsname[20];/*学生的姓名*/
}st[100];
charhash[100]={0};/*链表的数组*/
intmain()
{
inti=0,j=0,flag=0,RN,*a;
FILE*fp;
charch,filename[20]={0},line[100]={0};
printf("Pleaseinputfilename:");
//fflush(stdin);/*用来清空输入缓存,以便不影响后面输入的东西*/
gets(filename);/*键盘输入文件名*/
fp=fopen(filename,"r");/*openreadonly*/
printf("名单如下:\n");/*显示所有的学生信息*/
while(fgets(line,sizeof(line)-1,fp))
{
if(line[0]!='\n'&&line[0]!='')
{
sscanf(line,"%s%s%s\n",st[i].sNo,st[i].sxueNo,st[i].sname);/*文件输入*/
printf("%s\n%s\n%s\n",st[i].sNo,st[i].sxueNo,st[i].sname);/*打印出来*/
i++;/*统计人数*/
}
}
/*设置随机数种子*/
srand((unsigned)time(NULL));
/*sizeof(类型符)是计算类型所占字节数,sizeof(int)是int所占字节数,再乘以i,得到i个int型数据的总字节数。malloc函数用于动态开辟一块内存空间,参数为开辟的内存空间字节数,返回开辟的内存空间的首地址指针。*/
a=(int*)malloc(sizeof(int)*i);
memset(a,-1,sizeof(a));/*将已开辟内存空间a的第4个字节设置为-1*/
printf("按空格键点名,其他键退出:");
fflush(stdin);
while((ch=getch())=='')
/*while(!(ch=getch())==NULL)*/
{
if(flag==i)/*如果flag等于总人数*/
{
printf("%s\n","点名结束");
break;
}
RN=rand()%i;/*产生一个随机数*/
while(hash[RN]==1)/*判断有没有完成某个一个学生点名*/
RN=rand()%i;/*产生随机数*/
flag++;/*计数*/
printf("\n~~~~~\n%s\n%s\n%s\n------------\n",st[RN].sNo,st[RN].sxueNo,st[RN].sname);/*输出学生的信息*/
hash[RN]=1;
}
}
(6)c语言怎么点名扩展阅读:
printf函数使用注意事项
1、域宽
%d:按整型数据的实际长度输出。
如果想输出指定宽度可以指定域宽,%md--&gt;m域宽,打印出来以后,在控制台上,显示m位;
如果我们要打印的数的位数如果超过我们设定m则原样输出;
如果我们要打印的数的位数如果小于我们设定的位数,则补空白,具体如下:
如果m为正数,则左对齐(左侧补空白);
如果m为负数,则右对齐(右侧补空白)。
2、转义字符
如果想输出字符"%",则应该在“格式控制”字符串中用连续两个%表示。
如:printf("%f%%",1.0/3);输出结果:0.333333%。
G. 求C语言做的学生点名程序(急......~!!!!!)
#include<stdio.h>
#include<string.h>
main()
{
int a=0,b=0,c=0,d=0;
char chr='O';
char t[]="noEnd";
//char *m[]={"20013011001杜永宁","20013011002王传华","20013011003殷泳","20013011004杨柳青"};
printf("........... A 开始点名.........end 结束点名...........\n");
printf("........... B 显示显示所有同学点名情况 ...........\n");
printf("........... C 保存点名 ...........\n");
printf("........... D 退出点名系统 ...........\n");
FILE *ft;
//fp=fopen("myfile.dat","r");
ft=fopen("baochun.txt","w");
// fscanf(fp,"%s,%s,%s,%s",m[0],m[1],m[2],m[3]);
while(chr!='x')
{
scanf("%c",&chr);
switch(chr)
{
case 'A':
while(strcmp(t,"over")!=0)
{
if(a+b+c+d==12) {a=b=c=d=0; printf ("清零!\n");}
scanf("%s",&t);
if(strcmp(t,"20013011001杜永宁")==0)
{
a++;
if(a<=3) printf("杜永宁已被点%d次\n",a);
if(a>3)
{ a=3;
printf("杜永宁已被点完三次\n");
}
}
else if(strcmp(t,"20013011002王传华")==0) {
b++;
if(b<=3) printf("王传华已被点%d次\n",b);
if(b>3)
{b=3;
printf("王传华已被点完三次\n");}
}
else if(strcmp(t,"20013011003殷泳")==0){
c++;
if(c<=3) printf("殷泳已被点%d次\n",c);
if(c>3)
{c=3;
printf("殷泳已被点完三次\n");
}
}
else if(strcmp(t,"20013011004杨柳青")==0) {
d++;
if(d<=3) printf("杨柳青已被点%d次\n",d);
if(d>3)
{d=3;
printf("杨柳青已被点完三次\n");
}
}
}break;
case 'B': {
printf("20013011001杜永宁已被点过名的次数为%d\n20013011002王传华已被点过名的次数为%d\ n20013011003殷泳已被点过名的次数为%d\n20013011004杨柳青已被点过名的次数为%d\n",a,b,c,d);}break;
case 'C':{ printf("保存成功\n");
fprintf(ft,"20013011001 杜永宁 已被点过名的次数为%d\n,20013011002 王传华已被点过名的次数为%d\n,20013011003 殷泳 已被点过名的次数为%d\n,20013011004 杨柳青已被点过名的次数为%d\n",a,b,c,d);}break;
default:break;
}
}//while(chr!='x');
}
H. 跪求c语言上课随机点名程序设计
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#defineSTU_NUM_MAX4
structStudentInfo//学生信息结构
{
charname[15];
intstu_id;
}stu[STU_NUM_MAX];
voidWriteData()//写入学生信息
{
FILE*fp;
intstu_num=4;
for(inti=0;i<stu_num;i++)
{
printf("请输入第%d个学生的姓名:",i+1);
scanf("%s",stu[i].name);
printf("请输入第%d个学生的学号:",i+1);
scanf("%d",&stu[i].stu_id);
}
if((fp=fopen("myfile.dat","ab"))==NULL)
{
printf("Can'topenfile ");
exit(1);
}
for(intj=0;j<stu_num;j++)
{
if(fwrite(&stu[j],sizeof(structStudentInfo),1,fp)!=1)
printf("Errorwritingfile. ");
}
fclose(fp);
}
voidTeacherDM(intstuID)//教师点名
{
FILE*fp;
boolfind_mark=false;
printf(" %s %s ","学号","姓名");
if((fp=fopen("myfile.dat","rb"))==NULL)
{
printf("Can'topenfile ");
exit(1);
}
inti=0;
do
{
fseek(fp,i*sizeof(structStudentInfo),SEEK_SET);
fread(&stu[i],sizeof(structStudentInfo),1,fp);
if(stu[i].stu_id==stuID)
{
printf(" %4d %s ",stu[i].stu_id,stu[i].name);
printf(" 请【%s】同学回答某某问题. ",stu[i].name);
find_mark=true;
break;
}
i++;
}while(!feof(fp));
if(!find_mark)printf(" 未能找到学生号为:%d的记录! ",stuID);
fclose(fp);
}
voidmain(void)
{
intstuID[4]={2013011001,2013011002,2013011003,2013011004};
//WriteData();
srand((unsigned)time(NULL));//随机种子
TeacherDM(stuID[rand()%(3-0+1)+0]);
}
运行效果截图:
另外多说一句,你所说的公正性,是不是指被点名过的同学不会再次被随机点名到。如果是这个意思,那么你可以通过数组来设置它,即把点名过的同学的学号或姓名保存到一维数组里,随机判断时只需循环检查下该同学是否已被点名过。这里就留给你做了。
I. c语言 随机点名
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#defineSTU_NUM_MAX64//假设最多有64个学生
structStudent
{
charname[10];
intstuID;
}stu[STU_NUM_MAX];
intexist[STU_NUM_MAX];//用以保存被点过名
staticintindex=0;//记住点名的次数
voidIitialize(){
for(inti=0;i<STU_NUM_MAX;i++)exist[i]=0;
}
boolIsExist(intid){
for(inti=0;i<STU_NUM_MAX;i++)
if(exist[i]==id)returntrue;//已存在
returnfalse;//不存在
}
voidAdd()//添加数据
{
FILE*fp;
intstu_num;
printf(" ?:");
scanf("%d",&stu_num);
for(inti=0;i<stu_num;i++){
printf(" ");
printf(" PleaseinputstudentID:");
scanf("%d",&stu[i].stuID);
printf(" Pleaseinputstudentname:");
scanf("%s",stu[i].name);
fflush(stdin);
}
if((fp=fopen("stu.dat","ab"))==NULL) {
printf("Can'topenfile ");
exit(1);
}
for(intj=0;j<stu_num;j++)
{
if(fwrite(&stu[j],sizeof(structStudent),1,fp)!=1)
printf("Errorwritingfile. ");
}
fclose(fp);
}
voidrollcall()//随机点名
{
FILE*fp;
if((fp=fopen("stu.dat","rb"))==NULL)
{
printf("Can'topenfile. ");
exit(1);
}
srand((unsigned)time(NULL));
inti=0;
intrandID=rand()%(64-1+1)+1;//1~64
printf(" 随机点到的学号为:%d %s %s ",randID,"StuID","StuName");
do
{
fseek(fp,i*sizeof(structStudent),SEEK_SET);
if(fread(&stu[i],sizeof(structStudent),1,fp))
{
if(stu[i].stuID==randID&&!IsExist(randID)){
printf(" %4d %5s ",stu[i].stuID,stu[i].name);
exist[index++]=randID;
break;}
}
i++;
}while(!feof(fp));
fclose(fp);
}
intmain()
{
intselect=0;
charanswer='y';
Iitialize();
do
{
printf("1.添加数据2.随机点名3.退出 请选择:");
fflush(stdin);
scanf("%d",&select);
switch(select)
{
case1:
Add();
break;
case2:
rollcall();
break;
case3:
return0;
}
fflush(stdin);
printf("Youwanttocontinue?:");
scanf("%c",&answer);
}while(answer=='y'||answer=='Y');
return0;
}
上面的代码,我留下几个细节问题留给你自己学着解决,都是很简单的:
上面的代码,我没有对重复的学号作判断。
上面的代码,我没有把点名存放到另一个文件,而是用数组替代(可以实现的也很简单)。我怕写得代码太多,网络限制提交。
上面的代码,是测试数据,stu.dat目标文件并没有64个学生,我只写入了12条数据。
上面的代码,我没有对数据数量(最多64条)作判断。