943,971 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4284
  • C++ RSS
Nov 16th, 2006
0

Need some help with Student Grade program

Expand Post »
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
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include "section.h"
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int main()
  9. {
  10. Section object;
  11. Section::readData();
  12. system("PAUSE");
  13. cin.get();
  14. return 0;
  15. }
section.h
C++ Syntax (Toggle Plain Text)
  1.  
  2. using namespace std;
  3.  
  4. class Section
  5. {
  6. private:
  7. string section;
  8. string instName;
  9. int students;
  10. const int SIZE = 30;
  11. int array[SIZE];
  12.  
  13. public:
  14. //Section[array];
  15. readData();
  16. num_scores();
  17. /* high_score();
  18.   low_score();
  19.   avg_score();*/
  20. };
  21.  
  22. void Section::readData()
  23. {
  24. std::string filename;
  25. cout << "Please enter in the path to the student score file: " << endl;
  26. getline(cin, filename);
  27.  
  28. ifstream theFile(filename.c_str());
  29.  
  30.  
  31. if (theFile.good( ) )
  32. {
  33. cout << "Test Scores are: " << endl;
  34.  
  35. int number = 0;
  36. double average = 0;
  37. int score = 0;
  38. int count = 0;
  39. int max = 0;
  40. int min = 0;
  41. while (theFile >> number )
  42. {
  43. if ( count == 0)
  44. {
  45. max = number;
  46. min = number;
  47. }
  48. else
  49. {
  50. if (number > max)
  51. max = number;
  52. if (number < min)
  53. min = number;
  54. }
  55.  
  56. score += number;
  57. count++;
  58. cout << "\n" << number;
  59. }
  60. average = score / count;
  61. cout << "\nLow score " << min << endl;
  62. cout << "\nHigh score " << max << endl;
  63. cout << "\nAverage score = " << average << endl;
  64.  
  65. }
  66. else
  67. {
  68. cout << "\nCould not open the file...";
  69.  
  70. }
  71. theFile.close();
  72.  
  73. }
Not sure where to go from here...
Last edited by matrimforever; Nov 16th, 2006 at 1:36 am.
Similar Threads
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
matrimforever is offline Offline
67 posts
since Sep 2006
Nov 16th, 2006
0

Re: Need some help with Student Grade program

>>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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Nov 16th, 2006
0

Re: Need some help with Student Grade program

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.
Reputation Points: 26
Solved Threads: 0
Junior Poster in Training
matrimforever is offline Offline
67 posts
since Sep 2006
Nov 16th, 2006
0

Re: Need some help with Student Grade program

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.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: How to deallocate memory
Next Thread in C++ Forum Timeline: explanation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC