97213529 郭益銘發表的部落格文章
世界任何人
data:
Employee 阿狗 15.5
Manager 阿貓 40
code:
using System;
using System.IO;
class Employee
{
private string name;
protected float billingRate;
protected float salary;
public Employee(string name, float billingRate)
{
this.name = name;
this.billingRate = billingRate;
}
public float CalculateCharge(float hours)
{
return (salary = hours * billingRate);
}
public float GetSalary()
{
return salary;
}
public string TypeName()
{
return ("Employee");
}
}
class Manager : Employee
{
private float allowance;
public Manager(string name, float billingRate): base(name, billingRate)
{
allowance = 1000;
}
public new float CalculateCharge(float hours)
{
if (hours < 1.0F)
hours = 1.0F;
return (salary = hours * billingRate+allowance);
}
public new string TypeName()
{
return ("Civil Employee");
}
}
class Test
{
public static void Main()
{
Console.Write("請輸入檔案位置:");
string path2 = Console.ReadLine();
StreamReader sr = new StreamReader(@path2,System.Text.Encoding.Default);
string str = sr.ReadToEnd();
string[] s = str.Split('\n');
Employee[] e = new Employee[s.Length];
for (int i = 0; i < s.Length; i++)
{
string[] tmp = s[i].Split(' ');
if (tmp[0] == "Manager")
e[i] = new Manager(tmp[1], float.Parse(tmp[2]));
else if (tmp[0] == "Employee")
e[i] = new Employee(tmp[1], float.Parse(tmp[2]));
}
for (int i = 0; i < e.Length; i++)
{
e[i].CalculateCharge(i * 1.0F + 20.0F);
Console.WriteLine("{0} charge = {1}", e[i].TypeName(), e[i].GetSalary());
}
}
}
Employee 阿狗 15.5
Manager 阿貓 40
code:
using System;
using System.IO;
class Employee
{
private string name;
protected float billingRate;
protected float salary;
public Employee(string name, float billingRate)
{
this.name = name;
this.billingRate = billingRate;
}
public float CalculateCharge(float hours)
{
return (salary = hours * billingRate);
}
public float GetSalary()
{
return salary;
}
public string TypeName()
{
return ("Employee");
}
}
class Manager : Employee
{
private float allowance;
public Manager(string name, float billingRate): base(name, billingRate)
{
allowance = 1000;
}
public new float CalculateCharge(float hours)
{
if (hours < 1.0F)
hours = 1.0F;
return (salary = hours * billingRate+allowance);
}
public new string TypeName()
{
return ("Civil Employee");
}
}
class Test
{
public static void Main()
{
Console.Write("請輸入檔案位置:");
string path2 = Console.ReadLine();
StreamReader sr = new StreamReader(@path2,System.Text.Encoding.Default);
string str = sr.ReadToEnd();
string[] s = str.Split('\n');
Employee[] e = new Employee[s.Length];
for (int i = 0; i < s.Length; i++)
{
string[] tmp = s[i].Split(' ');
if (tmp[0] == "Manager")
e[i] = new Manager(tmp[1], float.Parse(tmp[2]));
else if (tmp[0] == "Employee")
e[i] = new Employee(tmp[1], float.Parse(tmp[2]));
}
for (int i = 0; i < e.Length; i++)
{
e[i].CalculateCharge(i * 1.0F + 20.0F);
Console.WriteLine("{0} charge = {1}", e[i].TypeName(), e[i].GetSalary());
}
}
}