C#学习笔记(第1周作业)
受队友诱惑,去听了李强的C#公选课,第二天就完成作业了。
作业要求:
1. 小学生加法程序;
2. 能自由设置难度;
3. 对结果进行统计。
第一次写C#程序,遇到不少困难,和队友讨论,百度谷歌一齐上。
让同学帮忙测试,找出十多处Bug,一一修改。
本来挺好看的代码,被我改成一坨屎了都。T-T
上图:




下载地址:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AdditionGame
{
public partial class Setting : Form
{
public Setting()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
} private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
} private void Form1_Activated(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox1.Focus();
} private void button2_Click(object sender, EventArgs e)
{
if (textBox1.Text == "" || textBox2.Text == "")
{
Error f7 = new Error(this);
f7.Show();
this.Hide();
}
else
{
bool Flag = true;
string Str1 = Convert.ToString(textBox1.Text);
if (Str1.Length > )
Flag = false;
else
for (int i = ; i < Str1.Length; ++i)
if (Str1[i] < '' || Str1[i] > '')
{
Flag = false;
break;
}
string Str2 = Convert.ToString(textBox2.Text);
if (Str2.Length > )
Flag = false;
else
for (int i = ; i < Str2.Length; ++i)
if (Str2[i] < '' || Str2[i] > '')
{
Flag = false;
break;
}
if (Flag)
{
ClassCommon.Scope = Convert.ToInt32(textBox1.Text);
ClassCommon.Total = Convert.ToInt32(textBox2.Text);
if (ClassCommon.Scope == || ClassCommon.Total == )
{
Error f5 = new Error(this);
f5.Show();
this.Hide();
}
else
{
Playing f2 = new Playing(this);
f2.Show();
this.Hide();
}
}
else
{
Error f6 = new Error(this);
f6.Show();
this.Hide();
}
}
} private void button3_Click(object sender, EventArgs e)
{
this.Close();
} private void button4_Click(object sender, EventArgs e)
{
About f3 = new About(this);
f3.Show();
this.Hide();
} } }
Playing.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AdditionGame
{
public partial class Playing : Form
{
Form f1 = new Setting();
public Playing(Setting firstForm)
{
InitializeComponent();
f1 = firstForm;
} private void Get_Random_Addend()
{
Random seed = new Random();
Random Addend = new Random(seed.Next());
for (int i = ; i < ClassCommon.Total; ++i)
{
ClassCommon.F[i].Addend1 = Addend.Next(ClassCommon.Scope);
ClassCommon.F[i].Addend2 = Addend.Next(ClassCommon.Scope - ClassCommon.F[i].Addend1);
}
} private void Put_Random_Addend()
{
textBox1.Text = Convert.ToString(ClassCommon.F[ClassCommon.Count].Addend1);
textBox2.Text = Convert.ToString(ClassCommon.F[ClassCommon.Count].Addend2);
++ClassCommon.Count;
textBox3.Focus();
} private void Form2_Load(object sender, EventArgs e)
{
progressBar1.Minimum = ;
progressBar1.Maximum = ClassCommon.Total*;
progressBar1.Value = ;
for (int i = ; i < ClassCommon.Total; ++i)
ClassCommon.F[i].Ans = -;
ClassCommon.Count = ;
Get_Random_Addend();
Put_Random_Addend();
progressBar1.Value += ;
if (ClassCommon.F[ClassCommon.Count - ].Ans != -)
textBox3.Text = Convert.ToString(ClassCommon.F[ClassCommon.Count - ].Ans);
else
textBox3.Text = "";
textBox3.Focus();
} private void button3_Click(object sender, EventArgs e)
{
this.Close();
f1.Show();
} private void button4_Click(object sender, EventArgs e)
{
this.Close();
f1.Close();
} private void Form2_Activated(object sender, EventArgs e)
{
textBox3.Focus();
button1.Enabled = false;
this.Text = "第" + Convert.ToString(ClassCommon.Count) + "题";
if (ClassCommon.Count == ClassCommon.Total)
button2.Text = "完成";
else
button2.Text = "下一题";
} private void button2_Click(object sender, EventArgs e)
{
if (textBox3.Text != "" && textBox3.TextLength < )
{
if (ClassCommon.Count == ClassCommon.Total)
{
ClassCommon.F[ClassCommon.Count - ].Ans = Convert.ToInt32(textBox3.Text);
Result f4 = new Result(this.f1);
this.Close();
f4.Show();
}
else
{
button1.Enabled = true;
ClassCommon.F[ClassCommon.Count - ].Ans = Convert.ToInt32(textBox3.Text);
Put_Random_Addend();
progressBar1.Value += ;
}
}
if (ClassCommon.F[ClassCommon.Count - ].Ans != -)
textBox3.Text = Convert.ToString(ClassCommon.F[ClassCommon.Count - ].Ans);
else
textBox3.Text = "";
this.Text = "第" + Convert.ToString(ClassCommon.Count) + "题";
if (ClassCommon.Count == ClassCommon.Total)
button2.Text = "完成";
else
button2.Text = "下一题";
textBox3.Focus();
} private void button1_Click(object sender, EventArgs e)
{
ClassCommon.Count -= ;
if (ClassCommon.Count == )
button1.Enabled = false;
Put_Random_Addend();
progressBar1.Value -= ;
if (ClassCommon.F[ClassCommon.Count - ].Ans != -)
textBox3.Text = Convert.ToString(ClassCommon.F[ClassCommon.Count - ].Ans);
else
textBox3.Text = "";
if (ClassCommon.Count == ClassCommon.Total)
button2.Text = "完成";
else
button2.Text = "下一题";
this.Text = "第" + Convert.ToString(ClassCommon.Count) + "题";
textBox3.Focus();
} }
}
Error.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AdditionGame
{
public partial class Error : Form
{
Form f1 = new Setting();
public Error(Form firstForm)
{
InitializeComponent();
f1 = firstForm;
} private void Error_Load(object sender, EventArgs e)
{
button4.Focus();
} private void button4_Click(object sender, EventArgs e)
{
this.Close();
f1.Show();
} private void button3_Click(object sender, EventArgs e)
{
this.Close();
f1.Close();
}
}
}
Result.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AdditionGame
{
public partial class Result : Form
{
Form f1 = new Setting();
public Result(Form firstForm)
{
InitializeComponent();
this.f1 = firstForm;
} private void button3_Click(object sender, EventArgs e)
{
this.Close();
f1.Close();
} private void Result_Load(object sender, EventArgs e)
{
ClassCommon.Right = ;
ClassCommon.Wrong = ;
ClassCommon.Rate = 0.0;
for (int i = ; i < ClassCommon.Total; ++i)
if (ClassCommon.F[i].Addend1 + ClassCommon.F[i].Addend2 == ClassCommon.F[i].Ans)
++ClassCommon.Right;
else
++ClassCommon.Wrong;
ClassCommon.Rate = Convert.ToDouble(ClassCommon.Right) / Convert.ToDouble(ClassCommon.Total) * 100.0;
string Str3 = String.Format("{0:F}", ClassCommon.Rate);
listBox1.Items.Add("此次练习一共有 " + Convert.ToString(ClassCommon.Total) + " 题,答对 " + Convert.ToString(ClassCommon.Right) + " 题,答错 " + Convert.ToString(ClassCommon.Wrong) + " 题,正确率为 " + Str3 + " %");
if (ClassCommon.Right == ClassCommon.Total)
listBox1.Items.Add("干得漂亮,你全做对了!优秀是一种习惯,希望你继续保持。");
else
if (ClassCommon.Rate >= 80.0)
listBox1.Items.Add("你真棒,快看看哪些题目做错了!期待你更上一层楼。");
else
if (ClassCommon.Rate >= 60.0)
listBox1.Items.Add("做得一般,还需要付出更大的努力才行哦!");
else
listBox1.Items.Add("做得不好!你付出了时间与精力,为什么不付出感情呢?");
if (ClassCommon.Right != ClassCommon.Total)
{
listBox1.Items.Add("以下是你做错的题目以及正确答案:");
for (int i = ; i < ClassCommon.Total; ++i)
if (ClassCommon.F[i].Addend1 + ClassCommon.F[i].Addend2 != ClassCommon.F[i].Ans)
listBox1.Items.Add("第 " + Convert.ToString(i + ) + " 题," + Convert.ToString(ClassCommon.F[i].Addend1) + " + " + Convert.ToString(ClassCommon.F[i].Addend2) + " = " + Convert.ToString(ClassCommon.F[i].Ans) + "✘→" + Convert.ToString(ClassCommon.F[i].Addend1 + ClassCommon.F[i].Addend2) + "✔");
}
button4.Focus();
} private void button4_Click(object sender, EventArgs e)
{
this.Close();
f1.Show();
} private void Result_Activated(object sender, EventArgs e)
{
button4.Focus();
} private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{ } }
}
About.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace AdditionGame
{
public partial class About : Form
{
Form f1 = new Setting();
public About(Setting firstForm)
{
InitializeComponent();
f1 = firstForm;
} private void About_Load(object sender, EventArgs e)
{
button4.Focus();
} private void button3_Click(object sender, EventArgs e)
{
f1.Close();
this.Close();
} private void button4_Click(object sender, EventArgs e)
{
this.Close();
f1.Show();
} private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.cnblogs.com/haipzm/");
} private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("haipzm@gmail.com");
} }
}
ClassCommon.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace AdditionGame
{
public struct Data
{
public int Addend1;
public int Addend2;
public int Ans;
}
class ClassCommon
{
public static int MaxTotal = ;
public static Data[] F = new Data[MaxTotal];
public static int Count = ;
public static double Rate = 0.0;
public static int Right = ;
public static int Wrong = ;
public static int Total = ;
public static int Scope = ;
}
}
C#学习笔记(第1周作业)的更多相关文章
- 红帽学习笔记[RHCSA] 第二周
目录 红帽学习笔记[RHCSA]第二周 环境 第七课[网络配置相关] 在Vmware中添加网卡 将网卡添加到虚拟机上 关于网卡命名规则 配置网络 网络配置命令总结 更改hostname 关于SSH的一 ...
- 20145230《java学习笔记》第九周学习总结
20145230 <Java程序设计>第9周学习总结 教材学习内容 JDBC JDBC简介 JDBC是用于执行SQL的解决方案,开发人员使用JDBC的标准接口,数据库厂商则对接口进行操作, ...
- 从零开始,SpreadJS 新人学习笔记(第二周)
Hello,大家好,我是Fiona.经过上周的学习,我已经初步了解了SpreadJS的目录结构,以及如何创建Spread项目到我的工程目录中.>>还不知如何开始学习SpreadJS的同学, ...
- 红帽学习笔记[RHCSA] 第一周
目录 红帽学习笔记[RHCSA] 环境 第一课 关于Shell 命令的基础知识 在终端中敲命令的快捷键 本次课程涉及的命令 第二课 常用的目录结构与用途 本次课程涉及到的命令 第三课 关于Linux的 ...
- 201521123103 《Java学习笔记》第二周学习笔记
一.本周学习总结 1.学习了数据类型的使用:整数类型.浮点类型. boolean类型.数组等以及类型的转换,最重要的是学会了import引用包: 2.学习了string类对象的拼接.字符串池.枚举类型 ...
- 201521123047 《Java学习笔记》第二周学习总结
1. 本周学习总结 -知道并了解到浮点数的误差关系,懂得运java.math.BigDecimal来进行浮点数的精确计算 -对于"="与"=="的区分 -字符串 ...
- Week03-Java学习笔记第三次作业
Week03-面向对象入门 1.本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识点组织起来.请使用工具画出本周学习到的知识点及知识点之间的联系. ...
- 201521123103 《Java学习笔记》 第九周学习总结
一.本周学习总结 1.以你喜欢的方式(思维导图或其他)归纳总结异常相关内容. 二.书面作业 本次PTA作业题集异常 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写 ...
- Python学习笔记第八周
目录: 一.基础概念 1.动态导入模块 2.断言机制 3.SocketServer 二.作业 FTP服务器 三.单独注明 1.类中装饰器 2.进度条 一.基础概念 1.动态导入模块 有时在编程过程中, ...
- Python学习笔记第六周
目录 一.基础概念 面向对象编程 1.面向对象的几个核心特点 1.class类 2.object对象 3.encapsulation封装 4.inheritance继承 5.polymorphism多 ...
随机推荐
- MySQL数据库InnoDB存储引擎中的锁机制
MySQL数据库InnoDB存储引擎中的锁机制 http://www.uml.org.cn/sjjm/201205302.asp 00 – 基本概念 当并发事务同时访问一个资源的时候,有可能 ...
- linux下的ls命令
在LINUX系统中有一个重要的概念:一切都是文件.其实这是UNIX哲学的一个体现,而Linux是重写UNIX而来,所以这个概念也就传承了下来.在UNIX系统中,把一切资源都看作是文件,包括硬件设备.U ...
- UNIX/Linux网络编程基础:应用层协议简介
目录 1.HTTP协议 2.FTP协议 3.TELNET协议 4.NFS协议 1.HTTP协议 应用层协议HTTP协议是Web的核心.HTTP协议在Web的客户程序和服务器程序中得以实现,运行在不同系 ...
- 编写who命令:文件操作,缓冲区与联机帮助
最近阅读UULP(Understanding Unix/Linux Programming),按照书中介绍对Unix/Linux系统编程进行学习梳理,总结如下. 1. who命令能做什么 who命令用 ...
- Design Mode 之 结构模式
这里我们主要介绍7种结构型模式:适配器模式.装饰模式.代理模式.外观模式.桥接模式.组合模式.享元模式.其中对象的适配器模式是各种模式的起源,我们看下面的图: B1.适配器模式(Adapter) 模式 ...
- 开发工具 之 PowerDesigner
PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...
- 美国H1B基本情况及相关数据
H-1B是外国人在美国工作的签证,从美国学校毕业之后会有12个月的OPT实习期,在OPT结束之前必须申请到H1B签证才能在实习期结束后继续工作. H1B需要由雇佣你的公司帮你申请,也就是说必须先找到工 ...
- 1.7.4.1 Function Queries-函数查询
1 . Function Queries 函数查询使你可以使用一个或者多个数字字段的实际的值生成一个关联的得分(score),函数查询支持DixMax,eDisMax,标准的查询解析. 函数查询使用函 ...
- 跨平台轻量级redis、ssdb代理服务器(C++ 11编写)
dbproxy 是我业余采用C++11编写的跨平台代理服务器(并使用lua和自己的网络库),以扩展系统负载,同时使用多个后端数据库,后端数据库支持redis和ssdb. 需要由用户自己编写lua脚本控 ...
- 数据结构【二】:简单阻塞队列BlockingQueue
在POSIX多线程[一]:简单队列simple queue的基础上使用内部互斥锁和条件变量来控制并发以达到线程安全的目的,其主要用于 [生产者-消费者] 队列. 1.BlockingQueue初始化时 ...