Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 88 additions & 1 deletion Lab8/Blue/Task1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,92 @@
{
public class Task1
{
public class Response
{
private string _name;
protected int _votes;

public string Name => _name;
public int Votes => _votes;

public Response(string name)
{
_name = name;
}

public virtual int CountVotes(Response[] responses)
{
int count = 0;
for (int i = 0; i < responses.Length; i++)
{
if (_name == responses[i]._name)
{
count++;
}
}

for (int i = 0; i < responses.Length; i++)
{
if (_name == responses[i]._name)
{
responses[i]._votes = count;
}
}

return count;
}

public virtual void Print()
{
Console.WriteLine("Name: " + _name + ", Votes: " + _votes);
}
}

public class HumanResponse : Response
{
private string _surname;
public string Surname => _surname;

public HumanResponse(string name, string surname) : base(name)
{
_surname = surname;
}

public override int CountVotes(Response[] responses)
{
int count = 0;
for (int i = 0; i < responses.Length; i++)
{

if (responses[i] is HumanResponse humanResp)
{
if (Name == humanResp.Name && _surname == humanResp._surname)
{
count++;
}
}
}

for (int i = 0; i < responses.Length; i++)
{
if (responses[i] is HumanResponse humanResp)
{
if (Name == humanResp.Name && _surname == humanResp._surname)
{
humanResp._votes = count;
}
}
}

return count;
}

public override void Print()
{
Console.WriteLine($"Name: {Name}, Surname: {_surname}, Votes: {_votes}");
}

}
}
}

}
161 changes: 160 additions & 1 deletion Lab8/Blue/Task2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,164 @@
{
public class Task2
{
public struct Participant
{
// Fields / Поля
private string _name;
private string _surname;
private int[,] _marks;

private bool _FirstJump;
private bool _SecondJump;

// Properties / Свойства ///////////////////////////////////////////////////////////////
public string Name => _name;
public string Surname => _surname;
public int[,] Marks
{
get
{
int[,] copy = new int[_marks.GetLength(0), _marks.GetLength(1)];
Array.Copy(_marks, 0, copy, 0, _marks.Length);
return copy;
}
}
public int TotalScore
{
get
{
int total = 0;
foreach (int value in _marks)
total += value;

return total;
}
}
//////////////////////////////////////////////////////////////////////////////////

// Constructor
public Participant(string name, string surname)
{
_name = name;
_surname = surname;
_marks = new int[2, 5]; // jumps, scores
_FirstJump = false;
_SecondJump = false;
}

// Method 1
public void Jump(int[] result)
{
if (result.Length != 5 || result == null || (_FirstJump && _SecondJump))
return;

if (!_FirstJump)
{
for (int j = 0; j < _marks.GetLength(1); j++)
_marks[0, j] = result[j];
_FirstJump = true;
}

else if (!_SecondJump)
{
for (int j = 0; j < _marks.GetLength(1); j++)
_marks[1, j] = result[j];
_SecondJump = true;
}
}

// Method 2
public static void Sort(Participant[] array)
{
Array.Sort(array, (a, b) => b.TotalScore.CompareTo(a.TotalScore));
}

public void Print()
{
return;
}
}

public abstract class WaterJump
{
private readonly string _name;
private readonly int _bank;
private Participant[] _participants;

public string Name => _name;
public int Bank => _bank;
public Participant[] Participants => _participants.ToArray();
public abstract double[] Prize { get; }

protected WaterJump(string name, int bank)
{
_name = name;
_bank = bank;
_participants = [];
}

public void Add(Participant participant)
{
Array.Resize(ref _participants, _participants.Length + 1);
_participants[^1] = participant;
}

public void Add(Participant[] participants)
{
if (participants.Length == 0 || participants == null)
return;

int oldSize = _participants.Length;
Array.Resize(ref _participants, oldSize + participants.Length);

for (int i = 0; i < participants.Length; i++)
_participants[oldSize + i] = participants[i];
}
}

public class WaterJump3m : WaterJump
{
public WaterJump3m(string name, int bank) : base(name, bank) { }
public override double[] Prize
{
get
{
if (Participants.Length < 3)
return null;

return [Bank * 0.5, Bank * 0.3, Bank * 0.2];
}
}
}
public class WaterJump5m : WaterJump
{
public WaterJump5m(string name, int bank) : base(name, bank) { }

public override double[] Prize
{
get
{
if (Participants.Length < 3)
return null;

int count = Participants.Length / 2;
count = Math.Max(count, 3);
count = Math.Min(count, 10);

double[] prize = new double[count];

double extra = Bank * (20.0 / count) / 100;

prize[0] = Bank * 0.40 + extra;
prize[1] = Bank * 0.25 + extra;
prize[2] = Bank * 0.15 + extra;

for (int i = 3; i < count; i++)
prize[i] = extra;

return prize;
}
}
}
}
}
}
Loading
Loading