Create an IPO chart and a program that allows the user to enter the gender ( eit
ID: 3856079 • Letter: C
Question
Create an IPO chart and a program that allows the user to enter the gender ( either F or M) and GPA (0.0 through 4.0) for any number of students. The program shuld calculate and display the average GPA for all students, the average GPA for male students, and the average GPA for female students. If necessary, create a new project named Intermediate23 Project, and save it in te Cpp8Chap07 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
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.