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

please help! I\'m in intro to c++ programming and do not understand this problem

ID: 3799844 • Letter: P

Question


please help! I'm in intro to c++ programming and do not understand this problem. does not need to be intricate, as this is an introduction course..please help.thanks

23. Create a program that allows the u enter the (either For M) and GPA through for any number of students. The program should calculate and display the average GPA for all students, the average GPA students, and the average GPA for female students. If necessary, create a new project named Intermediate23 Project, and save it in the Cpp8IChap07 folder Enter the C++ instructions into a source file named Intermediate23 cpp. Also enter appropriate comments and any additional instructions required by the compiler. Save, run, and test the program.

Explanation / Answer

//C++ code
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <ctype.h>

using namespace std;

int main()
{
int totalMale = 0;
int totalFemale = 0;
int totalStudents = 0;
double avgGPA = 0, avgGPAmale = 0, avgGPAfemale = 0;
char gender;
double gpa;

while(true)
{
cout << "Enter gender(M/F), q to quit: ";
cin >> gender;

if(gender == 'M')
{
cout << "Enter gpa of male student(0.0-4.0): ";
cin >> gpa;

totalMale++;
avgGPAmale = avgGPAmale + gpa;
avgGPA = avgGPA + gpa;
totalStudents++;
}

else if(gender == 'F')
{
cout << "Enter gpa of female student(0.0-4.0): ";
cin >> gpa;

totalFemale++;
avgGPAfemale = avgGPAfemale + gpa;
avgGPA = avgGPA + gpa;
totalStudents++;
}

else if(gender == 'q')
{
break;
}

else
cout << "Invalid Input ";

cout << endl;
}


avgGPAmale = avgGPAmale / totalMale;
avgGPAfemale = avgGPAfemale / totalFemale;
avgGPA = avgGPA / totalStudents;

cout << " Average GPA of male students " << avgGPAmale << endl;
cout << "Average GPA of female students " << avgGPAfemale << endl;
cout << "Average GPA of all students " << avgGPA << endl;

return 0;
}


/*
output:

Enter gender(M/F), q to quit: M
Enter gpa of male student(0.0-4.0): 3.5

Enter gender(M/F), q to quit: F
Enter gpa of female student(0.0-4.0): 2.3

Enter gender(M/F), q to quit: M
Enter gpa of male student(0.0-4.0): 2.3

Enter gender(M/F), q to quit: M
Enter gpa of male student(0.0-4.0): 4.0

Enter gender(M/F), q to quit: F
Enter gpa of female student(0.0-4.0): 2.1

Enter gender(M/F), q to quit: F
Enter gpa of female student(0.0-4.0): 3.4

Enter gender(M/F), q to quit: M
Enter gpa of male student(0.0-4.0): 2

Enter gender(M/F), q to quit: F
Enter gpa of female student(0.0-4.0): 3

Enter gender(M/F), q to quit: q


Average GPA of male students 2.95
Average GPA of female students 2.7
Average GPA of all students 2.825

*/