programming function help

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.


#include
#include
#include

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!!!
";
}

cout<<"Processing data...
";
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<<".
";

inData.close();
}

i dont know what to do nxt because we need to use all of the functions stated above

Comments

  • : Rewrite the program developed below so that the function main is
    : merely a collection of function calls. Your program should use the
    : following functions.
    :
    : 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.
    :
    :
    : #include
    : #include
    : #include
    :
    : 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!!!
    ";
    : }
    :
    : cout<<"Processing data...
    ";
    : 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<<".
    ";
    :
    : inData.close();
    : }
    :
    : please also add an explination
    :

    Great! You've mastered the Ctrl+C button. Now let's move on with basic OS operation course Nr 2. Please try to move your mouse to the upper left corner. Good!

    This is a homework question. And all you've done for it is Copy&Paste. And if we answer it for you all you will do is Copy&Paste a second time. Anyone can do that. I take it you're not serious about learning to program?

    Your post (and therefore mine) will probably be deleted soon, unless you show that you've atleast made some effort! We're willing to help you, but you have to show that you're willing to learn.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry

  • : i dont know what to do nxt because we need to use all of the
    : functions stated above
    :
    Have two source files. Call one main and put your main functiona and your main fucntion only in it. Then write the functions you've been given in the other files.
    Start with openfiles. Presumably this will take an instream& and an outstream&. It will return a boolean for success or fail. If you fail to open weither file, write a dignostic to cerr.
    Then test this function. Does it work? Does it fail nicely when you pass it a non-existent filename for the input? An illegal filename for the output?
    Then write and test closefiles(). Write a little test string to the output file, and see whether the file is created properly.

    Then write the other fucntions. All the time you are putting test code into main(), to make sure that each function works as specified.

    The last thing you write is the real main(). You've got all your functions, now main() just pastes them together to make a complete program. Since all the functions work, main() should be very easy to write.
  • : 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.


    The most logical step, is to actually make the functions above, and do your own CS homework.

    Here's a few hints, in a VERY generic sense:

    function openFiles(File input, File output)
    open input
    if(success)
    open output
    if(success)
    File inputGlobal=Input
    File outputGlobal=Output
    else "Invalid output file"
    else "Invalid input file"
    return

    function initialize(int a,...)
    a=0
    ...=0
    return

    I think you get the idea. If not, I'll gladly keep giving you this excellent code for a nominal fee.

    On a more serious note, unless my computer is messing with me, not only did you just paste in some code, you also missed parts, and put in ZERO effort. Unless, that is, if you wrote that code, in which case, I don't think you'd be asking what to do next.

    Make the functions, look at what they are supposed to do, and figure out how to use them to do your intended task. Open your files and initialize your vars, scan for a gender, add the GPA to the running total of that gender, then, when you reach the EOF, figure out the GPA for each gender, format it, then output it to screen and file.

    It's just that simple.

    I'll be honest, I'm tired, so I hardly read the code; if I made an incorrect assumption in my reply, cut me some slack!!!

    This really isn't the place to ask really generic questions like "What do I do next?" Get a little more specific, specific questions (a) let us know what you really need help with, (b) saves us all time in figuring out what you need to do, and (c) let's us know that you aren't just trying to get us to do your homework for you.

    In other words, help us help you help yourself.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories