类与继承练习题(2)

2019-04-08 21:14

class Teacher : Person {

private string title; private string department;

public Teacher(int tid, string tname, string ttitle, string tdep) : base(tid, tname) {

title = ttitle; department = tdep; }

public override void infoPrint() {

Console.WriteLine(\ Teacher's Id: {0}\, id); Console.WriteLine(\ Teacher's Name: {0}\, name); Console.WriteLine(\ Teacher's Title: {0}\, title);

Console.WriteLine(\ Teacher's Department: {0}\, department); } }

class Student : Person {

private int classNum ; private int score;

public Student(int tid, string tname, int cNum, int sco) : base(tid, tname) {

classNum = cNum; score = sco; }

public override void infoPrint() {

Console.WriteLine(\ Student's ID: {0}\, id); Console.WriteLine(\ Student's Name: {0}\, name);

Console.WriteLine(\ Student's Class number: {0}\, classNum); Console.WriteLine(\ Student's Score: {0}\, score); } } }

//Program.cs

using System;

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

namespace TeacherAndStudent

{

class Program {

static void Main(string[] args) {

Console.WriteLine(\);

Teacher t = new Teacher(86, \, \, \); t.infoPrint();

Console.WriteLine(\);

Student s = new Student(101, \, 2, 90); s.infoPrint(); } } }

情况二: //Person.cs

using System;

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

namespace TeacherAndStudent {

class Person {

private int id; private string name;

public Person(int pid, string pname) {

id = pid; name = pname; }

public virtual void infoPrint() {

Console.WriteLine(\, id); Console.WriteLine(\, name); } }

class Teacher : Person {

private string title; private string department;

public Teacher(int tid, string tname, string ttitle, string tdep)

: base(tid, tname) {

title = ttitle; department = tdep; }

public override void infoPrint() {

base.infoPrint();

Console.WriteLine(\, title);

Console.WriteLine(\, department); } }

class Student : Person {

private int classNum ; private int score;

public Student(int tid, string tname, int cNum, int sco) : base(tid, tname) {

classNum = cNum; score = sco; }

public override void infoPrint() {

base.infoPrint();

Console.WriteLine(\, classNum); Console.WriteLine(\, score); } } }

//Program.cs

using System;

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

namespace TeacherAndStudent {

class Program {

static void Main(string[] args) {

Console.WriteLine(\);

Teacher t = new Teacher(86, \, \, \);

t.infoPrint();

Console.WriteLine(\);

Student s = new Student(101, \, 2, 90); s.infoPrint(); } } }


类与继承练习题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:重邮研究生招生

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: