| | |
header file/ classes
![]() |
•
•
Join Date: Apr 2005
Posts: 105
Reputation:
Solved Threads: 3
well... its me again with another project following the basics of the last one...
heres my header file:
and here is my schedule.cpp:
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
heres my header file:
C++ Syntax (Toggle Plain Text)
#ifndef SCHEDULE_H #define SCHEDULE_H #include<string> class schedule { public: // this section will display the heading for the output table void printHead (); //This function is used to calculate the totalgpa for one class int calcGradePoint(aGrade, int, int&); //This bubblesort is used to put the courses into alphabetical order void sortClass(string, int, char, int); //This function is used to calculate overall gpa = totalofgpa / totalhours float calcGPA(float, int); //this function will print the output lines in the table void printLine (); private: int hours[50], cnt = 0; //Variables used char grades[50], gpaForOneClass[50]; string courses[50]; float gpa = 0.0, totalHours = 0, gpaSum = 0; gradevalue in; enum aGrade {a, b, c, d, f, w, i}; }; #endif // SCHEDULE_H
and here is my schedule.cpp:
C++ Syntax (Toggle Plain Text)
#include "schedule.h" #include<iostream> // all the classes I could ever need for this program #include<iomanip> // and a few extra just incase. #include<cmath> #include<cstdlib> #include<string> using namespace std; enum aGrade {a, b, c, d, f, w, i}; int hours[50], cnt = 0; //Variables used char grades[50], gpaForOneClass[50]; string courses[50]; float gpa = 0.0, totalHours = 0, gpaSum = 0; aGrade in; void schedule::printHead () // this section will display the heading for the output table { cout<<"\n\nList of the Courses"<<endl<<"\n Class Hours Grade \n"; cout<<"-----------------------------------"<<endl; } aGrade convert(aGrade in, //OUT: in char grades) //IN: grades { switch (grades) //switch stmt to get all the letters into the enum catagories { case 'a':case 'A': in = a; break; case 'b':case 'B': in = b; break; case 'c':case 'C': in = c; break; case 'd':case 'D': in = d; break; case 'f':case 'F': in = f; break; case 'w':case 'W': in = w; break; case 'i':case 'I': in = i; break; } return in; } int schedule::calcGradePoint(aGrade in, //IN: in int hours, // IN: hours int& cnt) //INOUT: cnt //This function is used to calculate the totalgpa for one class { if(in == a) return 4 * hours; if(in == b) return 3 * hours; if(in == c) return 2 * hours; if(in == d) return 1 * hours; if(in == f) return 0 * hours; if(in == w) return 0 * hours; if(in == i) return 0 * hours; else cout<<"\nInvalid entry"<<endl; cnt = cnt - 1; } void schedule::sortClass(string courses[], //INOUT: courses int hours[], //INOUT: hours char grades[], //INOUT: grades const int cnt) //IN: cnt //This bubblesort is used to put the courses into alphabetical order { int i = cnt, j = 0, k = 1, temper; string temp; char tmp; while (i >= 0 && k) { k = 0; for (j = 0; j <= i; j++) if (courses[j] > courses[j+1]) { temp = courses[j]; courses[j] = courses[j+1]; courses[j+1] = temp; temper = hours[j]; hours[j] = hours[j+1]; hours[j+1] = temper; tmp = grades[j]; grades[j] = grades[j+1]; grades[j+1] = tmp; k = 1; } i--; } } float schedule::calcGPA(const float gpaSum, //IN: gpaSum const int totalHours ) //IN: totalHours //This function is used to calculate overall gpa = totalofgpa / totalhours { float gpa; gpa = float (gpaSum / totalHours); return gpa; } void schedule::printLine (const int cnt, int b, string courses[], int hours[], char grades[], float gpa, int totalHours) { for (int b = 1; b <= cnt; b++) //puts the information into the table { cout<<setw(12)<<courses[b]<<setw(9)<<hours[b]<<setw(10)<<grades[b]<<endl; } cout<<"\nThe total GPA is "<<gpa<<" and you attempted "<<totalHours<<" hours."<<endl; }
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
•
•
Join Date: Apr 2005
Posts: 63
Reputation:
Solved Threads: 1
C++ Syntax (Toggle Plain Text)
void schedule::printLine (const int cnt, int b, string courses[], int hours[], char grades[], float gpa, int totalHours)
C++ Syntax (Toggle Plain Text)
//this function will print the output lines in the table void printLine ();
The definition is different than the prototype...
try this in the class declaration:
C++ Syntax (Toggle Plain Text)
void printLine(const int, int, string [], int [], char p[], float, int);
•
•
Join Date: Apr 2005
Posts: 105
Reputation:
Solved Threads: 3
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.
and .cpp
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>,
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)
#ifndef SCHEDULE_H #define SCHEDULE_H #include<string> class schedule { public: schedule(); enum aGrade {a, b, c, d, f, w, i}; // this section will display the heading for the output table void printHead (); //This function is used to calculate the totalgpa for one class int calcGradePoint(); //This bubblesort is used to put the courses into alphabetical order void sortClass(std::string, int, char, int); //This function is used to calculate overall gpa = totalofgpa / totalhours float calcGPA(float, int); //this function will print the output lines in the table void printLine(); private: int hours[50], cnt; //Variables used char grades[50], gpaForOneClass[50]; std::string courses[50]; float gpa, totalHours, gpaSum; }; #endif // SCHEDULE_H
and .cpp
C++ Syntax (Toggle Plain Text)
#include "schedule.h" #include<iostream> // all the classes I could ever need for this program #include<iomanip> // and a few extra just incase. #include<cmath> #include<cstdlib> #include<string> using namespace std; enum aGrade {a, b, c, d, f, w, i}; schedule::schedule() { int cnt = 0; //Variables used float gpa = 0.0; float totalHours = 0; float gpaSum = 0; } void schedule::printHead () // this section will display the heading for the output table { cout<<"\n\nList of the Courses"<<endl<<"\n Class Hours Grade \n"; cout<<"-----------------------------------"<<endl; } aGrade convert(enum aGrade in, //OUT: in char grades) //IN: grades { switch (grades) //switch stmt to get all the letters into the enum catagories { case 'a':case 'A': in = a; break; case 'b':case 'B': in = b; break; case 'c':case 'C': in = c; break; case 'd':case 'D': in = d; break; case 'f':case 'F': in = f; break; case 'w':case 'W': in = w; break; case 'i':case 'I': in = i; break; } return in; } int schedule::calcGradePoint(enum aGrade in, //IN: in int hours[], // IN: hours int& cnt) //INOUT: cnt //This function is used to calculate the totalgpa for one class { if(in == a) return 4 * hours[cnt]; if(in == b) return 3 * hours[cnt]; if(in == c) return 2 * hours[cnt]; if(in == d) return 1 * hours[cnt]; if(in == f) return 0 * hours[cnt]; if(in == w) return 0 * hours[cnt]; if(in == i) return 0 * hours[cnt]; else cout<<"\nInvalid entry"<<endl; cnt = cnt - 1; } void schedule::sortClass(string courses[], //INOUT: courses int hours[], //INOUT: hours char grades[], //INOUT: grades const int cnt) //IN: cnt //This bubblesort is used to put the courses into alphabetical order { int i = cnt, j = 0, k = 1, temper; string temp; char tmp; while (i >= 0 && k) { k = 0; for (j = 0; j <= i; j++) if (courses[j] > courses[j+1]) { temp = courses[j]; courses[j] = courses[j+1]; courses[j+1] = temp; temper = hours[j]; hours[j] = hours[j+1]; hours[j+1] = temper; tmp = grades[j]; grades[j] = grades[j+1]; grades[j+1] = tmp; k = 1; } i--; } } float schedule::calcGPA(const float gpaSum, //IN: gpaSum const int totalHours ) //IN: totalHours //This function is used to calculate overall gpa = totalofgpa / totalhours { float gpa; gpa = float (gpaSum / totalHours); return gpa; } void schedule::printLine () { for (int b = 1; b <= cnt; b++) //puts the information into the table { cout<<setw(12)<<courses[b]<<setw(9)<<hours[b]<<setw(10)<<grades[b]<<endl; } cout<<"\nThe total GPA is "<<gpa<<" and you attempted "<<totalHours<<" hours."<<endl; }
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>,
•
•
Join Date: Nov 2004
Posts: 108
Reputation:
Solved Threads: 3
[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.
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.
Server: irc.daniweb.com
Channel: #C++
Chat Via:
http://daniweb.com/chat/minichat.php
or
Your favorite IRC client.
•
•
•
•
Originally Posted by jhdobbins
[Linker error] undefined reference to `WinMain@16'
"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
•
•
Join Date: Apr 2005
Posts: 105
Reputation:
Solved Threads: 3
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?
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?
•
•
•
•
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??
•
•
•
•
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?
"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
•
•
Join Date: Apr 2005
Posts: 105
Reputation:
Solved Threads: 3
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
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
![]() |
Similar Threads
- compile header file (C++)
- Link source code and header file together? (C++)
- How to write a header file (C++)
Other Threads in the C++ Forum
- Previous Thread: subtraction operator overload
- Next Thread: reading records from a file
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ char class classes classified code coding compatible compile console conversion count date delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file filewrite forms fstream function functions game givemetehcodez graph gui homeworkhelp homeworkhelper homeworksolutions iamthwee icon if...else ifstream input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node object output play pointer problem program programming project python random read recursion reference rpg string strings struct symbol temperature template test text text-file toolkit tree url values variable vector video win32 windows winsock wordfrequency wxwidgets






