a) Write a method GetOneStudent that asks a student for both of his/her WRAV101 and
WRSC111 marks (each as a real number). The method must return both of these marks. The
method must ensure that each of the marks is in the range 0 to 100.
b) Write a method CanContinue that takes as input two marks, one for WRAV101 and one for
WRSC111. Each of these marks is in the range 0 to 100. The method must return the value
true if both of these marks are at least 50, otherwise the method must return the value false.
c) Write a method DisplayDecision that takes as input two marks, one for WRAV101 and one
for WRSC111. Each of these marks is in the range 0 to 100. If the student can continue with
the second semester modules (use CanContinue above), an appropriate message and the
average mark for the two modules is displayed, otherwise the student is informed that he may
not continue.
class Program
{
static void Main()
{
(int WRAV101, int WRSC111) = GetOneStudent();
DisplayDecision(WRAV101, WRSC111);
}
static (int WRAV101, int WRSC111) GetOneStudent()
{
return (Read("Enter the WRAV101 mark (0-100): "),
Read("Enter the WRAV101 mark (0-100): "));
}
static bool CanContinue(int WRAV101, int WRSC111)
{
return new int[] { WRAV101, WRSC111 }.All(m => m >= 50);
}
static void DisplayDecision(int WRAV101, int WRSC111)
{
bool canContinue = CanContinue(WRAV101, WRSC111);
string message = canContinue ?
$"Student can continue studing. (Average mark is {(WRAV101 + WRSC111) / 2})." :
"The marks too low, Student cannot continue studing.";
Console.WriteLine(message);
}
static int Read(string message, int min = 0, int max = 100)
{
while (true)
{
Console.Write(message);
if (int.TryParse(Console.ReadLine(), out int result) &&
result >= min && result <= max)
return result;
Console.WriteLine("Incorrect value of mark, pleae, try again!");
}
}
}
Comments
Leave a comment