DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Please help with Pointers, Classes, Virtual Functions, and Abstract Classes (http://www.daniweb.com/forums/thread120633.html)

cmoney12051 Apr 23rd, 2008 3:03 pm
Please help with Pointers, Classes, Virtual Functions, and Abstract Classes
 
2 Attachment(s)
i have to make the C++ program that will have the user input some test grades and exam grades and their personal info then output their stuff in the end. i have almost the whole thing done, but i would compile it throws up a list of 30 erros and i am having troble with it. i think it looks good but im still not all that good with this stuff please help. here is the code

  1. #include <iostream>

  2. #include <string>

  3. using namespace std;

  4. class Grade

  5. {

  6. private:

  7.         string firstName;

  8.         string lastName;

  9.         int idNum;

  10.         int numHomeworks;

  11.         int numExams;

  12.         int listSize;

  13.         int score;

  14.         int grades;

  15.        

  16. public:

  17.         void getStudentInfo();

  18.         void getExamGrades(grades, Grade::numExams);

  19.         void getHWGrades(grades, Grade::numExams, listSize);

  20.         void calcTotalPoints(grades, listSize);

  21.         void calcLetterGrade();

  22.         void displayInfo();

  23.         void setID(int id);

  24.         void setScore(int grades);

  25.         void setExams(int exams);

  26.         void setName(string fn, string ln);

  27.        

  28.         Grade(string, string, int, int, int, int);

  29. };

  30. Grade::Grade(string fn, string ln, int id, int grades; int exams, int listSize)

  31. {

  32.         firstName = fn;

  33.         lastName = ln;

  34.         idNum = id;

  35.         grades = grades;

  36.         numExams = exams;

  37.         listSize = listSize;

  38. }

  39. void Grade::setID(int id)

  40. {

  41.         idNum = id;

  42. }

  43. void Grade::setScore(int grades)

  44. {

  45.         grades = grades;

  46. }

  47. void Grade::setExams(int exams)

  48. {

  49.         numExams = exams;

  50. }

  51. void Grade::setName(string fn, string ln)

  52. {

  53.         firstName = fn;

  54.         lastName = ln;

  55. }

  56. void Grade::getStudentInfo()

  57. {

  58.         cout << "First Name: " << endl;

  59.         cin >> firstName;

  60.         cout <<"Last Name: " <<endl;

  61.         cin >> lastName;

  62.         cout <<"ID: "<<endl;

  63.         cin >>idNum;

  64. }

  65. void Grade::getExamGrades(grades, Grade::numExams)

  66. {

  67.         cout <<"Score for Exam #1: "<<endl;

  68.         cin >> numExams;

  69.         cout <<"Score for Exam #2: "<<endl;

  70.         cin >> numExams;

  71. }

  72. void Grades::getHWGrades(grades, Grade::numExams, listSize)

  73. {

  74.         cout <<"Score for Homework #1: "<<endl;

  75.         cin >> grades;

  76.         cout <<"Score for Homework #2: "<<endl;

  77.         cin >> grades;

  78.         cout <<"Score for Homework #3: "<<endl;

  79.         cin >> grades;

  80.         cout <<"Score for Homework #4: "<<endl;

  81.         cin >> grades;

  82.         cout <<"Score for Homework #5: "<<endl;

  83.         cin >> grades;

  84.         cout <<"Score for Homework #6: "<<endl;

  85.         cin >> grades;

  86.         cout <<"Score for Homework #7: "<<endl;

  87.         cin >> grades;

  88.         cout <<"Score for Homework #8: "<<endl;

  89.         cin >> grades;

  90.         cout <<"Score for Homework #9: "<<endl;

  91.         cin >> grades;

  92.         cout <<"Score for Homework #10: "<<endl;

  93.         cin >> grades;

  94. }

  95. void Grade::calcTotalPoints(grades, listSize)

  96. {

  97.         grade*10+numExams*2=score

  98. }

  99. void Grade::calcLetterGrade();

  100. {

  101.         if (score < 59)

  102.         {

  103.                 cout << " Letter grade is F" << endl;

  104.         }

  105.         if (score == 60)

  106.         {

  107.                 cout << " Letter grade is D" << endl;

  108.         }

  109.         if (score == 69)

  110.         {

  111.                 cout << " Letter grade is D" << endl;

  112.         }

  113.         if (score == 68)

  114.         {

  115.                 cout << " Letter grade is D" << endl;

  116.         }

  117.         if (score == 67)

  118.         {

  119.                 cout << " Letter grade is D" << endl;

  120.         }

  121.         if (score == 66)

  122.         {

  123.                 cout << " Letter grade is D" << endl;

  124.         }

  125.         if (score == 65)

  126.         {

  127.                 cout << " Letter grade is D" << endl;

  128.         }

  129.         if (score == 64)

  130.         {

  131.                 cout << " Letter grade is D" << endl;

  132.         }

  133.         if (score == 63)

  134.         {

  135.                 cout << " Letter grade is D" << endl;

  136.         }

  137.         if (score == 62)

  138.         {

  139.                 cout << " Letter grade is D" << endl;

  140.         }

  141.         if (score == 61)

  142.         {

  143.                 cout << " Letter grade is D" << endl;

  144.         }

  145.         if (score == 70)

  146.         {

  147.                 cout << " Letter grade is C" << endl;

  148.         }

  149.         if (score == 71)

  150.         {

  151.                 cout << " Letter grade is C" << endl;

  152.         }

  153.         if (score == 72)

  154.         {

  155.                 cout << " Letter grade is C" << endl;

  156.         }

  157.         if (score == 73)

  158.         {

  159.                 cout << " Letter grade is C" << endl;

  160.         }

  161.         if (score == 74)

  162.         {

  163.                 cout << " Letter grade is C" << endl;

  164.         }

  165.         if (score == 75)

  166.         {

  167.                 cout << " Letter grade is C" << endl;

  168.         }

  169.         if (score == 76)

  170.         {

  171.                 cout << " Letter grade is C" << endl;

  172.         }

  173.         if (score == 77)

  174.         {

  175.                 cout << " Letter grade is C" << endl;

  176.         }

  177.         if (score == 78)

  178.         {

  179.                 cout << " Letter grade is C "<< endl;

  180.         }

  181.         if (score == 79)

  182.         {

  183.                 cout << " Letter grade is C" << endl;

  184.         }

  185.         if (score == 80)

  186.         {

  187.                 cout << " Letter grade is B" << endl;

  188.         }

  189.         if (score == 81)

  190.         {

  191.                 cout << " Letter grade is B" << endl;

  192.         }

  193.         if (score == 82)

  194.         {

  195.                 cout << " Letter grade is B" << endl;

  196.         }

  197.         if (score == 83)

  198.         {

  199.                 cout << " Letter grade is B" << endl;

  200.         }

  201.         if (score == 84)

  202.         {

  203.                 cout << " Letter grade is B" << endl;

  204.         }

  205.         if (score == 85)

  206.         {

  207.                 cout << " Letter grade is B" << endl;

  208.         }

  209.         if (score == 86)

  210.         {

  211.                 cout << " Letter grade is B" << endl;

  212.         }

  213.         if (score == 87)

  214.         {

  215.                 cout << " Letter grade is B" << endl;

  216.         }

  217.         if (score == 88)

  218.         {

  219.                 cout << " Letter grade is B" << endl;

  220.         }

  221.         if (score == 89)

  222.         {

  223.                 cout << " Letter grade is B" << endl;

  224.         }

  225.         if (score > 90)

  226.         {

  227.                 cout << " Letter grade is A" << endl;

  228.         }

  229. }

  230. void Grade::displayInfo()

  231. {

  232.         cout<<"-----Grade Report-----"<<endl;

  233.         cout<<"Student #: "<<idNum<<endl;

  234.         cout<<"Name: "<<firstName<<" "<<lastName<<endl;

  235.         cout<<"Total Points: "<<score<<endl;

  236.         cout<<"Grade: "<<myGrade.calcLetterGrade<<endl;

  237. }

  238. void main()

  239. {

  240. Grade myGrade; // declare a Grade object

  241. const int listSize = Grade::numExams + Grade::numHomeworks; // determine array size

  242. int grades[listSize]; // create array

  243. myGrade.getStudentInfo();

  244.     // Prompt for and obtain first name, last name, and id

  245.     // Ensures that the value entered for id is exactly 4 digits

  246. myGrade.getExamGrades(grades, Grade::numExams);

  247.     // Prompts for and reads in the exam scores

  248.     // Ensures that exam scores are not less than zero

  249. myGrade.getHWGrades(grades, Grade::numExams, listSize);

  250.     // Prompts for and reads in the homework scores

  251.     // Ensures that homeworks scores are greater than zero and less than 26

  252. myGrade.calcTotalPoints(grades, listSize);

  253.     // Calculates total points (data member)

  254.     // Prompts for and obtains office visit value (and includes it in total points)

  255. myGrade.calcLetterGrade();

  256.     // Determines letter grade (data member)

  257. myGrade.displayInfo();

  258.     // Outputs all data member values (with formatting text)

  259. }


If you see any errors ar anyway that i could get this to compile please let me know. i would really apreciate it. thanks

P.S. i also attached both the .cpp file and the compiler output tex file aswell.

rdrast Apr 23rd, 2008 3:43 pm
Re: Please help with Pointers, Classes, Virtual Functions, and Abstract Classes
 
Wow... Before worrying about getting it to compile, you might want to think about writing a design document to get your logic straight.

But...
Your error log tells you what is wrong. In your class declaration, you aren't referring to valid types, you are referring to your own names for things. Problem.

main isn't a void function.

You declare Grade::numExams and Grade::grades as private, and non-static, then immediately try to use them in a public fashion in main. At this point they are A) unaccessible, and B) uninitialized.

In your class, er, how many of your actual homework assignment grades get recorded somewhere? Well, all of them, but only #10 matters, since you keep overwriting the same variable. Ditto the exam grades, except there you only overwrite once.

CalcLetterGrade... er, isn't there perhaps a better method of doing this? Maybe with relational operators? And you miss the case where grade is 90.

Again, the errors list is pretty good, why not work through that from the first down, recompiling every time you fix something.

Incremental Compiles are always better than just writing a bunch of code and preying for the best.

cmoney12051 Apr 24th, 2008 1:04 am
Re: Please help with Pointers, Classes, Virtual Functions, and Abstract Classes
 
Thanks for the help. I wouldn't have able to get it figured out without you.


All times are GMT -4. The time now is 4:16 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC