我是c#初学者,在练习中出现了点小问题,题目是计算员工的工资增长,(不同员工初始薪水不一样,且增长率也不同,
且员工有编号,及姓名输出),(还有能否给一份c#语言编的用递归做的题目如n!,小弟想熟悉一下语法,多给几个样本也好)
namespace 不同员工的工资计算使用的是多态
{
class Employee //employee基类
{
private string name;
private int sno;
private float rate;
private float sallary;
Employee();
~Employee();
public string Name
{
get { return this.name; }
set
{
if (this.name != value)
this.name = value;
}
}
public int Sno
{
get { return this.sno; }
set
{
if (this.sno != value)
this.sno = value;
}
}
public float Rate
{
get { return this.rate; }
set
{
if (this.rate != value)
this.rate = value;
}
}
public float Sallary
{
get { return this.sallay; }
set
{
if (this.sallay != value)
this.sallay = value;
}
}
public void PrintInfo() { Console.WriteLine("{0}编号是{1}", Name, Sno); }
public virtual void Increase()
{
Sallary = Rate * Sallary; //虚方法便于后面子类的重载,因为不同的员工的学历经历不一样
Console.WriteLine("工资增长{0}", Sallary);
}
}
public class Commonworker : Employee
{
public Commonworker();
}
public class Bachelor : Employee
{
public Bachelor();
public override void Increase() { Sallary = 2 * (Rate * Sallary); }
public class Postgaduate : Employee
{
public Postgaduate();
public override void Increase() { Sallary = 3 * (Rate * Sallary); } class Program
{
static void Main(string[] args)
{
Employee p1 = new Commonworker();
Employee p2 = new Bachelor();
Employee p3 = new Postgaduate();
p1.Name = "Smith";
p1.Sno = 0001;
p1.Sallary = 1000;
p1.Rate = .25;
p1.PrintInfo();
p1.Increase();
p2.Name = "tom";
p2.Sno = 1001;
p2.Sallary = 2000;
p2.Rate = .35;
p2.PrintInfo();
p2.Increase();
p3.Name = "jerry";
p3.Sno = 2001;
p3.Sallary = 3000;
p3.Rate = .75;
p3.PrintInfo();
p3.Increase();
}
}
}
}
}
错误 1 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Commonworker”的可访问性低
错误 2 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Bachelor”的可访问性低 D:\我的文档\Visual Studio 2005\Projects\ConsoleApplication1\不同员工的工资计算使用的是多态\不同员工的工资计算使用的是多态\Program.cs 62 18 不同员工的工资计算使用的是多态错误 3 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Bachelor.Postgaduate”的可访问性低
且员工有编号,及姓名输出),(还有能否给一份c#语言编的用递归做的题目如n!,小弟想熟悉一下语法,多给几个样本也好)
namespace 不同员工的工资计算使用的是多态
{
class Employee //employee基类
{
private string name;
private int sno;
private float rate;
private float sallary;
Employee();
~Employee();
public string Name
{
get { return this.name; }
set
{
if (this.name != value)
this.name = value;
}
}
public int Sno
{
get { return this.sno; }
set
{
if (this.sno != value)
this.sno = value;
}
}
public float Rate
{
get { return this.rate; }
set
{
if (this.rate != value)
this.rate = value;
}
}
public float Sallary
{
get { return this.sallay; }
set
{
if (this.sallay != value)
this.sallay = value;
}
}
public void PrintInfo() { Console.WriteLine("{0}编号是{1}", Name, Sno); }
public virtual void Increase()
{
Sallary = Rate * Sallary; //虚方法便于后面子类的重载,因为不同的员工的学历经历不一样
Console.WriteLine("工资增长{0}", Sallary);
}
}
public class Commonworker : Employee
{
public Commonworker();
}
public class Bachelor : Employee
{
public Bachelor();
public override void Increase() { Sallary = 2 * (Rate * Sallary); }
public class Postgaduate : Employee
{
public Postgaduate();
public override void Increase() { Sallary = 3 * (Rate * Sallary); } class Program
{
static void Main(string[] args)
{
Employee p1 = new Commonworker();
Employee p2 = new Bachelor();
Employee p3 = new Postgaduate();
p1.Name = "Smith";
p1.Sno = 0001;
p1.Sallary = 1000;
p1.Rate = .25;
p1.PrintInfo();
p1.Increase();
p2.Name = "tom";
p2.Sno = 1001;
p2.Sallary = 2000;
p2.Rate = .35;
p2.PrintInfo();
p2.Increase();
p3.Name = "jerry";
p3.Sno = 2001;
p3.Sallary = 3000;
p3.Rate = .75;
p3.PrintInfo();
p3.Increase();
}
}
}
}
}
错误 1 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Commonworker”的可访问性低
错误 2 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Bachelor”的可访问性低 D:\我的文档\Visual Studio 2005\Projects\ConsoleApplication1\不同员工的工资计算使用的是多态\不同员工的工资计算使用的是多态\Program.cs 62 18 不同员工的工资计算使用的是多态错误 3 可访问性不一致: 基类“不同员工的工资计算使用的是多态.Employee”比类“不同员工的工资计算使用的是多态.Bachelor.Postgaduate”的可访问性低
static void Main(string[] args)
{
Console.WriteLine(Calc(3));
Console.ReadKey();
}
private static int Calc(int num)
{
if (0 == num || 1 == num)
return 1;
else
return num * Calc(num - 1);
}
在类定义时加上public
{
return index <= 2 ? 1 : Fibonacci(index - 1) + Fibonacci(index - 2);
}
public int Fibonacci(int index)
{
return index <= 1 ? 1 : (index ) *Fibonacci(index - 1);
}
}
static void Main(string[] args)
{ Fib f = new Fib();
f.Fibonacci(5);
Console.Write("{0}", f.Fibonacci(5));}