C++随机点名程序代码(c语言课堂随机点名程序)
c语言 课堂随机点名程序 跪求大神帮我修改正确!
#include stdio.h
#include stdlib.h
#includestring.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 (choustucnt)
{
printf("这个班没有这么多学生\n");
}
} while(choustucnt ||chou0);
for (i=0;ichou;i++)
{
flag=0;
tmp=rand()%stucnt+1;
for (j=0;ji;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;ichou;i++)
{
fflush(stdin);
getchar();
printf("%s",stubuff[sel[i]-1]);
}
}
func2(char stubuff[100][100],int stucnt)
{
int i;
for (i=0;istucnt;i++)
{
fflush(stdin);
getchar();
printf("%s",stubuff[i]);
}
}
用c shap编写随机点名的程序代码
Form1.Designer.cs的代码:
namespace 随机点名
{
partial class Form1
{
/// summary
/// 必需的设计器变量。
/// /summary
private System.ComponentModel.IContainer components = null;
/// summary
/// 清理所有正在使用的资源。
/// /summary
/// param name="disposing"如果应释放托管资源,为 true;否则为 false。/param
protected override void Dispose(bool disposing)
{
if (disposing (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
/// summary
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// /summary
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.txt = new System.Windows.Forms.TextBox();
this.lbl = new System.Windows.Forms.Label();
this.lbl1 = new System.Windows.Forms.Label();
this.lbl2 = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
this.tm = new System.Windows.Forms.Timer(this.components);
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(171, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "添加名单";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txt
//
this.txt.Location = new System.Drawing.Point(52, 12);
this.txt.Name = "txt";
this.txt.Size = new System.Drawing.Size(93, 21);
this.txt.TabIndex = 1;
//
// lbl
//
this.lbl.AutoSize = true;
this.lbl.BackColor = System.Drawing.Color.Lime;
this.lbl.Font = new System.Drawing.Font("楷体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl.ForeColor = System.Drawing.Color.Red;
this.lbl.Location = new System.Drawing.Point(234, 110);
this.lbl.Name = "lbl";
this.lbl.Size = new System.Drawing.Size(75, 20);
this.lbl.TabIndex = 2;
this.lbl.Text = "OOOOOO";
//
// lbl1
//
this.lbl1.AutoSize = true;
this.lbl1.BackColor = System.Drawing.SystemColors.Control;
this.lbl1.Font = new System.Drawing.Font("楷体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl1.Location = new System.Drawing.Point(234, 70);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(75, 20);
this.lbl1.TabIndex = 3;
this.lbl1.Text = "OOOOOO";
//
// lbl2
//
this.lbl2.AutoSize = true;
this.lbl2.BackColor = System.Drawing.SystemColors.Control;
this.lbl2.Font = new System.Drawing.Font("楷体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lbl2.Location = new System.Drawing.Point(234, 147);
this.lbl2.Name = "lbl2";
this.lbl2.Size = new System.Drawing.Size(75, 20);
this.lbl2.TabIndex = 4;
this.lbl2.Text = "OOOOOO";
//
// button2
//
this.button2.Location = new System.Drawing.Point(300, 214);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 5;
this.button2.Text = "开始";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// tm
//
this.tm.Tick += new System.EventHandler(this.tm_Tick);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(22, 55);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(100, 140);
this.richTextBox1.TabIndex = 6;
this.richTextBox1.Text = "名单";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(187, 117);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(41, 12);
this.label1.TabIndex = 7;
this.label1.Text = "中奖者";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(410, 261);
this.Controls.Add(this.label1);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.lbl2);
this.Controls.Add(this.lbl1);
this.Controls.Add(this.lbl);
this.Controls.Add(this.txt);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txt;
private System.Windows.Forms.Label lbl;
private System.Windows.Forms.Label lbl1;
private System.Windows.Forms.Label lbl2;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Timer tm;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Label label1;
}
}
Form1.cs的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 随机点名
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String[] str=new String[100];
int n = 0;
private void button1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txt.Text)) {
MessageBox.Show("输入为空!");
}
else {
str[n] = txt.Text;
richTextBox1.AppendText(str[n]+"\n");
MessageBox.Show("添加成功!");
n++;
}
}
int l = 0;
private void button2_Click(object sender, EventArgs e)
{
if (l == 0) {
tm.Start();
button2.Text = "停止";
l = 1;
}
else if (l == 1) {
tm.Stop();
button2.Text="开始";
l = 0;
}
}
static int k = 0;
private void tm_Tick(object sender, EventArgs e)
{
if (n 3)
{ tm.Stop();
MessageBox.Show("名单太少,抽奖方式太浪费");
button2.Text = "开始";
}
else
{
if (k == 0) {
lbl1.Text = str[n-1];
lbl.Text = str[k];
lbl2.Text = str[k+1];
k++;
}
else if (k 0kn-1 )
{
lbl1.Text = str[k-1];
lbl.Text = str[k];
lbl2.Text = str[k+1 ];
k++;
}
else {
lbl.Text = str[k];
lbl1.Text = str[n-2];
lbl2.Text = str[0];
k = 0;
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
richTextBox1.AppendText("\n");
}
}
}
Program.cs的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 随机点名
{
static class Program
{
/// summary
/// 应用程序的主入口点。
/// /summary
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
////给分吧,我的q2472591219,若需要加我,我将实例打包给你
求C++的随机点名程序。。。要有随机点名和顺序点名
1、使用UrlDownLoadToFile这个API下载指定url的学生名单(#includeurlmon.h #pragma comment(lib, "urlmon.lib"))
2、使用fopen读取学生名单到一个char*的缓冲区, 使用stl string来处理这段缓冲区, 并使用stl vectorSStudentInfo* 存储学生信息
struct SStudentInfo
{
};
vectorSStudentInfo* m_vInfo;
3、使用C语言随机函数取得随机数,
srand((unsigned)time(0)); int rid = rand()%m_vInfo.size() - 1; SStudentInfo *pInfo = m_vInfo[rid];
4、将pInfo里面的信息显示到界面
界面可以使用MFC, 如果使用控制台做的话也很方便
我只提供一个思路
如果要我提供源码, 你必须告诉我你的那个网站是什么, 我需要分析你的网站信息来编写通过班级选择性加载
跪求c语言上课随机点名程序设计
#includestdio.h
#include?stdlib.h
#include?time.h
#define??STU_NUM_MAX?4
struct?StudentInfo??//?学生信息结构
{
?char?name[15];
?int?stu_id;
}stu[STU_NUM_MAX];
void?WriteData()??//写入学生信息
{
FILE?*fp;
int?stu_num=4;
???
for?(int?i=0;istu_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't?open?file\n");
exit(1);
}
for?(int?j=0;jstu_num;j++)
{
if(fwrite(stu[j],sizeof(struct?StudentInfo),1,fp)!=1)
?printf("Error?writing?file.\n");
}
fclose(fp);
}
void?TeacherDM(int?stuID)?//?教师点名
{
FILE?*fp;
bool?find_mark=false;
????
printf("\n\t%s\t\t%s\n","学号","姓名");?
if((fp=fopen("myfile.dat","rb"))==NULL)?
{
printf("Can't?open?file\n");
exit(1);
}
????int?i=0;
do
{
????????fseek(fp,i*sizeof(struct?StudentInfo),SEEK_SET);
fread(stu[i],sizeof(struct?StudentInfo),1,fp);?
if(stu[i].stu_id==stuID)
{
printf("\t%4d\t%s\n",stu[i].stu_id,stu[i].name);
printf("\n\n\t请【%s】同学回答某某问题.\n",stu[i].name);
find_mark=true;
break;
}
i++;
}while(!feof(fp));
if(!find_mark)?printf("\n\t\t未能找到学生号为:%d的记录!\n",stuID);
fclose(fp);
}
void?main(void)
{
int?stuID[4]={2013011001,2013011002,2013011003,2013011004};
????//WriteData();
srand((unsigned)time(NULL));//随机种子
????TeacherDM(stuID[rand()%(3-0+1)+0]);
}
运行效果截图:
另外多说一句,你所说的公正性,是不是指被点名过的同学不会再次被随机点名到。如果是这个意思,那么你可以通过数组来设置它,即把点名过的同学的学号或姓名保存到一维数组里,随机判断时只需循环检查下该同学是否已被点名过。这里就留给你做了。
C#写一个随机点名系统
list
name = new list
(){"姓名1","姓名2","姓名3", ...};
//创建随机数生成器
random ran = new random();
//生成范围内的随机数
int index = ran.next(0, name.count);
//输出随机获取的姓名
messagebox.show(name[index]);满意就采纳,有疑问继续追问!!
用c编写一个随机点人的程序 每次运行显示两个人名
//程序如下,加法 减法各25道
#includestdio.h
#includetime.h
#includestdlib.h
void main()
{
int i,a,b,c,score=0;
srand((unsigned)time(NULL));
for(i=1;i=50;i++)
{ a=rand()%89+10;
b=rand()%89+10;
c=rand()%198;
if(i=25)
{
printf("%d+%d=%d\n",a,b,c);
if(c==a+b)
{printf("正确!\n"); score+=2; }
else
printf("错误!\n");
}
else
{
printf("%d-%d=%d\n",a,b,c);
if(c==a-b)
{printf("正确!\n"); score+=2; }
else
printf("错误!\n");
}
}
printf("总分为:%d\n",score);
}