Answer to Question #15366 in C++ for Mandy

Question #15366
Ms Angelina Barnard is the English teacher at Royden High. She shows the movie “Gone with the
wind” to three separate groups of pupils. After each session every pupil who attended the show
has to indicate whether he or she found Scarlett (indicated by S) or Rhett (indicated by R) or any
other character (indicated by any character except S or R) the most interesting character in the
movie. We need a C++ program to count the votes for each of the two main characters and the
votes for all the other characters together. Then the three totals have to be displayed.
The program has the following structure:
90
· The three totals are initialised to 0.
· Now follows a for loop going from 1 to the number of sessions (namely 3).
· Inside the loop a prompting message is displayed asking the user to enter the number of
pupils who attended the specific session.
· Inside this first for loop is another for loop. This loop goes from 1 to the number of pupils
that attended the session.
1
Expert's answer
2012-09-27T11:33:36-0400
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
int n = 0;
int totals[3][3];
for (int i = 0; i < 3; i++)
& for (int j = 0; j < 3; j++)
& totals[i][j] = 0;

for (int i = 0; i < 3; i++) {
& cout << "Enter the number of pupils who attended the session " << i + 1
& lt;< ": ";
& cin >> n;
& for (int j = 0; j < n; j++) {
& cout << "Please indicate whether pupil " << j + 1
& lt;< " found (S, R or any other character): ";
& char c = 'a';
& cin >> c;
& if (c == 'S')
& totals[i][0]++;
& else if (c == 'R')
& totals[i][1]++;
& else
& totals[i][2]++;
& }
}
cout << endl << endl;
cout << setw(12) << "Session" << setw(12) << "Scarlett" << setw(12)
& lt;< "Rhett" << setw(12) << "other" << endl;
for (int i = 0; i < 3; i++)
& cout << setw(12) << i + 1 << setw(12) << totals[i][0] << setw(12)
& lt;< totals[i][1] << setw(12) << totals[i][2] << endl;
return 0;
}

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