C#操作1-5

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

          int conut = 0;
        private void button1_Click(object sender, EventArgs e)
        {
          
            //double sum = 0;
            double input1 = Convert.ToDouble(this.tBinput1.Text.ToString());
            double input2 = Convert.ToDouble(this.tBinput2.Text.ToString());
           tBcomputer1.Text =((double)input1 + (double)input2).ToString();
           tBcomputer2.Text = ((double)input1 - (double)input2).ToString();
           tBcomputer3.Text = ((double)input1 * (double)input2).ToString();
           tBcomputer4.Text = ((double)input1 / (double)input2).ToString();

           if (tBuser1.Text.ToString() == "" || tBuser2.Text.ToString() == "" || tBuser3.Text.ToString() == "" || tBuser4.Text.ToString() == "")
           {
               MessageBox.Show("请输入完整!!!!");
           }
            double user1 = Convert.ToDouble(this.tBuser1.Text.ToString());
            double user2 = Convert.ToDouble(this.tBuser2.Text.ToString());
            double user3 = Convert.ToDouble(this.tBuser3.Text.ToString());
            double user4 = Convert.ToDouble(this.tBuser4.Text.ToString());
           
         

            if (tBuser1.Text.ToString() == this.tBcomputer1.Text)
              conut++;
           
            if (tBuser2.Text.ToString() == tBcomputer2.Text)
              conut++;
            if (tBuser3.Text.ToString() == tBcomputer3.Text)
              conut++;
            if (tBuser4.Text.ToString() == tBcomputer4.Text)
                conut++;

            //tBuser1.Text = ((double)input1 + (double)input2).ToString();

           this.tBjishu.Text = conut.ToString ();

        }



} }


第二题用菜单控制加减乘除

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();
        }
       
       
           
       
        private void TStemjia_Click(object sender, EventArgs e)
        {

            double text1 = Convert.ToDouble(this.tBnumber1.Text.ToString());
            double text2 = Convert.ToDouble(this.tBnuber2.Text.ToString());
            double he = text1 + text2;
            MessageBox.Show(he.ToString ());
        }

        private void TStemjian_Click(object sender, EventArgs e)
        {
            double text1 = Convert.ToDouble(this.tBnumber1.Text.ToString());
            double text2 = Convert.ToDouble(this.tBnuber2.Text.ToString());
            double cha = text1 - text2;
            MessageBox.Show(cha.ToString());
        }

        private void TStemcheng_Click(object sender, EventArgs e)
        {
            double text1 = Convert.ToDouble(this.tBnumber1.Text.ToString());
            double text2 = Convert.ToDouble(this.tBnuber2.Text.ToString());
            double ji = text1 * text2;
            MessageBox.Show(ji.ToString());
        }

        private void TStemchu_Click(object sender, EventArgs e)
        {
            double text1 = Convert.ToDouble(this.tBnumber1.Text.ToString());
            double text2 = Convert.ToDouble(this.tBnuber2.Text.ToString());
            double shang = text1 / text2;
            MessageBox.Show(shang.ToString());
        }

       
    }
}

第三题IO流读写文件

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 WindowsFormsApplication7
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string source = "";
        string target = "";
        //private void button1_Click(object sender, EventArgs e)
        //{

        //    OpenFileDialog dlg = new OpenFileDialog();

        //    dlg.Filter = "文本文件|*.txt";
        //    DialogResult result = dlg.ShowDialog();
        //    if (result == DialogResult.OK)
        //    {
        //        this.txtSource.Text = dlg.FileName;

        //        StreamReader sr = new StreamReader(this.txtSource.Text);
        //        source = sr.ReadToEnd();
        //        sr.Close();
        //        MessageBox.Show("读取数据成功!");

        //    }


        //}

        //private void button2_Click(object sender, EventArgs e)
        //{
        //    OpenFileDialog dlg = new OpenFileDialog();

        //    dlg.Filter = "文本文件|*.txt";
        //    DialogResult result = dlg.ShowDialog();
        //    if (result == DialogResult.OK)
        //    {
        //        this.txtTarget.Text = dlg.FileName;
        //        StreamWriter sw = new StreamWriter(this.txtTarget.Text);
        //        sw.Write(source);
        //        sw.Close();
        //        MessageBox.Show("拷贝数据成功!");

        //    }
        //}

        private void 读取源文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "文本文件|*.txt";
            DialogResult result = dlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.txtSource.Text = dlg.FileName;

                StreamReader sr = new StreamReader(this.txtSource.Text);
                source = sr.ReadToEnd();
                sr.Close();
                MessageBox.Show("读取数据成功!");
            }
        }

        private void 复制到目标文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "文本文件|*.txt";
            DialogResult result = dlg.ShowDialog();
            if (result == DialogResult.OK)
            {
                this.txtTarget.Text = dlg.FileName;
                StreamWriter sw = new StreamWriter(this.txtTarget.Text);
                sw.Write(source);
                sw.Close();
                MessageBox.Show("拷贝数据成功!");
            }
        }


    }
}

第四题TestNameSpace

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

namespace FirstNameSpace
{
    //嵌套的名称空间
    namespace SecondNameSpace
    {
        public class SecondTest
        {
            public void SecondMethod()
            {
                Console.WriteLine("您现在调用的是:SecondNameSpace空间下的类的方法");
            }
        }
    }

    public class FirstTest
    {
        public void FirstMethod()
        {
            Console.WriteLine("您现在调用的是:FirstNameSpace空间下的类的方法");
        }
    }
    
    
    
    //用于测试的类
    class Program
    {
        static void Main(string[] args)
        {
            //测试调用第一个命名空间下的类的方法
            FirstNameSpace.FirstTest first = new FirstNameSpace.FirstTest();
            first.FirstMethod();

            //测试调用嵌套命名空间下的类的方法
            FirstNameSpace.SecondNameSpace.SecondTest second = new FirstNameSpace.SecondNameSpace.SecondTest();
            second.SecondMethod();
        }
    }
}

第五题Person人员类

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

namespace 第五题
{
    public class Person
    {
        public Person()
        { 
        
        }
        public Person(string name, int age, string sex)
        {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }
        
        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        int age;

        public int Age
        {
            get { return age; }
            set { age = value; }
        }
        string sex;

        public string Sex
        {
            get { return sex; }
            set { sex = value; }
        }

    }
}



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

namespace 第五题
{
    class Student:Person
    {
        public Student()
        { 
        
        }

        public Student(float c1, float c2, float c3, float c4, float c5)
        {
            this.Subject1_Score = c1;
            this.Subject2_Score = c2;
            this.Subject3_Score = c3;
            this.Subject4_Score = c4;
            this.Subject5_Score = c5;
        }

        public Student(string stuName, int stuAge, string stuSex, float c1, float c2, float c3, float c4, float c5)
            : base(stuName, stuAge, stuSex)
        {
            this.Subject1_Score = c1;
            this.Subject2_Score = c2;
            this.Subject3_Score = c3;
            this.Subject4_Score = c4;
            this.Subject5_Score = c5;
        }
        //第一门课成绩
        float Subject1_Score;

        public float Subject1_Score1
        {
            get { return Subject1_Score; }
            set { Subject1_Score = value; }
        }
        //第一门课成绩
        float Subject2_Score;

        public float Subject2_Score1
        {
            get { return Subject2_Score; }
            set { Subject2_Score = value; }
        }
        //第一门课成绩
        float Subject3_Score;

        public float Subject3_Score1
        {
            get { return Subject3_Score; }
            set { Subject3_Score = value; }
        }
        //第一门课成绩
        float Subject4_Score;

        public float Subject4_Score1
        {
            get { return Subject4_Score; }
            set { Subject4_Score = value; }
        }
        //第一门课成绩
        float Subject5_Score;

        public float Subject5_Score1
        {
            get { return Subject5_Score; }
            set { Subject5_Score = value; }
        }

        //计算某个学员五门课程平均分
        public float GetAvgScore()
        { 
          return (this.Subject1_Score + this.Subject2_Score +this.Subject3_Score +this.Subject4_Score + this.Subject5_Score)/5;
        }

    }
}



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

namespace 第五题
{
    class Program
    {
        static void Main(string[] args)
        {
           // Student stu1 = new Student(
            
            //测试
            Student student = new Student("张三", 8, "", 4, 6, 8, 2, 10);
            float stuAvg = student.GetAvgScore();
            Console.WriteLine("张三的平均成绩是:" + stuAvg.ToString());
        }
    }
}


 

 

posted @ 2013-09-15 09:36  博斯芮网络科技  阅读(268)  评论(0编辑  收藏  举报