当前位置:编程学习 > C#/ASP.NET >>

有关C#编程问题 救急

定义一个人员类clsPerson,包括属性:姓名,编号,性别和用于输入输出的方法。在此基础上派生出学生类clsStudent(增加成绩)和教师类clsTeacher(增加教龄),并实现对学生和教师的信息的输入输出。
答案:public class clsPerson

{

private string name;

private string num;

private string sex;

public void input()

{


num = Console.ReadLine();


name = Console.ReadLine();


sex = Console.ReadLine();

}

public void output()

{


Console.WriteLine("编号:" + num);


Console.WriteLine("姓名:" + name);


Console.WriteLine("性别:" + sex);

}

}
public class clsStudent : clsPerson

{

float score;

public void input_stu()

{


input();


score = Console.Read();

}

public void output_stu()

{


output();


Console.WriteLine("得分:" + score);

}

}
public class clsTeacher : clsPerson

{

int teachage;

public void input_teacher()

{


input();


teachage = Console.Read();

}

public void output_teacher()

{


output();


Console.WriteLine("教龄:" + teachage);

}

}

 public string Sex{ get; set;}
 public string ID{ get; set;}
public virtual void ShowInfo()
{
 Console.writeLine("姓名",this.name);
 Console.writeLine("ID",this.ID);
 Console.writeLine("性别",this.sex);
}
public virtual void SetInfo()
{
 this.name = console.ReadLine();
this.ID = console.ReadLine();
this.sex = console.ReadLine();
}

}
public class clsStudent:clsPerson

public double StudentResult{get; set;}
{
public override void ShowInfo()
{
Console.writeLine("姓名",this.name);
 Console.writeLine("ID",this.ID);
 Console.writeLine("性别",this.sex);
Console.writeline("成绩",this.StudentResult);

public virtual void SetInfo()
{
 this.name = console.ReadLine();
this.ID = console.ReadLine();
this.sex = console.ReadLine();
thi.StudentResult = Convert.ToInt32(Console.Readline);
}
}
public class clsTeacher:clsPerson
{
 public int Age{get; set;}
public override void ShowInfo()
{
Console.writeLine("姓名",this.name);
 Console.writeLine("ID",this.ID);
 Console.writeLine("性别",this.sex);
Console.writeline("年龄",this.Age);

public virtual void SetInfo()
{
 this.name = console.ReadLine();
this.ID = console.ReadLine();
this.sex = console.ReadLine();
this.Age = Convert.ToInt32(Console.Readline());
}
}

用记事本写的 写的不规范 代码是正确的 你用VS上新建个项目复制上去就OK

上一个:C#编程,调用
下一个:C#编程 注册问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,