用c语言编写一个自动点名系统,具体要求如下一、具体题目: 设计一个供教师上课使用的
用c语言编写一个自动点名系统,具体要求如下一、具体题目:设计一个供教师上课使用的自动点名系统。基本要求如下:学生名单存在一个文本文件students.txt中(见附件),...
用c语言编写一个自动点名系统,具体要求如下一、具体题目:
设计一个供教师上课使用的自动点名系统。
基本要求如下:
学生名单存在一个文本文件students.txt中(见附件),格式
学号 姓名
19210201 祝福
19210202 史文明
……
系统启动后,自动从文本文件中读取学生信息。每次选取(点击)相应功能,系统随机抽取一个学生,显示给老师,用作点名。
进一步的要求如下:
界面优化
一般用文本界面显示菜单,自行设计和完成菜单功能,供老师点选,可以考虑动态显示系统选择的过程。有能力的同学可以设计成图形界面。
功能强化
考虑公平性,每个学生被点中的概率和次数尽量一样,不能出现一个学生被点名两次了,还有学生没被点中的情况。(可以使用另外一个文本文件,记录学生被点名的次数,或者在students.txt文件加入一个记录学生被点名次数的字段)
急求这个题目的程序设计,能帮忙看一下吗。谢谢啦 展开
设计一个供教师上课使用的自动点名系统。
基本要求如下:
学生名单存在一个文本文件students.txt中(见附件),格式
学号 姓名
19210201 祝福
19210202 史文明
……
系统启动后,自动从文本文件中读取学生信息。每次选取(点击)相应功能,系统随机抽取一个学生,显示给老师,用作点名。
进一步的要求如下:
界面优化
一般用文本界面显示菜单,自行设计和完成菜单功能,供老师点选,可以考虑动态显示系统选择的过程。有能力的同学可以设计成图形界面。
功能强化
考虑公平性,每个学生被点中的概率和次数尽量一样,不能出现一个学生被点名两次了,还有学生没被点中的情况。(可以使用另外一个文本文件,记录学生被点名的次数,或者在students.txt文件加入一个记录学生被点名次数的字段)
急求这个题目的程序设计,能帮忙看一下吗。谢谢啦 展开
4个回答
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
//---------------data structure----------------
struct student{
char id[30];
char name[30];
int called_times;
};
struct node{
struct node *next;
struct student student;
};
//------------end of data structure----------------
//------------global data-----------------------
static struct node *list_entry;
static int num_called, num_uncalled;
//------------end of global data-------------------
//------------list functions----------------------
static struct node *newnode(struct student *student){
struct node *node;
if((node = (struct node *)malloc(sizeof(struct node))) == NULL)
exit(-1);
memcpy(&node->student, student, sizeof(struct student));
return node;
}
static void append(struct node *node){
node->next = list_entry;
list_entry = node;
}
//------------end of list functions--------------
//------------file operations------------------
static void read_data(FILE *file){
rewind(file);
while(1){
struct student buf;
struct node *node;
int res = fread(&buf, sizeof(struct student), 1, file);
if(res != 1){
break;
}else{
if((node = newnode(&buf)) == NULL)
exit(-1);
append(node);
if(buf.called_times == 1)
++num_called;
else
++num_uncalled;
}
}
}
static void save_data(FILE *file){
rewind(file);
struct node *node;
int cnt = 0;
for(node = list_entry; node;)
if(fwrite(&node->student, sizeof(struct student), 1, file) != 1)
break;
else{
list_entry = node;
node = node->next;
free(list_entry);
++cnt;
}
printf("%d students saved!\n", cnt);
}
//------------end of file operations------------
//------------cmd functions---------------------
static void show_menu(void){
printf("\n\t-------welcome to rolling system---------\
\n\t you can press the CAPITAL charactor or item number to operate.\
\n\t other charactor are not recognized.\
\n\t1.show_(A)ll\
\n\t2.show_(C)alled\
\n\t3.show_(U)ncaled\
\n\t4.add_(I)tem\
\n\t5.(D)el_item\
\n\t6.call_a_(N)ame\
\n\t7.(Q)uit\
\n\t--------------------------------------\
\n\tenter your choice:");
}
static void show_title(void){
printf("%-30s%-30s\n", "ID", "NAME");
}
static void show_item(struct student *student){
printf("%-30s%-30s\n", \
student->id, \
student->name \
);
}
static void show_all(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
show_item(&node->student);
}
static void show_called(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 1)
show_item(&node->student);
}
static void show_uncalled(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 0)
show_item(&node->student);
}
static void refresh(void){
struct node *node;
num_uncalled += num_called;
num_called = 0;
for(node = list_entry; node; node = node->next)
node->student.called_times = 0;
}
static void call_a_name(void){
struct node *node;
int index;
srand(time(0));
if(num_uncalled == 0)
refresh(); // all called_times reset to 0
show_title();
index = rand() % num_uncalled;
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 0){
if(index-- == 0)
break;
}
show_item(&node->student);
node->student.called_times = 1;
++num_called;
--num_uncalled;
}
void add_item(void){
struct node *node;
struct student student;
student.called_times = 0;
printf("pls enter new item as follows\n");
show_title();
scanf("%s %s",\
student.id,
student.name
);
node = newnode(&student);
append(node);
++num_uncalled;
}
void del_item(void){
char id[30];
struct node *node, *ahead;
printf("Pls enter the ID you want to delete:");
scanf("%s", id);
for(ahead = node = list_entry; node; ahead = node, node = node->next){
if(strcmp(id, node->student.id)) //id unmatched
continue;
else{ //matched
ahead->next = node->next; //del node;
node->student.called_times == 0? --num_uncalled : --num_called;
free(node);
node = ahead->next;
}
}
}
//------------end of cmd functions--------------
int main(void){
FILE *file;
char *filename = "student.txt";
if((file = fopen(filename, "r")) == NULL)
printf("cannot open %s\n", filename), exit(-2);
read_data(file);
fclose(file);
while(1){
char cmd;
int select_quit_sign = 0;
printf("total %d students, called %d, uncalled %d.\n", num_called + num_uncalled, num_called, num_uncalled);
show_menu();
scanf("%c", &cmd);
printf("you cmd is:%c\n", cmd);
switch(cmd){
case '1':case 'a':case 'A':
show_all();
break;
case '2':case 'c':case 'C':
show_called();
break;
case '3':case 'u':case 'U':
show_uncalled();
break;
case '4':case 'i':case 'I':
add_item();
break;
case '5':case 'd':case 'D':
del_item();
break;
case '6':case 'n':case 'N':
call_a_name();
break;
case '7':case 'q':case 'Q':
select_quit_sign = 1;
break;
default:
printf("unknown command!\n");
break;
}
printf("--------"); //bottom of output
if(select_quit_sign == 1)
break;
scanf("%*c"); //clear input buffer
}
if((file = fopen(filename, "w")) == NULL)
printf("cannot open %s\n", filename), exit(-2);
save_data(file);
fclose(file);
return 0;
}
#include<stdlib.h>
#include<string.h>
#include<time.h>
//---------------data structure----------------
struct student{
char id[30];
char name[30];
int called_times;
};
struct node{
struct node *next;
struct student student;
};
//------------end of data structure----------------
//------------global data-----------------------
static struct node *list_entry;
static int num_called, num_uncalled;
//------------end of global data-------------------
//------------list functions----------------------
static struct node *newnode(struct student *student){
struct node *node;
if((node = (struct node *)malloc(sizeof(struct node))) == NULL)
exit(-1);
memcpy(&node->student, student, sizeof(struct student));
return node;
}
static void append(struct node *node){
node->next = list_entry;
list_entry = node;
}
//------------end of list functions--------------
//------------file operations------------------
static void read_data(FILE *file){
rewind(file);
while(1){
struct student buf;
struct node *node;
int res = fread(&buf, sizeof(struct student), 1, file);
if(res != 1){
break;
}else{
if((node = newnode(&buf)) == NULL)
exit(-1);
append(node);
if(buf.called_times == 1)
++num_called;
else
++num_uncalled;
}
}
}
static void save_data(FILE *file){
rewind(file);
struct node *node;
int cnt = 0;
for(node = list_entry; node;)
if(fwrite(&node->student, sizeof(struct student), 1, file) != 1)
break;
else{
list_entry = node;
node = node->next;
free(list_entry);
++cnt;
}
printf("%d students saved!\n", cnt);
}
//------------end of file operations------------
//------------cmd functions---------------------
static void show_menu(void){
printf("\n\t-------welcome to rolling system---------\
\n\t you can press the CAPITAL charactor or item number to operate.\
\n\t other charactor are not recognized.\
\n\t1.show_(A)ll\
\n\t2.show_(C)alled\
\n\t3.show_(U)ncaled\
\n\t4.add_(I)tem\
\n\t5.(D)el_item\
\n\t6.call_a_(N)ame\
\n\t7.(Q)uit\
\n\t--------------------------------------\
\n\tenter your choice:");
}
static void show_title(void){
printf("%-30s%-30s\n", "ID", "NAME");
}
static void show_item(struct student *student){
printf("%-30s%-30s\n", \
student->id, \
student->name \
);
}
static void show_all(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
show_item(&node->student);
}
static void show_called(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 1)
show_item(&node->student);
}
static void show_uncalled(void){
struct node *node;
show_title();
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 0)
show_item(&node->student);
}
static void refresh(void){
struct node *node;
num_uncalled += num_called;
num_called = 0;
for(node = list_entry; node; node = node->next)
node->student.called_times = 0;
}
static void call_a_name(void){
struct node *node;
int index;
srand(time(0));
if(num_uncalled == 0)
refresh(); // all called_times reset to 0
show_title();
index = rand() % num_uncalled;
for(node = list_entry; node; node = node->next)
if(node->student.called_times == 0){
if(index-- == 0)
break;
}
show_item(&node->student);
node->student.called_times = 1;
++num_called;
--num_uncalled;
}
void add_item(void){
struct node *node;
struct student student;
student.called_times = 0;
printf("pls enter new item as follows\n");
show_title();
scanf("%s %s",\
student.id,
student.name
);
node = newnode(&student);
append(node);
++num_uncalled;
}
void del_item(void){
char id[30];
struct node *node, *ahead;
printf("Pls enter the ID you want to delete:");
scanf("%s", id);
for(ahead = node = list_entry; node; ahead = node, node = node->next){
if(strcmp(id, node->student.id)) //id unmatched
continue;
else{ //matched
ahead->next = node->next; //del node;
node->student.called_times == 0? --num_uncalled : --num_called;
free(node);
node = ahead->next;
}
}
}
//------------end of cmd functions--------------
int main(void){
FILE *file;
char *filename = "student.txt";
if((file = fopen(filename, "r")) == NULL)
printf("cannot open %s\n", filename), exit(-2);
read_data(file);
fclose(file);
while(1){
char cmd;
int select_quit_sign = 0;
printf("total %d students, called %d, uncalled %d.\n", num_called + num_uncalled, num_called, num_uncalled);
show_menu();
scanf("%c", &cmd);
printf("you cmd is:%c\n", cmd);
switch(cmd){
case '1':case 'a':case 'A':
show_all();
break;
case '2':case 'c':case 'C':
show_called();
break;
case '3':case 'u':case 'U':
show_uncalled();
break;
case '4':case 'i':case 'I':
add_item();
break;
case '5':case 'd':case 'D':
del_item();
break;
case '6':case 'n':case 'N':
call_a_name();
break;
case '7':case 'q':case 'Q':
select_quit_sign = 1;
break;
default:
printf("unknown command!\n");
break;
}
printf("--------"); //bottom of output
if(select_quit_sign == 1)
break;
scanf("%*c"); //clear input buffer
}
if((file = fopen(filename, "w")) == NULL)
printf("cannot open %s\n", filename), exit(-2);
save_data(file);
fclose(file);
return 0;
}
--
2022-12-05 广告
2022-12-05 广告
图形化编程简单理解为用积木块形式编程,scratch和python也是其中的一种,属于入门级编程,以其简单生动的画面获得无数学生的喜爱,深圳市创客火科技有限公司是一家做教育无人机的公司,旗下有编程无人机,积木无人机及室内外编队,每款飞机含有...
点击进入详情页
本回答由--提供
展开全部
编写一个自动点名系统
这个开发平台
这个开发平台
追问
😊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你好!程序完成了吗?可以尝试完成
更多追问追答
追问
你知道怎么写吗
追答
可以按照你的题目要求实现,留下你的,。企,。鹅,。号,。吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
2458194647
可以写的,
更多追问追答
追问
能帮忙写一下吗,非常感谢
追答
额额 我要是跟你说 收费的话
你还需要吗?
2458194647
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询