Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,399 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,222 people online right now. Registration is fast and FREE... Join Now!




c++ function help

 
Reply to this topicStart new topic

c++ function help

anjoz
post 30 Aug, 2008 - 12:23 AM
Post #1


New D.I.C Head

*
Joined: 30 Aug, 2008
Posts: 1

a. Function openFiles: This function opens the input and out 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 female and male students GPA
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 appropriate parameters to pass information in and out of functions

For research purposes and to better help students, the admissions office of your local university want to know how well female and male students perform in certain courses. You receive a file that contains female and male students GPA 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.

cpp

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

void main()
{
ifstream inData;
char gender;
float average_gpa, sum_gpa = 0, gpa;
int count = 0;

inData.open("GPA_Detail.dat");
if(!inData){
cout<<"Cannot open input file. Program terminates!!!\n";
}

cout<<"Processing data...\n";
inData>>gender>>gpa;
count++;
while(!inData.eof()){
sum_gpa += gpa;
inData>>gender>>gpa;
count++;
}

average_gpa = sum_gpa / count;
cout<<fixed;
cout<<"The average gpa is"<<setprecision(2)<<average_gpa<<".\n";

inData.close();
}


i dont know what to do nxt because you need to use all of the function stated above

** Edit ** code.gif
User is offlineProfile CardPM

Go to the top of the page

baavgai
post 30 Aug, 2008 - 02:28 AM
Post #2


Dreaming Coder

Group Icon
Joined: 16 Oct, 2007
Posts: 1,962



Thanked 96 times

Dream Kudos: 475

Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua

My Contributions


This is one of the most poorly designed programs I've ever seen! Not yours, the one that you're being asked to write.

The functions are mostly meaningless and passing data around as requested is pedantic. However, if I were forced to satisfy the requirement, I believe I'd start with something like this:

cpp

typedef struct ResultType {
int countFemale;
int countMale;
float sumFemaleGPA;
float sumMaleGPA;
};

bool openFiles(ifstream &inData) {
inData.open("GPA_Detail.dat", ifstream::in);
if(!inData.is_open()){
cout<<"Cannot open input file. Program terminates!!!\n";
return false;
}
return true;
}

float sumGrades(const ResultType &results) {
return results.sumFemaleGPA + results.sumMaleGPA;
}

void printResults(const ResultType &results) { //...


Hope this helps.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 07:48AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month