Answer to Question #330551 in C++ for LM.

Question #330551

A teacher divides her class in different group (gr) sizes according to the

activity they have to do. Write a program to determine the number (nr) of groups as well as the nr of pupils (p) who are left to form a smaller gr. They're 56 in the class.

Program structure:

• Declare 3 int variables nrPupils, nrGroups, and nrLeft. nrPupils is the

nr of ps in a class, nrGroups is the nr of grs the class is divided into, and nrLeft is the nr of ps who're in the remaining smaller gr.

• Assign the value 56 to nrPupils.

• Declare an int variable groupSize that's used by a cin statement to input a value from the keyboard and store the size of the grs the teacher requested. Display a message. E.g. Please enter the size of each gr?

• Write the statement to calculate the nr of grs of size groupSize.

• Write the statement to calculate the nr of ps who're in the remaining smaller gr.

The output of the program must be displayed as follows:

There are 9 grs consisting of 6

pupils There are 3 remaining pupils



1
Expert's answer
2022-04-19T03:08:23-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