封装,策略模式

本文介绍了一个名为Writeclear的类,用于实现文件写入和清空操作。包括实例化对象、设置属性如文件路径、操作符和值,并通过write()和clear()方法进行文件内容的读写和清空。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.IO;
 6 
 7 namespace 出题
 8 {
 9     class Writeclear   //Writeclear类
10     {
11        private string a;
12        private string b;
13        private string opertaors;
14        public Writeclear(string A,string B,string Operators)
15        {
16            a = A;
17            b = B;
18            opertaors = Operators;
19  
20        }
21        
22        private string x;
23        private string y;
24        private string operator1;
25        public string X
26        {
27            set
28            {
29                x = value;
30            }
31        }
32        public string Y
33        {
34            set
35            {
36                y = value;
37            }
38        }
39        public string Operator1
40        {
41            set
42            {
43                operator1 = value;
44            }
45        }
46   
47        public void write()
48        {
49            StreamWriter a1 = new StreamWriter(a, true);
50            a1.WriteLine(x);
51            a1.Close();
52            StreamWriter a2 = new StreamWriter(b, true);
53            a2.WriteLine(y);
54            a2.Close();
55            StreamWriter a3 = new StreamWriter(opertaors, true);
56            a3.WriteLine(operator1);
57            a3.Close();
58            
59        }
60        public void clear()
61        {
62            StreamWriter b1 = new StreamWriter(a);
63            b1.WriteLine("");
64            b1.Close();
65            StreamWriter b2 = new StreamWriter(b);
66            b2.WriteLine("");
67            b2.Close();
68            StreamWriter b3 = new StreamWriter(opertaors);
69            b3.WriteLine("");
70            b3.Close();
71        }
72        
73 
74     }
75 }
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace 出题
 7 {
 8     class calcuall
 9     {
10         Calculator calculator = new Calculator();
11         private string opreator2;
12         public string Operator2
13         {
14             set
15             {
16                 opreator2 = value;
17             }
18         
19         }
20         public void cal()
21         {
22             if (opreator2 == "+")
23             {
24                 calculator.Add();
25             }
26             if (opreator2 == "-")
27             {
28                 calculator.sub();
29             }
30             if (opreator2 == "/")
31             {
32                 calculator.division();
33             }
34             if (opreator2 == "*")
35             {
36                 calculator.multiplication();
37             }
38          
39         }
40             
41     
42     }
43 }

 

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

namespace 出题
{
    class Calculator
    {
        private int z;
        private int x;
        private int y;
        private string operator1;
        private int answer;
        public int X
        {
           
            set
            {
                x = value;
            }
        }
        public int Y
        {
            set
            {
                y = value;
            }
        }
        public string Operator1
        {
            set
            {
                operator1 = value;
            }
        }
        public int Answer
        {
            get
            {
                return answer;
            }
        }
        public void Add()
        {
            answer= x + y;
 
        }
        public void sub()
        {
            if (x > y)
            {

                answer = x - y;
            }
            else
            {
                z = y;
                y = x;
                x = z;
                answer = x - y;
            }
               
        }
        public void multiplication()
        {
            answer = x * y;
        }
        public void division()
        {
            if (y == 0)
            {
                z = y;
                y = x;
                x = z;
                answer = x / y;
            }
            else
            {
                answer = x / y;
            }
        }

    }
}

 

from1

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.IO;
10 
11 
12 namespace 出题
13 {
14     public partial class Form1 : Form
15     {
16         public Form1()
17         {
18             InitializeComponent();
19         }
20 
21 
22         private void button1_Click(object sender, EventArgs e)
23         {
24             string fnm = @"one";
25             string fnmm = @"tow";
26             string fnmn = @"fuhao";
27             Writeclear write1 = new Writeclear(fnm,fnmm,fnmn);
28             write1.X = textBox1.Text;
29             write1.Y = textBox2.Text;
30             write1.Operator1 = comboBox1.Text;
31             write1.write();
32             textBox1.Clear();
33             textBox2.Clear(); 
34 
35         }
36 
37         private void button2_Click(object sender, EventArgs e)
38         {
39             Form2 fam = new Form2();
40             fam.ShowDialog();
41          
42         }
43 
44         private void button3_Click(object sender, EventArgs e)
45         {
46 
47             string fnm = @"one";
48             string fnmm = @"tow";
49             string fnmn = @"fuhao";         
50             Writeclear write1 = new Writeclear(fnm, fnmm, fnmn); 
51             write1.clear();
52         }
53       
54  
55         }
56     }

from2

sing 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();
        }

        int i=1;
       public static int count = -1;
       public static int right = 0;
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                int t = int.Parse(textBox5.Text);
                if (t <= 0)
                {
                    timer1.Enabled = false;
                    textBox5.Enabled = false;
                    MessageBox.Show("时间到了!");
                    Form3 fr3 = new Form3();
                    fr3.ShowDialog();

                }
                t = t - 1;
                textBox5.Text = t.ToString();

            }
            catch
            {
 
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string t = textBox5.Text;
                textBox5.Text = t;
                timer1.Enabled = true;
                timer1.Interval = 1000;
                timer1.Start();
            }
            catch
            { 

            }
            baaa();
            count++;
        

        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        { 
            Calculator calculator=new Calculator();
            calcuall cal=new calcuall();
            calculator.X=int.Parse(textBox1.Text);
            calculator.Y=int.Parse(textBox3.Text);
            calculator.Operator1=textBox2.Text;
            cal.Operator2=textBox2.Text;                     
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox4.Text ==calculator.Answer.ToString() )
                {
                    MessageBox.Show("回答正确!");
                    right++;

from3

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 namespace 出题
11 {
12     public partial class Form3 : Form
13     {
14         public Form3()
15         {
16             InitializeComponent();
17         }
18 
19         private void Form3_Load(object sender, EventArgs e)
20         {
21             textBox1.Text = Form2.right.ToString();
22             textBox2.Text = Form2.count.ToString();
23             textBox3.Text = ((Form2.right / (double)(Form2.count)) * 100).ToString() + "%";
24         }
25     }
26 }

 

转载于:https://www.cnblogs.com/zwt0626/p/4995630.html

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值