Question
C++ program
For research purposes and to better help students, the admissions office of your local university wants to know how well fema
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void initialize(int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA,double& avgMaleGPA, double& avgFemaleGPA);
void openFiles(ifstream& inFile);
void sumGrades(int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA,ifstream& inFile);
void averageGrade(double& avgMaleGPA, double& avgFemaleGPA,int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA);
void printResults(double& avgMaleGPA,double& avgFemaleGPA);
int main() {
ifstream inFile;

int countFemale, countMale;
double sumFemaleGPA, sumMaleGPA;
double avgFemaleGPA, avgMaleGPA;

initialize(countMale,countFemale,sumMaleGPA,sumFemaleGPA,avgMaleGPA,avgFemaleGPA);
openFiles(inFile);
sumGrades(countMale,countFemale,sumMaleGPA,sumFemaleGPA,inFile);
averageGrade(avgMaleGPA,avgFemaleGPA,countMale,countFemale,sumMaleGPA,sumFemaleGPA);
printResults(avgMaleGPA,avgFemaleGPA);

inFile.close();


return 0;
}
void initialize(int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA,double& avgMaleGPA, double& avgFemaleGPA)
{
countFemale = 0, countMale = 0;
sumFemaleGPA = 0, sumMaleGPA = 0;
avgFemaleGPA = 0, avgMaleGPA = 0;
}
void openFiles(ifstream& inFile)
{
inFile.open("gpainput.txt");

}
void sumGrades(int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA,ifstream& inFile) {
char ch ;
double GPA;
while (inFile >> ch >> GPA) {
  inFile >> ch >> GPA;
  if (ch =='m') {
   sumMaleGPA = sumMaleGPA + GPA;
            countMale++;
  } else if (ch =='f'){
   sumFemaleGPA = sumFemaleGPA + GPA;
   countFemale++;
  }
}

}
void averageGrade(double& avgMaleGPA, double& avgFemaleGPA,int& countMale,int& countFemale,double& sumMaleGPA,double& sumFemaleGPA) {
avgMaleGPA = sumMaleGPA / countMale;
avgFemaleGPA = sumFemaleGPA / countFemale;

}
void printResults(double& avgMaleGPA,double& avgFemaleGPA) {
cout << "Average Male GPA: " << avgMaleGPA
   << "\nAverage female GPA: " << avgFemaleGPA << endl;
}

Add a comment
Know the answer?
Add Answer to:
C++ program For research purposes and to better help students, the admissions office of your local...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it...

    C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it at the city, county and state level. A research project on population distribution in the Southeast US has acquired a data file from the Census Bureau that contains the populations of each county in Mississippi (MS) and Florida (FL). For this research project write a program that calculates the average county population for these two states. Each line in the Census Bureau data file...

  • use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is...

    use c++ Weighted GPA Calculator2 Many schools factor in the number of credits each course is worth, meaning a 4-credit class has more value than a 2-credit class when calculating students GPA Suppose the following were the grades for a student CreditsGrade lass Pre-Calculus History Chemistry Physical Education 1 Letter grades are assigned as follows Letter grades are worth these points 0-60 F 61 -70 D 71 80 C 81 -90 B 91 -100 A Class Pre-Calculus History Chemistr)y Physical...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did...

    c++ CSI Lab 6 This program is to be written to accomplish same objectives, as did the program Except this time we modularize our program by writing functions, instead of writing the entire code in main. The program must have the following functions (names and purposes given below). Fot o tentoutefill datere nedefremfite You will have to decide as to what arguments must be passed to the functions and whether such passing must be by value or by reference or...

  • Write a C++ program to store and update students' academic records in a binary search tree....

    Write a C++ program to store and update students' academic records in a binary search tree. Each record (node) in the binary search tree should contain the following information fields:               1) Student name - the key field (string);               2) Credits attempted (integer);               3) Credits earned (integer);               4) Grade point average - GPA (real).                             All student information is to be read from a text file. Each record in the file represents the grade information on...

  • Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a...

    Program 5 Due 10/25 C-String and Two-dimensional Array Use An input data file starts with a student's name (on one line). Then, for each course the student took last semester, the file has 2 data lines. The course name is on the first line. The second line has the student's grade average (0 to 100) and the number of credits for the course Sample data: Jon P. Washington, Jr. Computer Science I 81 4 PreCalculus 75 3 Biology I 88...

  • C++ Write a program that reads students’ names followed by their test scores from the given...

    C++ Write a program that reads students’ names followed by their test scores from the given input file. The program should output to a file, output.txt, each student’s name followed by the test scores and the relevant grade. Student data should be stored in a struct variable of type StudentType, which has four components: studentFName and studentLName of type string, testScore of type int and grade of type char. Suppose that the class has 20 students. Use an array of...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT