Need Help

I am a beginner and need help with this program. i dont know where to start, if you all can help me it will be good.


Student grade records are stored in “Student Data.txt” file.

Your tasks are:

1.define a structure for student grade records for data
stored in file with additional fields for average exam
score and grade.
2. declare an array of records on the HEAP.
3. populate from the file: “Student Data.txt”.
4. define a function to display student records (formatted).
5. define a function to compute average and
populate average field.
6. define a function to compute the grade and
populate grade field.
7. define a function to compute class average.
8. define a function to compute class standard deviation.
9. display class average and standard deviation.
10. demonstrate ALL functions.

11. Use this assignment as the cover sheet.
12. Document your test results.
13. List your source code.


Here is "Student Data.txt" info

Amy Adams
10111
97 86 78 95
Ben Barr
20222
89 81 73 87
Carla Carr
30333
79 71 63 77
Don Davis
40444
69 62 58 67
Edna Eaton
50555
63 51 62 48

This assignment requires the use of structures, arrays, files and functions. How can you be at this coding level and not know where to start? At least make an attempt. Maybe do the function prototypes so you know what datatypes you will be passing around. Or write up a quick flowchart to help guide you through the program logic.
ok here it is i have tried...
i dont know what to do next

//  main.cpp


#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void displaystudentrecords();
void computeaverage();
void computethegrade();
void classaverage();
void classstandarddeviation();

int main()
{
    double average = 0;
    double& averageRef = average;
    double class_average = 0;
    double& class_averageRef = class_average;
    int sum_of_test_scores = 0;
    int& sum_of_test_scoresRef = sum_of_test_scores;
    double standard_deviation = 0;
    
    //2D Array.
    const int students = 5;
    const int test_scores = 4;
    int scores[students][test_scores];
    
    //Arrays on the heap.
    string* arrayNames = nullptr;
    arrayNames = new string[students];
    string* arrayNamesRef = arrayNamesRef;
    
    int* arrayID = nullptr;
    arrayID = new int[students];
    
    int* arrayAverage = nullptr;
    arrayAverage = new int[students];
    
    int* arrayLetterGrade = nullptr;
    arrayLetterGrade = new int[students];
    
    ifstream inputFile;
    // Open the file.
    inputFile.open("Student Data.txt");
    
    // do an initial test.
    cout<<boolalpha;
    cout<< "Is the file good? --> "<<inputFile.good()<<endl<<endl;
    
    if (inputFile.fail())
        cout << "Can't open the file!" << endl;
    else
    {
        for( int i(0); i != 5; i++ )
        {
            // read name.
            getline(inputFile, arrayNames[i]);
            
            // read student id.
            inputFile >> arrayID[i];
            
            // read four(4) scores.
            for( int j(0); j != 4; j++ )
            {
                inputFile >> scores[i][j];
            }
            
            string str;
            
            // consume '\n' char (Use getline for mac/Xcode!!!).
            getline (inputFile, str);
            
            cout << "I have read "<<i+1 <<" record/s\n\n";
        }// end read loop.
        
        struct studentinfo //(grade records for data stored in file with additional fields for average exam score and grade.)
        {
            int student_grade_records;
            double average_exam_score;
            int grade;
        };
        
        displaystudentrecords();
        classaverage();
        classstandarddeviation();
    }
    return 0;
}// End Main.

void displaystudentrecords()
{
    for( int i(0); i != 5; i++ )
    {
        cout << "Name: "<< arrayNames[i];
        
        cout << "ID: " << arrayID[i] <<endl;
        
        for( int j(0); j != 4; j++ )
        {
            cout << "Test scores: " << scores[i][j] << endl;
            
            sum_of_test_scores += scores[i][j];
        }
        cout << endl;
        computeaverage();
    }
}// End displaystudentrecords.

void computeaverage()
{
    average = sum_of_test_scores / test_scores;
    cout << "The average is: " << average << endl;
    
}// compute average.

void computethegrade()
{
    if (average > 100)
    {
        cout << "invalid average for grade please try again." << endl;
    }
    else if(average >= 90 && average <= 100)
    {
        cout << "Letter grade is A!" << endl;
    }
    else if (average >= 89 && average <= 80)
    {
        cout << "Letter grade is B" << endl;
    }
    else if (average >= 79 && average <= 70)
    {
        cout << "Letter grade is C" << endl;
    }
    else if (average >= 79 && average <= 60)
    {
        cout << "Letter grade is D" << endl;
    }
    else
    {
        cout << "Letter grade is F!" << endl;
    }
    
    cout << endl;
    
}// End compute the grade.

void classaverage()
{
    class_average = sum_of_test_scores / test_scores;
    cout << "The class average is: " << class_average << endl;

}// End class average.

void classstandarddeviation()
{
    standard_deviation = sqrt(pow(exam_scores[count] - average, 2.0) / SIZE);
    cout << "The standard deviation is: " << standard_deviation << endl << endl;
    
}// End class standard deviation.
Last edited on
Topic archived. No new replies allowed.