943,944 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3073
  • C++ RSS
Apr 19th, 2005
0

header file/ classes

Expand Post »
well... its me again with another project following the basics of the last one...

heres my header file:
C++ Syntax (Toggle Plain Text)
  1.  
  2. #ifndef SCHEDULE_H
  3. #define SCHEDULE_H
  4.  
  5. #include<string>
  6.  
  7. class schedule
  8. {
  9. public:
  10.  
  11. // this section will display the heading for the output table
  12. void printHead ();
  13.  
  14.  
  15. //This function is used to calculate the totalgpa for one class
  16. int calcGradePoint(aGrade, int, int&);
  17.  
  18.  
  19. //This bubblesort is used to put the courses into alphabetical order
  20. void sortClass(string, int, char, int);
  21.  
  22.  
  23. //This function is used to calculate overall gpa = totalofgpa / totalhours
  24. float calcGPA(float, int);
  25.  
  26.  
  27. //this function will print the output lines in the table
  28. void printLine ();
  29.  
  30.  
  31. private:
  32.  
  33. int hours[50], cnt = 0; //Variables used
  34. char grades[50], gpaForOneClass[50];
  35. string courses[50];
  36. float gpa = 0.0, totalHours = 0, gpaSum = 0;
  37. gradevalue in;
  38. enum aGrade {a, b, c, d, f, w, i};
  39.  
  40.  
  41. };
  42. #endif // SCHEDULE_H




and here is my schedule.cpp:

C++ Syntax (Toggle Plain Text)
  1. #include "schedule.h"
  2. #include<iostream> // all the classes I could ever need for this program
  3. #include<iomanip> // and a few extra just incase.
  4. #include<cmath>
  5. #include<cstdlib>
  6. #include<string>
  7. using namespace std;
  8.  
  9. enum aGrade {a, b, c, d, f, w, i};
  10.  
  11.  
  12. int hours[50], cnt = 0; //Variables used
  13. char grades[50], gpaForOneClass[50];
  14. string courses[50];
  15. float gpa = 0.0, totalHours = 0, gpaSum = 0;
  16. aGrade in;
  17.  
  18.  
  19. void schedule::printHead () // this section will display the heading for the output table
  20. {
  21. cout<<"\n\nList of the Courses"<<endl<<"\n Class Hours Grade \n";
  22. cout<<"-----------------------------------"<<endl;
  23. }
  24.  
  25. aGrade convert(aGrade in, //OUT: in
  26. char grades) //IN: grades
  27.  
  28. {
  29. switch (grades) //switch stmt to get all the letters into the enum catagories
  30. {
  31. case 'a':case 'A':
  32. in = a;
  33. break;
  34. case 'b':case 'B':
  35. in = b;
  36. break;
  37. case 'c':case 'C':
  38. in = c;
  39. break;
  40. case 'd':case 'D':
  41. in = d;
  42. break;
  43. case 'f':case 'F':
  44. in = f;
  45. break;
  46. case 'w':case 'W':
  47. in = w;
  48. break;
  49. case 'i':case 'I':
  50. in = i;
  51. break;
  52.  
  53. }
  54.  
  55. return in;
  56. }
  57.  
  58. int schedule::calcGradePoint(aGrade in, //IN: in
  59. int hours, // IN: hours
  60. int& cnt) //INOUT: cnt
  61. //This function is used to calculate the totalgpa for one class
  62.  
  63. {
  64. if(in == a)
  65. return 4 * hours;
  66. if(in == b)
  67. return 3 * hours;
  68. if(in == c)
  69. return 2 * hours;
  70. if(in == d)
  71. return 1 * hours;
  72. if(in == f)
  73. return 0 * hours;
  74. if(in == w)
  75. return 0 * hours;
  76. if(in == i)
  77. return 0 * hours;
  78. else
  79. cout<<"\nInvalid entry"<<endl;
  80. cnt = cnt - 1;
  81. }
  82.  
  83.  
  84. void schedule::sortClass(string courses[], //INOUT: courses
  85. int hours[], //INOUT: hours
  86. char grades[], //INOUT: grades
  87. const int cnt) //IN: cnt
  88. //This bubblesort is used to put the courses into alphabetical order
  89.  
  90. {
  91. int i = cnt, j = 0, k = 1, temper;
  92. string temp;
  93. char tmp;
  94.  
  95. while (i >= 0 && k)
  96. {
  97.  
  98. k = 0;
  99. for (j = 0; j <= i; j++)
  100. if (courses[j] > courses[j+1])
  101. {
  102. temp = courses[j];
  103. courses[j] = courses[j+1];
  104. courses[j+1] = temp;
  105.  
  106. temper = hours[j];
  107. hours[j] = hours[j+1];
  108. hours[j+1] = temper;
  109.  
  110. tmp = grades[j];
  111. grades[j] = grades[j+1];
  112. grades[j+1] = tmp;
  113.  
  114. k = 1;
  115. }
  116. i--;
  117. }
  118. }
  119.  
  120.  
  121.  
  122. float schedule::calcGPA(const float gpaSum, //IN: gpaSum
  123. const int totalHours ) //IN: totalHours
  124. //This function is used to calculate overall gpa = totalofgpa / totalhours
  125.  
  126. {
  127. float gpa;
  128. gpa = float (gpaSum / totalHours);
  129. return gpa;
  130. }
  131.  
  132.  
  133. void schedule::printLine (const int cnt, int b, string courses[], int hours[], char grades[], float gpa, int totalHours)
  134. {
  135. for (int b = 1; b <= cnt; b++) //puts the information into the table
  136. {
  137. cout<<setw(12)<<courses[b]<<setw(9)<<hours[b]<<setw(10)<<grades[b]<<endl;
  138. }
  139.  
  140. cout<<"\nThe total GPA is "<<gpa<<" and you attempted "<<totalHours<<" hours."<<endl;
  141. }




here are my compiling errors.

64 schedule.cpp prototype for ` int schedule::calcGradePoint(aGrade, int, int&)' does not match any in class

15 schedule.h int schedule::calcGradePoint()

91 schedule.cpp prototype for ` void schedule::sortClass(std::string*, int*, char*, int)' does not match any

19 schedule.h void schedule::sortClass()

127 schedule.cpp prototype for ` float schedule::calcGPA(float, int)' does not match any in class `schedule'

23 schedule.h float schedule::calcGPA()

135 schedule.cpp prototype for ` void schedule::printLine(int, int, std::string*, int*, char*, float, int)'

27 schedule.h void schedule::printLine()




heres my grading points for this lab:

Grading Points:
1) Use the following type definitions:
enum aGrade {A, B, C, D, F, W, I};
struct aClass
{
string course;
aGrade grade;
int hours;
int GP;
};
2) All variables must be local.
3) All functions and type definitions must be in a header file (*.h).
4) All function bodies must be in a separate body file (*.cpp) from the main.
5) An array of 10 structures of type aClass will make up the storage mechanism; i.e., you will process 10 students.
6) Comment all functions thoroughly: InOut, Out, requires, ensures.
7) Input must be inline (i.e. all values entered on the same line)
$>class grade hours
8 ) Allow both upper and lower case entries for grades.
9) Accept “quit�, “Quit�, and “QUIT� as acceptable terminators for loop
10) Use the following functions:
printHead //Prints the top of the display chart
printLine //Prints 1 line of the table
calcGradePoints //Calculates grade points for structure
calcGPA //Calculates total GPA
sortClass //Uses a bubble sort to put classes in order


I and reading in my text book and trying to figure this out... i dont care about the struct yet. And i didn't include my main function. I just want to see where i am going wrong with this header file/class
Similar Threads
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

C++ Syntax (Toggle Plain Text)
  1. void schedule::printLine (const int cnt, int b, string courses[], int hours[], char grades[], float gpa, int totalHours)
C++ Syntax (Toggle Plain Text)
  1.  
  2. //this function will print the output lines in the table
  3. void printLine ();

The definition is different than the prototype...
try this in the class declaration:
C++ Syntax (Toggle Plain Text)
  1. void printLine(const int, int, string [], int [], char p[], float, int);
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
marinme is offline Offline
63 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

Thanks, that wiped out 2 of the errors.
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

I posted this again because i got alot more errors for some reason... then
turned around and got rid of most of the errors? only down to four now... not sure what happened in those few minutes.

C++ Syntax (Toggle Plain Text)
  1. #ifndef SCHEDULE_H
  2. #define SCHEDULE_H
  3.  
  4. #include<string>
  5.  
  6. class schedule
  7. {
  8. public:
  9.  
  10. schedule();
  11.  
  12. enum aGrade {a, b, c, d, f, w, i};
  13.  
  14. // this section will display the heading for the output table
  15. void printHead ();
  16.  
  17.  
  18. //This function is used to calculate the totalgpa for one class
  19. int calcGradePoint();
  20.  
  21.  
  22. //This bubblesort is used to put the courses into alphabetical order
  23. void sortClass(std::string, int, char, int);
  24.  
  25.  
  26. //This function is used to calculate overall gpa = totalofgpa / totalhours
  27. float calcGPA(float, int);
  28.  
  29.  
  30. //this function will print the output lines in the table
  31. void printLine();
  32.  
  33.  
  34. private:
  35.  
  36. int hours[50], cnt; //Variables used
  37. char grades[50], gpaForOneClass[50];
  38. std::string courses[50];
  39. float gpa, totalHours, gpaSum;
  40.  
  41.  
  42.  
  43. };
  44. #endif // SCHEDULE_H


and .cpp

C++ Syntax (Toggle Plain Text)
  1. #include "schedule.h"
  2. #include<iostream> // all the classes I could ever need for this program
  3. #include<iomanip> // and a few extra just incase.
  4. #include<cmath>
  5. #include<cstdlib>
  6. #include<string>
  7. using namespace std;
  8.  
  9. enum aGrade {a, b, c, d, f, w, i};
  10.  
  11. schedule::schedule()
  12. {
  13. int cnt = 0; //Variables used
  14. float gpa = 0.0;
  15. float totalHours = 0;
  16. float gpaSum = 0;
  17.  
  18. }
  19.  
  20. void schedule::printHead () // this section will display the heading for the output table
  21. {
  22. cout<<"\n\nList of the Courses"<<endl<<"\n Class Hours Grade \n";
  23. cout<<"-----------------------------------"<<endl;
  24. }
  25.  
  26. aGrade convert(enum aGrade in, //OUT: in
  27. char grades) //IN: grades
  28.  
  29. {
  30. switch (grades) //switch stmt to get all the letters into the enum catagories
  31. {
  32. case 'a':case 'A':
  33. in = a;
  34. break;
  35. case 'b':case 'B':
  36. in = b;
  37. break;
  38. case 'c':case 'C':
  39. in = c;
  40. break;
  41. case 'd':case 'D':
  42. in = d;
  43. break;
  44. case 'f':case 'F':
  45. in = f;
  46. break;
  47. case 'w':case 'W':
  48. in = w;
  49. break;
  50. case 'i':case 'I':
  51. in = i;
  52. break;
  53.  
  54. }
  55.  
  56. return in;
  57. }
  58.  
  59. int schedule::calcGradePoint(enum aGrade in, //IN: in
  60. int hours[], // IN: hours
  61. int& cnt) //INOUT: cnt
  62. //This function is used to calculate the totalgpa for one class
  63.  
  64. {
  65. if(in == a)
  66. return 4 * hours[cnt];
  67. if(in == b)
  68. return 3 * hours[cnt];
  69. if(in == c)
  70. return 2 * hours[cnt];
  71. if(in == d)
  72. return 1 * hours[cnt];
  73. if(in == f)
  74. return 0 * hours[cnt];
  75. if(in == w)
  76. return 0 * hours[cnt];
  77. if(in == i)
  78. return 0 * hours[cnt];
  79. else
  80. cout<<"\nInvalid entry"<<endl;
  81. cnt = cnt - 1;
  82. }
  83.  
  84.  
  85. void schedule::sortClass(string courses[], //INOUT: courses
  86. int hours[], //INOUT: hours
  87. char grades[], //INOUT: grades
  88. const int cnt) //IN: cnt
  89. //This bubblesort is used to put the courses into alphabetical order
  90.  
  91. {
  92. int i = cnt, j = 0, k = 1, temper;
  93. string temp;
  94. char tmp;
  95.  
  96. while (i >= 0 && k)
  97. {
  98.  
  99. k = 0;
  100. for (j = 0; j <= i; j++)
  101. if (courses[j] > courses[j+1])
  102. {
  103. temp = courses[j];
  104. courses[j] = courses[j+1];
  105. courses[j+1] = temp;
  106.  
  107. temper = hours[j];
  108. hours[j] = hours[j+1];
  109. hours[j+1] = temper;
  110.  
  111. tmp = grades[j];
  112. grades[j] = grades[j+1];
  113. grades[j+1] = tmp;
  114.  
  115. k = 1;
  116. }
  117. i--;
  118. }
  119. }
  120.  
  121.  
  122.  
  123. float schedule::calcGPA(const float gpaSum, //IN: gpaSum
  124. const int totalHours ) //IN: totalHours
  125. //This function is used to calculate overall gpa = totalofgpa / totalhours
  126.  
  127. {
  128. float gpa;
  129. gpa = float (gpaSum / totalHours);
  130. return gpa;
  131. }
  132.  
  133.  
  134. void schedule::printLine ()
  135. {
  136. for (int b = 1; b <= cnt; b++) //puts the information into the table
  137. {
  138. cout<<setw(12)<<courses[b]<<setw(9)<<hours[b]<<setw(10)<<grades[b]<<endl;
  139. }
  140.  
  141. cout<<"\nThe total GPA is "<<gpa<<" and you attempted "<<totalHours<<" hours."<<endl;
  142. }

errors::

65 schedule.cpp prototype for ` int schedule::calcGradePoint(schedule::aGrade, int*, int&)' does not match

20 schedule.h int schedule::calcGradePoint()

92 schedule.cpp prototype for ` void schedule::sortClass(std::string*, int*, char*, int)' does not match any

24 schedule.h void schedule::sortClass(std::basic_string<char, std::char_traits<char>,
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

[edit]Saw the second post not as bad[/edit]
Some tips:
1. Don't use the same variable names for the names of parameters.
2. Make sure that you actully have a function prototyped in your header.
3. Make sure that the function you prototyped in your header matches that one that you have defined in your class.
4. You can't assign a value for a data member in your class in the header you do that in the constructor or use a "setter" function.
4. Maybe work on your spacing it's wierd not the worst I have seen but I don't like it.
Reputation Points: 14
Solved Threads: 4
Junior Poster
prog-bman is offline Offline
108 posts
since Nov 2004
Apr 20th, 2005
0

Re: header file/ classes

Only getting one error message now...

[Linker error] undefined reference to `WinMain@16'

?? im lost.
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

Quote originally posted by jhdobbins ...
[Linker error] undefined reference to `WinMain@16'
Sounds like prime keywords for a search, which might turn up some relevant hits.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Apr 20th, 2005
0

Re: header file/ classes

just a quick question... if you run a win32 console...

you have to have a main in your project to work without the errors right??

say you have a header and another .cpp that contains the functions defined in the header, you have to include the other .cpp file with the main to get rid of such errors as...

[Linker error] undefined reference to `WinMain@16'

right?
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 2005
Apr 20th, 2005
0

Re: header file/ classes

Quote originally posted by jhdobbins ...
if you run a win32 console...

you have to have a main in your project to work without the errors right??
Yes.

Quote originally posted by jhdobbins ...
say you have a header and another .cpp that contains the functions defined in the header, you have to include the other .cpp file with the main to get rid of such errors as...

[Linker error] undefined reference to `WinMain@16'

right?
First, I hope you are not meaning include in the #include sense. But I believe yes -- there must be exactly one main, and it doesn't really matter in which source file it is located.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Apr 20th, 2005
0

Re: header file/ classes

no i didnt mean it in the #include sense.

I meant.. your project file must CONTAIN not include...

sorry for the misrepresentation.

but now i am curious what this error means?

C:\Documents and Settings\Josh\Desktop\Makefile.win [Build Error] [cs110lab5.o] Error 1

i have a schedule.h
a schedule.cpp
and then the file that contains my main is cs110lab5.cpp
Reputation Points: 10
Solved Threads: 3
Junior Poster
jhdobbins is offline Offline
105 posts
since Apr 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: subtraction operator overload
Next Thread in C++ Forum Timeline: reading records from a file





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


Follow us on Twitter


© 2011 DaniWeb® LLC