Purchase Solution

# User Defined Functions: Example Problem

Not what you're looking for?

You receive a file that contains female and male student GPA's for certain courses. Due to confidentiality, the letter code f is used for female students and m for male students. Every file entry consists of a letter code followed by a GPA. Each line has one entry. The number of entries in the file is unknown. Write a program that computes and outputs the average GPA for both female and male students. Format your results to two decimal places.

When creating this program please write the program so that the function main, in addition to the variable declaration, is merely a collection of function calls. Your program should use the following functions:

a. Function openFiles: This function opens the input and output files, and sets the output of the floating-point numbers to two decimal places in a fixed decimal format with a decimal point and trailing zeros.

b. Function initialize: This function initializes variables such as countFemale, countMale, sumFemaleGPA, and sumMaleGPA.

c. Function sumGrades: This function finds the sum of the female and male students GPAs.

d. Function averageGrade: This function finds the average GPA for female and male students.

e. Function printResults: This function outputs the relevant results.

f. There can be no global variables. Use the appropriate parameters to pass information in and out of functions.

##### Solution Summary

Provides a written program using the given functions.

##### Solution Preview

#include<iostream.h>
#include<fstream.h>
#include<string.h>

void openFiles();
void initialize(int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA,double FaverageGrade, double MaverageGrade);
void sumGrades(int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA);
void printResults(int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA,double FaverageGrade, double MaverageGrade);

void main( )
{
int countFemale =0;
int countMale=0;
double sumFemaleGPA=0.0;
double sumMaleGPA=0.0;
...

##### Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.

##### Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

##### Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

##### C++ Operators

This quiz tests a student's knowledge about C++ operators.

##### Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.