小石头 封装

第一个页面

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;
using System.IO;
namespace 老陈
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void luti_Click(object sender, EventArgs e)
        {
            StreamWriter n1 = File.AppendText("n1.txt");
            n1.WriteLine(textBox1.Text);
            n1.Close();
            StreamWriter n2 = File.AppendText("n2.txt");
            n2.WriteLine(textBox2.Text);
            n2.Close();
            StreamWriter n3 = File.AppendText("n3.txt");
            n3.WriteLine(textBox3.Text);
            n3.Close();
            richTextBox1.Text += textBox1.Text + textBox2.Text + textBox3.Text+"\n";
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            MessageBox.Show("写入成功");
        }

        private void kaishi_Click(object sender, EventArgs e)
        {//跳转页面
            Form2 frm2 = new Form2();
            frm2.ShowDialog();
        }
    }
}

  运行的界面

第二个页面

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;
using System.IO;
namespace 老陈
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public static int Count = 0;
        private int t = 60;
        public static int right = 0;
        //总计的个数和正确的个数
        int m = 0;
        private void button1_Click(object sender, EventArgs e)
        {   //时间
            label1.Text = t.ToString();
            timer1.Enabled = true;
            timer1.Interval = 1000;
            timer1.Start();
            //出题
            string[] n1 = new string[100];
            n1 = File.ReadAllLines("n1.txt");
            textBox1.Text = n1[m];
            string[] n2 = new string[100];
            n2 = File.ReadAllLines("n2.txt");
            textBox2.Text = n2[m];
            string[] n3 = new string[100];
            n3 = File.ReadAllLines("n3.txt");
            textBox3.Text = n3[m];
            m++;

        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            //调用;
            int a = int.Parse(textBox1.Text);
            int b = int.Parse(textBox3.Text);
            Char c = Convert.ToChar(textBox2.Text);
            Class1 con = new Class1();
            con.chu(a, b, c);
            if (e.KeyCode == Keys.Enter)
            {

                if (con.answer == int.Parse(textBox4.Text))
                {
                    MessageBox.Show("回答正确!下一题请按开始按钮!");
                    right++;
                    Count++;
                }

                else
                {

                    MessageBox.Show("回答错误!下一题请按开始按钮!");
                    Count++;

                }
                timer1.Enabled = false;
                textBox1.Clear();//清空
                textBox2.Clear();
                textBox3.Clear();
                textBox4.Clear();

            }

        }
        private void timer1_Tick_1(object sender, EventArgs e)
        {
            if (t <= 0)
            {
                timer1.Enabled = false;
                MessageBox.Show("时间到!");
            }
                t = t - 1;
                label1.Text = t.ToString();
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            textBox4.Enabled = false;
            MessageBox.Show("运算结束!");
            textBox5.Text = Form2.Count.ToString();//题目总数
            textBox6.Text = Form2.right.ToString();
            textBox7.Text = ((Form2.right / (double)(Form2.Count)) * 100).ToString() + "%";//正确率
        }

    }
}

  运行的界面

封装如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 老程
{
    class Class1
    {
        public int sum;
        public int answer
        {
            get
            {
                return sum;
            }
        }

        public int chu(int n1, int n2, char fuhao)
        {
            if (fuhao == ‘+‘)
            {
                return sum = n1 + n2;
            }
            else if (fuhao == ‘-‘)
            {
                return sum = n1 - n2;
            }
            else if (fuhao == ‘*‘)
            {
                return sum= n1 * n2;
            }
            return sum;

        }

    }
}

  总结:在做这次的封装,遇到了很多困难,从当初的不知道封装是什么,怎么去做,到今天才把这个做好。我知道我的代码不是很好,这是老师布置作业后我开始看我以前C#的书和请教已经完成的同学,然后无数次的测试,修改我的代码,到现在做成这样,不过我的实现功能不是特别全,不会保存,不过我的下一步会完善的,我会继续努力让自己跟上去的。

时间: 2024-08-24 13:00:55

小石头 封装的相关文章

老陈与小石头运算代码

总结:在这次作业中学会了封装,但是还是不会运用策略模式.Form1窗体的代码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; using System.IO; namespace 老

python学习 面向对象封装

from collectoins import namedtuplePoint=namedtuple('point',['x','y'])t1=Point(1,2)print(t1.x)print(t1.y)没有方法的类属性不会发生变化    定义简单 不能改变面向对象封装私有属性!!!私有方法!!!用装饰器描述的几个方法@property !!!@classmethod!!@staticmethod! 封装:class Teacher:     def __init__(self,name,p

python—面向对象的封装

封装 私有属性 class Teacher: __identifier = 'Teacher' #私有静态属性 def __init__(self,name,pwd) self.name = name self.__pwd = pwd #私有属性 内部使用,外部不能使用 def pwd(self): print(self.__pwd) alex = Teacher('alex','3714') alex.pwd() class Teacher: __identifier = 'Teacher'

dbutils封装对象,单列,一行一列(用)

基本用法:查找并封装对象与对象集合 public User findUserByNamePassword(String name,String password){ QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource()); String sql = "select * from user where name='"+name+"' and password = '"+password

python基础--接口与归一化设计、封装、异常、网络编程

1 接口与归一化设计 1.1 归一化概念: 归一化的好处: 1.归一化让使用者无需关心对象的类是什么,只需要知道这些对象都具备某些功能就可以了,这极大降低了使用者的使用难度. 2.归一化使得高层的外部使用者可以不加区分的处理所有接口兼容的对象集合 继承的两种用途 一:继承基类的方法,并且做出自己改变或者扩展(代码重用):实践中,继承的这种用途意义并不很大,甚至常常是有害的.因为它使得子类与基类出现强耦合. 二:声明某个子类兼容于某基类,定义一个接口类(模仿java的Interface),接口类中

自动化测试框架 selenium api的封装

接上一篇 http://tianxietaotao.blog.51cto.com/12002420/1951701 这篇我大概介绍下我这个工具的简单介绍 先上图: 制作背景: Web自动化测试在现在测试领域已经越来越普遍,但是写代码对于好多测试猿代码基础较弱,搭建系统也比较麻烦.所以我抽闲暇时间做了这个简单的工具:下面简单介绍下功能 工具简单介绍: 1.工具栏:Resume:调试阶段执行到下一个断点 next:单步执行 debug/run 模式切换 执行.停止 2.用例树:用例采用execl或者

lambda表达式封装对数据库的查询

前言: 1.为什么要封装lambda表达式数据库查询,原因有一下几点: 1.1.在以往的开发中进行数据库表查询时,其实所需要的字段就是其中几个,但是在开发中,开发者往往习惯select * 进行查询,当数据多和用户量多时,查询的效率会降低. 1.2.在写查询where条件的时候,总是用string.format去拼接字符串,开发效率低. 1.3.代码不够优雅,代码中嵌套和多sql语句,如果是表字段发生改变时编译器检查不出来,代码出错的概率大. 1.4.本着 write less  do more

Android封装TitleBar基本适用所有常规开发

Android封装TitleBar基本适用所有常规开发 github地址:https://github.com/SiberiaDante/SiberiaDanteLib/blob/master/sample/src/main/notes/TitleBar.md 主要实现:(后续会继续完善,喜欢的给个star,感谢支持) 使用方法 allprojects { repositories { ... aven { url 'https://jitpack.io' } } } dependencies

将数据库从服务器移到浏览器--indexedDB基本操作封装

数据库是属于服务器的,这是天经地义的事,但是有时候数据也许并非需要存储在服务器,但是这些数据也是一条一条的记录,怎么办?今天来带领你领略一下H5的一个新特性--indexedDB的风骚.你会情不自禁的发出感叹--不可思议! 一.链接数据库 indexedDB没有创建数据库的概念,你可以直接链接数据库,如果你链接的数据库并不存在,那么会自动的创建一个数据库.看下面的这个例子. <!DOCTYPE html> <html lang="en"> <head>