Code a program to get the number of students and the group size from the user. Calculate and display the number of groups that must be used to divide the students in the given size. The last group would possibly not be filled. Display also the number of students in the last group.
Functions to code and use:
●CalcNumberGroups. This function must get the number of students and the group size via parameters. It must calculate and return the number of group(integer) that would be used
●CalcLastGroupSize. This function must get the number of students and the group size via parameters. It must calculate and return the number of students(integer) in the last group
Module Module1
Sub Main()
'Get the number of students and the group size from the user.
Console.Write("Enter the number of students: ")
Dim numberStudents As Integer = Integer.Parse(Console.ReadLine())
Console.Write("Enter the group size: ")
Dim groupSize As Integer = Integer.Parse(Console.ReadLine())
Console.WriteLine("The number of groups that would be used: {0}", CalcNumberGroups(numberStudents, groupSize))
Console.WriteLine("The number of students in the last group: {0}", CalcLastGroupSize(numberStudents, groupSize))
Console.ReadLine()
End Sub
''' <summary>
''' This function must get the number of students and the group size via parameters.
''' It must calculate and return the number of group(integer) that would be used
''' </summary>
''' <param name="numberStudents"></param>
''' <param name="groupSize"></param>
''' <returns></returns>
''' <remarks></remarks>
Function CalcNumberGroups(ByVal numberStudents As Integer, ByVal groupSize As Integer) As Integer
Return (numberStudents - CalcLastGroupSize(numberStudents, groupSize)) / groupSize
End Function
''' <summary>
''' This function must get the number of students and the group size via parameters.
''' It must calculate and return the number of students(integer) in the last group
''' </summary>
''' <param name="numberStudents"></param>
''' <param name="groupSize"></param>
''' <returns></returns>
''' <remarks></remarks>
Function CalcLastGroupSize(ByVal numberStudents As Integer, ByVal groupSize As Integer) As Integer
Return (numberStudents Mod groupSize)
End Function
End Module
Comments
Leave a comment