Thread: Help!!!

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

    Unhappy Help!!!

    I have to write a program that reads a student's name together with his or her test scores.The program should then compute the average test score for each student and assign the appropriate grade.

    I must have: A. a void function calculateAverage for the average.
    B. a void function caculateGrade to determine the letter grade


    so far I have:

    Code:
    #include <iostream>
    #include <iomanip>
    #include <cmath>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    void calculateAverage(int,int,int,int,int);
    void calculateGrade(double);
    
    int main()
    {
    	ifstream inFile;
    	ofstream outFile;
    	
    	int test1 = 0,test2= 0,test3= 0,test4= 0,test5= 0;
    	
    	string name;
    
    	inFile.open("c:\\7-6.txt");
    	outFile.open("c:\\7-6output.out");
    
    	outFile<<"Student\t"<<"Test 1\t"<<"Test 2\t"<<"Test 3\t"<<"Test 4\t"<<"Test 5\t"<<"Average\t"<<"Grade"<<endl;
    	inFile>>name, test1,test2,test3,test4,test5;
    	outFile<<<<name<<"\t"<<test1<<"\t"<<test2<<"\t"<<test3<<"\t"<<test4<<"\t"<<test5<<avg<<"\t"<<grade<<endl;
    	
    	return 0;
    }
    void calculateAverage(int test1,int test2,int test3,int test4,int test5)
    {
    
    	return;
    }
    void calculateGrade()
    {
    	return;
    }
    I know it isnt completed, but while running a test run on what I have the program never shows any output only a blank screen....what is wrong?

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by cccstudent
    while running a test run on what I have the program never shows any output only a blank screen....what is wrong?
    your program doesn't write anything to the screen it just writes to a file.
    If you want to see anything on the screen you have to write to cout, cerr or clog.
    Kurt

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> inFile>>name, test1,test2,test3,test4,test5;
    When chainging inputs, you don't use commas. See if you can figure out how to change this to be correct.

    BTW, good job on starting with something small and getting it to work first. That's much smarter than trying to do the whole thing at once.

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    Ok

    that part is good. now I am clueless on how to read each student individually into calculateAverage. I know I need to use a loop somehow, but lost on where to begin. And do I even need
    Code:
    inFile>>name>> test1>>test2>>test3>>test4>>test5;
    in my main function or should it be used in calculateAverage?

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    better not to mix input values and calculations.
    void calculateAverage
    And how do you plan to return the calculated value to the calling function?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    so

    I need to keep my input in my calling function main() and do not use a void function so I can return my calculated average??

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    6
    but I need to call the names and test scores from main to calculateAverage right?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> but I need to call the names and test scores from main to calculateAverage right?
    Do you mean you need to send the names and test scores to calculateAverage? You do need to send the test scores, but the name isn't needed by calculateAverage.

  9. #9
    Registered User
    Join Date
    Nov 2006
    Posts
    6

    yeah

    I have to use a void function for calculateAverage (Exercise calls for a void function) and it looks like this
    Code:
    void calculateAverage(int test1,int test2,int test3,int test4,int test5,)
    but I need to use a loop to read and sum the 5 test scores?

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    Pennsylvania
    Posts
    23
    I am reading over this code and honestly I woulda did it completely different. I never really learned about those files you used yet, but do they do what you need for each of the functions? I mean I would have just put the calculations in the functions being called from the main function. Is this program linked with another program and calling the values from the other program?

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Have you learned pass-by-reference? You can use pass by reference to get the average back from a function.

    If you cannot use that, then you'll have to output the average from the function, which isn't really good design but maybe ok for this assignment.

  12. #12
    Registered User
    Join Date
    Nov 2006
    Posts
    6
    Quote Originally Posted by Daesom
    I am reading over this code and honestly I woulda did it completely different. I never really learned about those files you used yet, but do they do what you need for each of the functions? I mean I would have just put the calculations in the functions being called from the main function. Is this program linked with another program and calling the values from the other program?
    The code i posted earlier was wrong in a sense... the assignment does call for a void function for calculateAverage, but not calculateGrade.The program is not linked with another program.

    The input file looks like this:

    Johnson 85 83 77 91 76
    Aniston 80 90 95 93 48
    Cooper 78 81 11 90 73
    Gupta 92 83 30 69 87
    Blair 23 45 96 38 59
    Clark 60 85 45 39 67
    Kennedy 77 31 52 74 83
    Bronson 93 94 89 77 97
    Sunny 79 85 28 93 82
    Smith 85 72 49 75 63

    It specifies to use a loop in CalculateAverage, but I don't understand what my loop should test for because I have no Sentinel value at the end of my scores, and I probably should have a loop in main testing for EOF.....Am I thinking clearly or spinning my wheels?

Popular pages Recent additions subscribe to a feed