C#创建学生类Student,其属性描述包括ID(编号)、Name(姓名)、SClass(班级)、CScore(语文成绩);创建教师类Teacher,其属性描述包括ID(编号)、Name(姓

```c
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 
{
    public  class Person
    {
        public string id;
        public string name;
        public string ID
        {
            get{ return id;}
            set { id = value; }
        }
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        public void InPreson()
        {
            Console.WriteLine("请输入ID:");
            ID= Convert.ToString(Console.ReadLine());
            Console.WriteLine("请输入Name:");
            Name = Convert.ToString(Console.ReadLine());
        }
        public void  OutPerson()
        {
            Console.WriteLine("ID:{0}",ID);
            Console.WriteLine("Name:{0}", Name);
        }
    }
    public class Student : Person
    {
        private string sClass;
        private double cScore;
        public string SClass
        {
            get { return sClass; }
            set { sClass = value; }
        }
        public double CScore
        {
            get { return cScore; }
            set { cScore = value; }
        }
        public void InStudent()
        {
            Console.Write("学生");
            base.InPreson();
            Console.WriteLine("班级: ");
            SClass = Convert.ToString(Console.ReadLine());
            Console.WriteLine("语文成绩:");
            CScore = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine();
        }
        public void OutStudent()
        {
            base.OutPerson();
            Console.WriteLine("班级:{0}", sClass);
            Console.WriteLine("语文成绩:{0}", cScore);
            Console.WriteLine();
        }
    }
    public class Teacher:Person
    {
        private string jobTitle;
        private string department;
        public string JobTitle
        {
            get { return jobTitle; }
            set { jobTitle = value; }
        }
        public string Department
        {
            get { return department; }
            set { department = value; }
        }
        public void InTeacher()
        {
            Console.Write("老师");
            base.InPreson();
            Console.WriteLine("职称:");
            JobTitle = Convert.ToString(Console.ReadLine());
            Console.WriteLine("部门:");
            Department = Convert.ToString(Console.ReadLine());
            Console.WriteLine();

        }
        public void OutTeacher()
        {
            base.OutPerson();
            Console.WriteLine("职称:{0}", jobTitle);
            Console.WriteLine("部门:{0}", department);
            Console.WriteLine();
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Student lihua = new Student();
            Teacher panlaoshi = new Teacher();
            lihua.InStudent();
            lihua.OutStudent();
            panlaoshi.InTeacher();
            panlaoshi.OutTeacher();
        }

    }

}

  • 10
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值