2021.4.20C#作业
创建学生类Student,其属性描述包括ID(编号)、Name(姓名)、SClass(班级)、CScore(语文成绩);## 创建教师类Teacher,其属性描述包括ID(编号)、Name(姓名)、JobTitle(职称)、Department(部门)。## 根据学生类和教师类抽象出基类Person,类Person包括属性ID(编号)、Name(姓名),编号和姓名的输入方法和显示方法。
在这里插入代码片class Person
{
private string id;
private string name;
public string ID
{
get { return id; }
set { id = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public virtual void input()
{
Console.WriteLine("ID:");
id = Convert.ToString(Console.ReadLine());
Console.WriteLine("姓名:");
name = Convert.ToString(Console.ReadLine());
}
public virtual void output()
{
Console.WriteLine("id:{0}", id);
Console.WriteLine("姓名:{0}", name);
}
}
class Student : Person
{
private string sClass;
private double cScore;
public override void input()
{
base.input();
Console.WriteLine("班级:");
sClass = Convert.ToString(Console.ReadLine());
Console.WriteLine("语文成绩¨:");
cScore = Convert.ToDouble(Console.ReadLine());
Console.WriteLine();
}
public override void output()
{
base.output();
Console.WriteLine("班级:{0}", sClass);
Console.WriteLine("语文成绩¨:{0}", cScore);
Console.WriteLine();
}
public string SClass
{
get { return sClass; }
set { sClass = value; }
}
public double CScore
{
get { return cScore; }
set { cScore = value; }
}
}
class Teacher : Person
{
private string jobTitle;
private string department;
public override void input()
{
base.input();
Console.WriteLine("职称:");
jobTitle = Convert.ToString(Console.ReadLine());
Console.WriteLine("部门:");
department = Convert.ToString(Console.ReadLine());
Console.WriteLine();
}
public override void output()
{
base.output();
Console.WriteLine("职称:{0}", jobTitle);
Console.WriteLine("部门:{0}", department);
}
public string JobTitle
{
get { return jobTitle; }
set { jobTitle = value; }
}
public string Department
{
get { return department; }
set { department = value; }
}
}
class Program
{
static void Main(string[] args)
{
Student dujiayi = new Student();
Teacher qcy = new Teacher();
dujiayi .input();
dujiayi .output();
qcy.input();
qcy.output();
Console.ReadLine();
}
}
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e851dc8626bd5f173fc0c1d79b0adad2.png#pic_center)