Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

‫מבחן במדמח אשכול ב’ איתי גליק‬

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();
}

public static bool IsPair(Node<int> n)


{
Node<int> p = n; // Check if
int prev = p.GetValue(); there are two
p = p.GetNext(); consecutive equal
int curr = p.GetValue(); numbers.
while (p != null)
{
if (prev == curr)
{
return true;
}
prev = curr;
p = p.GetNext();
if (p.GetNext() == null)
{
return false;
}
curr = p.GetValue();

}
return false;
}

public static bool IsFirstequalLast(Node<int> n) } // check if


{ first equal
Node<int> p = n; to last
int first = p.GetValue();
int last = 0;
while (p != null)
{
last = p.GetValue();
p = p.GetNext();
}
return last == first;
}
‫א‪+‬ב ‪3.‬‬

You might also like