陳煜珊109810656
http://s109810656.wikidot.com/system
using System;
using System.Collections.Generic;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
teacher t1 = new teacher("陳福氣", "男", 40, "教授");
teacher t2 = new teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class teacher : Person
{
String Lv;
public teacher(String name, String sex, int age, String Lv)
: base(name, sex, age)
{
this.Lv = Lv;
}
public override Person print()
{
Console.Write("老師 — ");
base.print();
Console.Write(" 職等:" + Lv);
return this;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("陳福氣", "男", 40, "教授");
Teacher t2 = new Teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String level;
public Teacher(String name, String sex, int age, String level)
: base(name, sex, age)
{
this.level = level;
}
public override Person print()
{
Console.Write("教師 — ");
base.print();
Console.Write(" 職等: " + level);
return this;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("陳福氣", "男", 40, "教授");
Teacher t2 = new Teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String level;
public Teacher(String name, String sex, int age, String level )
: base(name, sex, age)
{
this. level= level;
}
public override Person print()
{
Console.Write("教師 — ");
base.print();
Console.Write(" 職等:" + level);
return this;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 -- 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 -- 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 -- 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 -- 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 -- 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("陳福氣", "男", 40, "教授");
Teacher t2 = new Teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:"+name+" 性別:"+sex+" 年齡:"+age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 -- ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String lv;
public Teacher(String name, String sex, int age, String lv)
: base(name, sex, age)
{
this.lv = lv ;
}
public override Person print()
{
Console.Write("教師 -- ");
base.print();
Console.Write(" 職等:" + lv );
return this;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("陳福氣", "男", 40, "教授");
Teacher t2 = new Teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String level;
public Teacher(String name, String sex, int age, String level)
: base(name, sex, age)
{
this.level = level;
}
public override Person print()
{
Console.Write("教師 — ");
base.print();
Console.Write(" 職等:" + level);
return this;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Person
{
/*
* 請定義「人、學生與老師」等三個類別,其中的人有「姓名、性別、年齡」三個欄位,
* 學生另外有「學號、年級」等兩個欄位,老師另外有「職等」的欄位,所有物件都有
* print() 函數,可以將該物件的所有欄位印出。
*
* 請建立一個具有 3 個學生與兩個老師的陣列,利用多型機制,呼叫 print 函數以便
* 印出這 5 個人的基本資料,如下所示。
*
* 學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
* 學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
* 教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
* 學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
* 教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("潘勝利", "男", 20, "教授");
Teacher t2 = new Teacher("小朋友", "女", 18, "實習老師");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String level;
public Teacher(String name, String sex, int age, String level)
: base(name, sex, age)
{
this.level = level;
}
public override Person print()
{
Console.Write("老師 — ");
base.print();
Console.Write(" 職等:" + level);
return this;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Person
{
/*
學生 — 姓名:王小明,性別:男,年齡:20,學號:R773122456,年級:一年級
學生 — 姓名:李小華,性別:女,年齡:19,學號:R773122432,年級:一年級
教師 — 姓名:陳福氣,性別:男,年齡:40,職等:教授
學生 — 姓名:黃大虎,性別:男,年齡:22,學號:R773122721,年級:四年級
教師 — 姓名:李美女,性別:女,年齡:35,職等:助理教授
*/
class Program
{
static void Main(string[] args)
{
Student s1 = new Student("王小明", "男", 20, "R773122456", 1);
Student s2 = new Student("李小華", "女", 19, "R773122432", 1);
Student s3 = new Student("黃大虎", "男", 22, "R773122721", 4);
Teacher t1 = new Teacher("陳福氣", "男", 40, "教授");
Teacher t2 = new Teacher("李美女", "女", 35, "助理教授");
Person[] list = { s1, s2, t1, s3, t2 };
foreach (Person p in list)
{
p.print();
Console.WriteLine();
}
}
}
class Person
{
String name;
String sex;
int age;
public Person(String name, String sex, int age)
{
this.name = name;
this.sex = sex;
this.age = age;
}
public virtual Person print()
{
Console.Write("姓名:" + name + " 性別:" + sex + " 年齡:" + age);
return this;
}
}
class Student : Person
{
String id;
int degree;
public Student(String name, String sex, int age, String id, int degree)
: base(name, sex, age)
{
this.id = id;
this.degree = degree;
}
public override Person print()
{
Console.Write("學生 — ");
base.print();
Console.Write(" 學號:" + id + " 年級:" + degree);
return this;
}
}
class Teacher : Person
{
String level;
public Teacher(String name, String sex, int age, String level)
: base(name, sex, age)
{
this.level = level;
}
public override Person print()
{
Console.Write("教師 — ");
base.print();
Console.Write(" 職等:" + level);
return this;
}
}
}