header file/ classes

Reply

Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

header file/ classes

 
0
  #1
Apr 19th, 2005
well... its me again with another project following the basics of the last one...

heres my header file:
  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:

  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
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 63
Reputation: marinme is an unknown quantity at this point 
Solved Threads: 1
marinme marinme is offline Offline
Junior Poster in Training

Re: header file/ classes

 
0
  #2
Apr 20th, 2005
  1. void schedule::printLine (const int cnt, int b, string courses[], int hours[], char grades[], float gpa, int totalHours)
  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:
  1. void printLine(const int, int, string [], int [], char p[], float, int);
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #3
Apr 20th, 2005
Thanks, that wiped out 2 of the errors.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #4
Apr 20th, 2005
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.

  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

  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>,
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 108
Reputation: prog-bman is an unknown quantity at this point 
Solved Threads: 3
prog-bman prog-bman is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #5
Apr 20th, 2005
[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.
Join me on IRC:
Server: irc.daniweb.com
Channel: #C++

Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #6
Apr 20th, 2005
Only getting one error message now...

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

?? im lost.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,306
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 227
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: header file/ classes

 
0
  #7
Apr 20th, 2005
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #8
Apr 20th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,306
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 227
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: header file/ classes

 
0
  #9
Apr 20th, 2005
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.

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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 105
Reputation: jhdobbins is an unknown quantity at this point 
Solved Threads: 3
jhdobbins jhdobbins is offline Offline
Junior Poster

Re: header file/ classes

 
0
  #10
Apr 20th, 2005
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
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