Need some help with Student Grade program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 67
Reputation: matrimforever is an unknown quantity at this point 
Solved Threads: 0
matrimforever matrimforever is offline Offline
Junior Poster in Training

Need some help with Student Grade program

 
0
  #1
Nov 16th, 2006
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
  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
  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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,357
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need some help with Student Grade program

 
0
  #2
Nov 16th, 2006
>>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.
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 67
Reputation: matrimforever is an unknown quantity at this point 
Solved Threads: 0
matrimforever matrimforever is offline Offline
Junior Poster in Training

Re: Need some help with Student Grade program

 
0
  #3
Nov 16th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,357
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Need some help with Student Grade program

 
0
  #4
Nov 16th, 2006
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.
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC