I need help figuring this out. What I need is this:

  1. The section number, as a string
  2. The instructor's name, also as a string
  3. The number of students in this section, as an integer.
  4. The student's scores for the test, as an array of integers. Declare this array to be of size 30. Do Not use a vector in this exercise!

provide the following member functions in your class:

  1. A constructor that takes the section and instructor's name. It should set the number of students to zero and initialize all of the array elements to zero.
  2. A readData( )function to read in student scores from a file. This function should verify that the file opened correctly, and that each piece of data was successfully read. As you read in each score, store it in the array, and increment the variable that holds the number of students in the class. Read until you encounter an end of file condition.
  3. a function that returns the number of scores stored in the array,
  4. a function that takes in integer value as a parameter, and returns the score at that position in the array of scores.
  5. a function that returns the highest score on the test,
  6. a function that returns the lowest score on the test,
  7. a function that calculates the average score on the test, and
  8. optionally a function that sorts the array (extra credit).

Your main( ) routine should work as follows:

  1. Display your student information.
  2. Creates an object of the Section class.
  3. Prompt the user to enter in a file name
  4. Read in all of the scores from the file, using the readData( ) function described above. The object should now contain the number of scores read, and the scores should be stored in the array.
  5. Optionally sort the array (extra credit).
  6. Call the function that returns the number of scores stored in the array.
  7. Using this value in a loop, display all of the scores in the array.
  8. Call the function that returns the maximum score, and display it.
  9. Call the function that returns the minimum score, and display it
  10. Call the function that returns the average score, and display it.

What I have so far is:

section.cpp

#include <iostream>
#include <fstream>
#include "section.h"

using namespace std;


int main()
{
    Section object; 
    Section::readData();
   system("PAUSE");
   cin.get();
   return 0;
}

section.h

using namespace std;

class Section
{
private:
    string section;
    string instName;
    int students;
    const int SIZE = 30;
    int array[SIZE];
    
public:
    //Section[array];
    readData();
    num_scores();
    /* high_score();
    low_score();
    avg_score();*/
};

void Section::readData()
{
            std::string filename;
        cout << "Please enter in the path to the student score file: " << endl;
        getline(cin, filename);
        
        ifstream theFile(filename.c_str());
        
            
    if (theFile.good( ) )
   {
       cout << "Test Scores are: " << endl;
       
    int number = 0;
    double average = 0;
    int score = 0;
    int count = 0;
    int max = 0;
    int min = 0;
    while (theFile >> number )
    {    
        if ( count == 0)
        {
            max = number;
            min = number;
        }
        else
        {
        if (number > max)
            max = number;
        if (number < min)
            min = number;
        }
        
        score += number;
        count++;
    cout << "\n" << number;        
    }
    average = score / count;
    cout << "\nLow score " << min << endl;
    cout << "\nHigh score " << max << endl;
    cout << "\nAverage score = " << average << endl;
    
    }
   else
   {
       cout << "\nCould not open the file...";
    
   }
   theFile.close();
   
}

Not sure where to go from here... :(

>>provide the following member functions in your class:
does your class contain all 9 required methods ? If not then you need to code them as described in the program requirements. Just start with #1 and code each one in order. You should also test each method after coding it to insure that it works correctly. Do not wait until after you coded all of them because that will just make debugging efforts more difficult.

I think I can skip 1 for now. I coded 2 but I think I put it with section.h when it may need to go in section.cpp at the bottom as a single function. Also, not sure how to read in the scores and store them in an array. Do I need to create a separate file for these functions like testSection.cpp or they go in section.cpp(main) or section.h?

I think I can skip 1 for now. I coded 2 but I think I put it with section.h when it may need to go in section.cpp at the bottom as a single function. Also, not sure how to read in the scores and store them in an array. Do I need to create a separate file for these functions like testSection.cpp or they go in section.cpp(main) or section.h?

class declaration does in .h file -- no executable code other than inline code goes in the header file. That means you have to remove void Section::readData() from section.h.

section.cpp should only contain the implementation code for the methods that are in section.h file. main() should not be in that file, but for now I suppose it is ok to leave it there. Ultimately you will want main() in some other cpp file, such as main.cpp

>>I think I can skip 1 for now.
NO. do not skip any of the requirements. Do them in the order that they are stated.

This article has been dead for over six months. Start a new discussion instead.