上机实验4

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

        private void button1_Click(object sender, EventArgs e)
        {
            AddressBook person = new AddressBook(textBox1.Text, textBox2.Text, textBox3.Text);
            textBox4.Text=person.GetMessage();
        }

    }
}

class AddressBook
{
    private string name;
    private string phone;
    private string email;
    public AddressBook(string name,string phone,string email)
    {
        this.name=name;
        this.phone=phone;
        this.email=email;
    }
    public string Name
    {
        get{return name;}
    }
    public string Phone
    {
        get
        {
            if(phone==null)return"no value";
            else return phone;
        }
        set
        {
             phone=value;
        }
    }

    public string GetMessage()
    {
        return string.Format("name:{0}\r\nphone:{1}\r\nEmail:{2}", Name, Phone, email);
    }
}


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

        

        private void Form1_Load(object sender, EventArgs e)
        {
            now = new Time();
            textBox1.Text = now.ShowHour().ToString();
            textBox2.Text = now.ShowMinute().ToString();
            textBox3.Text = now.ShowSecond().ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            now.AddSecond();
            textBox1.Text = now.ShowHour().ToString();
            textBox2.Text = now.ShowMinute().ToString();
            textBox3.Text = now.ShowSecond().ToString();
        }
    }
}

class Time
{
    private int hour, minute, second;
    public Time()
    {
        hour = System.DateTime.Now.Hour;
        minute = System.DateTime.Now.Minute;
        second = System.DateTime.Now.Second;
    }
    public Time(int h, int m, int s)
    {
        hour = h; minute = m; second = s;
    }
    public int ShowHour()
    {
        return hour;
    }
    public int ShowMinute()
    {
        return minute;
    }
    public int ShowSecond()
    {
        return second;
    }
    public void AddSecond()
    {
        second++;
        if (second >= 60)
        {
            second = second % 60;
            minute++;
        }
        if (minute >= 60)
        {
            minute = minute % 60;
            hour++;
        }
    }
}


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 C5_Score
{
    public partial class Form1 : Form
    {

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int a;
            double ch, ma;
            a = Convert.ToInt32(textBox2.Text);
            ch = Convert.ToDouble(textBox3.Text);
            ma = Convert.ToDouble(textBox4.Text);
            Pupil person = new Pupil(textBox1.Text, a, ch, ma);
            textBox6.Text += person.getMessage();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int a;
            double ch, ma,eng;
            a = Convert.ToInt32(textBox2.Text);
            ch = Convert.ToDouble(textBox3.Text);
            ma = Convert.ToDouble(textBox4.Text);
            eng = Convert.ToDouble(textBox5.Text);
            middle person = new middle(textBox1.Text, a, ch, ma, eng);
            textBox6.Text += person.getMessage();
        }
    }
}

public abstract class Student
{
    protected string name;
    protected int age;
    public static int number;
    public Student(string name, int age)
    {
        this.name = name;
        this.age = age;
        number++;
    }
    public string Name { get { return name; } }
    public abstract double Average();
    public string getMessage()
    {
        return string.Format("总人数:{0},姓名:{1},平均成绩:{2}\r\n", number, name, Average());
    }
}

public class Pupil : Student
{
    protected double chinese;
    protected double math;
    public Pupil(string name, int age, double chinese, double math)
        : base(name, age)
    {
        this.chinese = chinese;
        this.math = math;
    }
    public override double Average()
    {
        return (chinese + math) / 2;
    }
   
}
public class middle : Pupil
{
    protected double english;
    public middle(string name, int age, double chinese, double math, double english)
        : base(name, age, chinese, math)
    {
        this.english = english;
    }
    public override double Average()
    {
        return (chinese + math + english) / 3;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值