Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

D COMP2002 Hw3 Fall16 x Homework 3 2 Name the se containing your c source code:

ID: 3777902 • Letter: D

Question

D COMP2002 Hw3 Fall16 x Homework 3 2 Name the se containing your c source code: hwa secowywycppn where your section number should replace not and your own student ID should replace the string nwwY. Grading table: Program runs without syntax errors Comments and Style Variable declaration input and prompt Checking that the files have been successfully Wntingond reading data from/to 19 Looping Flow control Calculation of the averages Displaying the menu Displaying the averages TOTAL Problem Specification Your friend asks you to help him/her in studying the height of a population. He/she wants to store data in a file called "population dat" of the following format a sequence of code and height separated by one space. The code can be either 1, in that case the following height corresponds to a man, or 2, in that case the following height correspond a woman (See Figure las a sample). uncti... docy a Lab10 B.pdf Lab10C (1) pdf ab10.pdf

Explanation / Answer

#include < iostream >;

using namespace std;

int main () {

    int nMale = 0, nFemale = 0, nTotal = 0, choice, sex;

    cout << "    THIS PROGRAM COUNTS AND PRINTS THE NUMBER OF MALES AND FEMALES IN A CLASS ";

    cout << "   ------------------------------------------------------------------------- ";

    cout << "Do you want to start? Enter -1 to exit: ";

    cin >> choice;

    while (choice != -1) {

          cout << " Is population? (1 = yes, 2 = no): ";

          cin >> sex;

          

          if (sex == 1) {

                 nMale += 1;

          } else {

                 nFemale += 1;

          }

          

          nTotal += 1;

                 

          cout << " Do you want to start? Enter -1 to exit: ";

          cin >> choice;

    }

    

    cout << " The total number of MALE students = " << nMale;

    cout << " The total number of FEMALE students = " << nFemale;

    cout << " The total number of population = " << nTotal;

    return 0;

}