Answer to Question #332831 in C++ for Padi Tlhabane

Question #332831

Teacher at Leva P School needs to divide her class in different group sizes due to activity they have to do. Help her to prepare workstations for each group. For art projects the class divided in groups of 6; science projects in groups of 4. She asked to write program to get number of groups and number of pupils left to form a smaller group. There are 56 pupils in the class.

Declare three int variables nrPupils, nrGroups, and nrLeft. nrPupils represents the

number of pupils in a class, nrGroups number of groups the class divided into, and nrLeft number of pupils remaining smaller group. Assign the value 56 to nrPupils. Declare an int variable groupSize that is used by a cin statement to input a value from the keyboard and store the size of the groups the teacher requested. Display an appropriate message. Please enter the size of each group? Write the statement to calculate the number of groups of groupSize. Write the statement to calculate the number of pupils who are in the remaining smaller group


1
Expert's answer
2022-04-23T09:04:06-0400
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int	nrPupils, nrGroups, nrLeft;
	cout << "Please, enter a number of pupils: ";
	cin >> nrPupils;
	int groupSize;
	cout << "Please, enter the size of each group: ";
	cin>> groupSize;
	nrGroups = nrPupils / groupSize;//calculate the nr of grs of size groupSize
	nrLeft = nrPupils % groupSize;//nrPupils / groupSize
	cout << "There are " << nrGroups << " grs consisting of " << groupSize
		<<" pupils. There are " << nrLeft << " remaining pupils";
}

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