Answer to Question #189737 in Visual Basic for maria

Question #189737

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: 

  • CalcNumberGroups. This function must get the number of students and the group size via parameters. It must calculate and return the number of groups (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 number of students (integer) in the last group.

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.


1
Expert's answer
2021-05-06T02:12:44-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: {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



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