Thread: Help!!!

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    11

    Help!!!

    HELP with a C++ program reading students grades from an infile and outputing the results to outfile?
    I have to write a program the reads students grades together with their test grades. It suppose to compute the average test scores an then assign the appropriate grade. have to use a void function to determine the average for the five test scores and a value returning function to determine and return each students grade. the students grades are on an infile and i have to output it to an outfile.

    This is what i have:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    
    
    calculateGrade(float);
    int main ()
    {
    ifstream infile;
    infile.open("C:\inGrade.dat");
    
    
    
    
    ofstream outfile;
    outfile.open("C:\FinalGrades.t...
    
    calculateGrade()
    
    
    infile.close ();
    outfile.close ();
    
    
    system("pause");
    return 0;
    }
    
    void calculateGrade(string, float)
    {
    if (average>=90)
    outfile<<"A"<<endl;
    else if(average>=80)
    outfile<<"B"<<endl;
    else if (average>=70)

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    calculateGrade() has no closing brace.
    Code:
    outfile.open("C:\FinalGrades.t...
    calculateGrade()
    The first line is missing ");, the second ;. Also, calculateGrade() takes two parameters.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    yea that was a typo on my part i fixed it. but i still need help with the functions

  4. #4
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    what functions do you need?

    describe them in detail

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    a voidfunction calculateAvg to determine the average of the five test scores for each student. use a loop to read and sum the five test scores

    then a value returning calculateGrade to determine and return each students grade

  6. #6
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    an example of a "for loop"
    Code:
    length = 2;
    for (int i = 0;i < length;++i)
    {
       cout << i << ' ';
    }
    Outputs : "0 1 2 "
    Experiment with the "for loop" and try to get a grip on it (basically, it's for repeating a task for a certain number of times. in your case, the number of grades the student has. and the task to be performed is the addition of those grades and after the for loop ou have to divide the sum of the grades with the number of the grades to get an avg.
    read this: http://www.intap.net/~drw/cpp/cpp04_03.htm

    I am not sure what does the calculateGrade do, but I tink that it should call the calculateAvg function and then return it's calculated average.

    gl

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    The output should be like this (Fill the last two columns and the last line
    showing the class average.)
    Student Test1 Test2 Test3 Test4 Test5 Average Grade
    Balto 85 83 77 91 76 ?? ?
    Mickey 80 90 95 93 48 ?? ?
    Minnie 78 81 11 90 73 ?? ?
    Doc 92 83 30 69 87 ?? ?
    Goofy 23 45 96 38 59 ?? ?
    Duckey 60 85 45 39 67 ?? ?
    Grumpy 27 31 52 74 83 ?? ?
    Sunny 93 94 89 77 97 ?? ?
    Piggy 79 85 28 93 82 ?? ?
    Pluto 85 72 49 75 63 ?? ?

    Class Average: ?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Shouldn't Average = Grade?
    I don't know the grading system there, but here, the grade is based on the average.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    yea the grade is based on average i gotta output them both and give the grade as a letter. The grade
    scale is: 90-100, A; 80-89, B; 70-79, C; 60-69, D; 0-59, F.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    you can calculate the average using the for loop.

    Do you need any help with it? I am not going to do your entire homework for you - I'd rather just guide you so we both profit from the situation.

  11. #11
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    yea thats cool cuz i need sum serious help

  12. #12
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Quote Originally Posted by hardi
    an example of a "for loop"
    Code:
    length = 2;
    for (int i = 0;i < length;++i)
    {
       cout << i << ' ';
    }
    Outputs : "0 1 2 "
    Experiment with the "for loop" and try to get a grip on it (basically, it's for repeating a task for a certain number of times. in your case, the number of grades the student has. and the task to be performed is the addition of those grades and after the for loop ou have to divide the sum of the grades with the number of the grades to get an avg.
    read this: http://www.intap.net/~drw/cpp/cpp04_03.htm

    I am not sure what does the calculateGrade do, but I tink that it should call the calculateAvg function and then return it's calculated average.

    gl
    Take a look at the for loop example.

  13. #13
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    what two parameters would I need?

  14. #14
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    Quote Originally Posted by ryang
    what two parameters would I need?
    "for loop" requires 3 parameters.

    What you should do:
    1st: figure out the number of times the "for loop" has to run.
    2nd: figure out the actual algorithm that the "for loop" has to carry out.

  15. #15
    Registered User
    Join Date
    Nov 2006
    Posts
    11
    im talkin about for the function calculate grade

Popular pages Recent additions subscribe to a feed