Answer to Question #189552 in Visual Basic for Delight

Question #189552

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


1
Expert's answer
2021-05-05T13:06:18-0400
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS