Professional Documents
Culture Documents
מבחן במדמח אשכול ב. תרגולdocx
מבחן במדמח אשכול ב. תרגולdocx
מבחן במדמח אשכול ב. תרגולdocx
1.א.
public static int AddStudent (Queue<Kita> q, int grade)
{
while (!q.IsEmpty())
{
if ((q.Head().GetGrade() = grade)&&(q.Head().GetNumOfStudent()<30))
{
q.Head().AddStudents(1);
return q.Head().GetNumber();
}
q.Remove();
}
return -1;
}
1. ב.
public static bool IsThere(Queue<Kita> q)
{
int max =0;
Kita kita = null;
q.Insert(kita);
while (q.Head()!=null)
{
if (q.Head().GetNumOfStudent() > max)
{
max = q.Head().GetNumOfStudent();
}
q.Insert(q.Remove());
}
q.Remove();
while (q.IsEmpty())
{
if ((max + q.Head().GetNumOfStudent()) == 50)
{
return true;
}
}
return false;
}
2.א.
2. ד+ .ב
class Player
{
protected string Name;
protected int Number;
protected string StrongFoot;
protected bool Starter;
public string GetName()
{
return Name;
}
public virtual int Salary()
{
return 9000;
}
}
class Goalkeeper:Player
{
protected int NumSaves;
public int GetNumSaves()
{
return NumSaves;
}
public override int Salary()
{
if (this.NumSaves < 20)
{
return 10000;
}
return 9000;
}
}
class Captain : Player
{
private string BandColor;
public string GetBandColor()
{
return BandColor;
}
public override int Salary()
{
if (this.BandColor == "Green")
{
return 12500;
}
return 11500;
}
}
2. ג.
public void AddPlayer(Player p)
{
if (p is Captain)
{
this.captain = (Captain)p;
return;
}
else if (p is Goalkeeper)
{
this.goalKeeper = (Goalkeeper)p;
return;
}
else if (p is Player)
{
if (this.players[15] == null)
{
this.players[15] = p;
for (int i = 0; i < this.players.Length; i++)
{
if (this.players[i].GetName()==p.GetName())
{
this.players[15] = null;
Console.WriteLine("Change your number");
}
}
return;
}
else
{
Console.WriteLine("The team is full");
return;
}
}
}
2.ה
public int TotalSalary()
{
int ans = 0;
ans += this.captain.Salary();
ans += this.goalKeeper.Salary();
for (int i = 0;i < this.players.Length; i++)
{
ans += this.players[i].Salary();
}
return ans;
}
יצירת שרשרת
public static Node<int> CreateChain(int n)
{
Node<int> first = new Node<int>(-1);// וחוליה ראשנה שלא תוחזר
Node<int> p = first;
Console.WriteLine("insert {0} numbers", n);
for (int i = 0; i < n; i++)
{
int num = int.Parse(Console.ReadLine());
Node<int> newNode = new Node<int>(num);
p.SetNext(newNode);
p = newNode;
}
return first.GetNext();
}
}
return false;
}