Adblock breaks this site

Someone help me please?

Discussion in 'Programming General' started by FreakNasty188, Oct 21, 2011.

  1. FreakNasty188

    FreakNasty188 Active Member

    Joined:
    Jul 15, 2011
    Posts:
    174
    Referrals:
    0
    Sythe Gold:
    0
    Someone help me please?

    I have to write this program for class. Can anyone help me? There's like barely any work I have to do on it, it's supposed to be really easy, I'm just stuck.

    Code:
    /********************************************************************************************
                          10/20/11:  Graded In-Class Exercise (Due by 11:59 PM - 10/21/11)
    
    Write a C++ program that reads a list of grades from the file grades.txt,
    and finds/calculates the average and the letter grade for each student and appends the
    appropriate letter grade for each student to the same data file.
    
    Reading, writing and assigning letter grade should be performed by
    appropriate functions (minimum of two functions needed).
    
    For letter grade use the criteria that was used in class, e.g. =90 is an A, etc.
    
    Hints:
    A file can be opened for input and appended output at the same time.
    When reading from a file the header line should be read outside the loop.
    End of the file has been identified by "zzzzz"
    
    ********************************************************************************************/
    
    /*********************************************
    * file name:
    * programmer name:
    * date created:
    * date of last revision:
    * details of the revision:
    * short description:
    **********************************************/
    
    #include <iostream>
    #include <string>
    #include <fstream>
    using namespace std;
    
    // Function prototypes
    void instructions();
    void writeFile(ofstream& outFile,
                   string firstName,
                   string lastName,
                   char letterGrade);
    void readFile(ifstream& inFile,
                  string& lastName,
                  float& exam1,
                  float& exam2,
                  float& exam3,
                  float& exam4);
    
    int main()
    {
        // Program description
        instructions();
    
        // Declare the variables
        ifstream inFile;
        ofstream outFile;
    
        string firstName,
               input,
               lastName;
    
        float exam1,
              exam2,
              exam3,
              exam4,
              total,
              average;
    
        char letterGrade;
    
        // Open the file for reading & check for failure
    
    	...
    
        // Open the file for writing in append mode & check for failure
    
    	 ...
    
        // Throw out the header
        getline(inFile,input);
        outFile << endl;
    
        // Main calculation
        while (inFile >> firstName && firstName != "zzzzz")   //firstName is read here
        {
            // Call readFile() to read remainder of the line
            ...
    
            //Find the average of the grades
            ...
    
            // Calculate the letter grade
            if (average >= 90)
                letterGrade = 'A';
            else if (average >= 80)
                letterGrade = 'B';
            else if (average >= 70)
                letterGrade = 'C';
            else if (average >= 60)
                letterGrade = 'D';
            else
                letterGrade = 'F';
    
            // Write to the file by calling writeFile()
            ...
        }
    
        // close files
        inFile.close();
        outFile.close();
    
        return(0);
    }
    
    // Function implementations
    void instructions()
    {
        // Add more to the cout statement below
        cout << "This program will calculate the averages of the grades listed in grades.txt\n\n";
    }
    
    void writeFile(ofstream& outFile,
                   string firstName,
                   string lastName,
                   char letterGrade)
    {
        // write data to file
        ...
    }
    
    void readFile(ifstream& inFile,
                  string& lastName,
                  float& exam1,
                  float& exam2,
                  float& exam3,
                  float& exam4)
    {
        // read one line
    	...
    }
    
    
    And here is the text file

    Code:
    Student name	Exam 1	Exam 2	Exam 3	Exam 4
    Jack Nicolas     77	70	65	80
    Amy Brown        55	80	85	90
    Josh Simpson     88	89	92	92
    Michael Lansing  65	74	68	77
    Sara Palm        85	78	80	81
    zzzzz
    
     
  2. gnimoctiwas

    gnimoctiwas Active Member

    Joined:
    Oct 22, 2011
    Posts:
    106
    Referrals:
    0
    Sythe Gold:
    0
    Someone help me please?

    Is what you posted something you need to incorporate or is that what you have written so far?
     
  3. JaminB

    JaminB Forum Addict

    Joined:
    Dec 5, 2010
    Posts:
    308
    Referrals:
    1
    Sythe Gold:
    0
    Someone help me please?

    Off the top of my head something like this?

     
< HangMan VB | Learning to program but what language to start with? >


 
 
Adblock breaks this site