| | |
Need some help with Student Grade program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 67
Reputation:
Solved Threads: 0
I need help figuring this out. What I need is this:
section.cpp
section.h
Not sure where to go from here...
- The section number, as a string
- The instructor's name, also as a string
- The number of students in this section, as an integer.
- 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!
- 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.
- 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.
- a function that returns the number of scores stored in the array,
- a function that takes in integer value as a parameter, and returns the score at that position in the array of scores.
- a function that returns the highest score on the test,
- a function that returns the lowest score on the test,
- a function that calculates the average score on the test, and
- optionally a function that sorts the array (extra credit).
- Display your student information.
- Creates an object of the Section class.
- Prompt the user to enter in a file name
- 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.
- Optionally sort the array (extra credit).
- Call the function that returns the number of scores stored in the array.
- Using this value in a loop, display all of the scores in the array.
- Call the function that returns the maximum score, and display it.
- Call the function that returns the minimum score, and display it
- Call the function that returns the average score, and display it.
section.cpp
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> #include "section.h" using namespace std; int main() { Section object; Section::readData(); system("PAUSE"); cin.get(); return 0; }
C++ Syntax (Toggle Plain Text)
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(); }
Last edited by matrimforever; Nov 16th, 2006 at 1:36 am.
>>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.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Sep 2006
Posts: 67
Reputation:
Solved Threads: 0
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?
Last edited by matrimforever; Nov 16th, 2006 at 1:53 am.
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.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- calculate the grades for a student using if..else statements. (Java)
- Grade Program (C++)
- Schedule program (Python)
- student grades program doesnt work how it should (C++)
- grade prediction program (C)
- c++ Grade program (C++)
Other Threads in the C++ Forum
- Previous Thread: How to deallocate memory
- Next Thread: explanation
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets






