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 group size. The last group would possibly not be filled. Display also the number of students in the last group.
Functions to code and use:
Example:
If there are 23 students and they must be divided into groups of 6, then there will be 4 groups. The last group will have 5 members.
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: {0}", CalcNumberGroups(numberStudents, groupSize))
Console.WriteLine("The last group has {0} members.", 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 Math.Ceiling(numberStudents / 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
Output
Comments
Leave a comment