I am a beginner in the C++ language and have run into a compiling error that has stumped me for days for my latest assignment. The code is using a class GradeBook to set both the name of the course and the instructor's name.
Here is the driver file where I include the header file that contains the class GradeBook
#include <iostream>
#include "GradeBook.h"
using namespace std;
int main()
{
gradeBook gradeBook1 ();
gradeBook gradeBook2 ();
cout << "Grade Book Initial Course Name: \n" << gradeBook1.getCourseName() << endl;
cout << "Initial Instructor Name: \n" << gradeBook2.getInstuctorName() << endl;
gradeBook.displayMessage();
return 0;
}
Here is the header file. I added in the #ifndef to prevent possible looping errors based on research into this problem.
#ifndef GRADE_H
#define GRADE_H
#include <string>
#include "GradeBook.cpp"
// __Grade_Book__
class GradeBook
{
std::string courseName, instructorName;
public:
// constructor initializes courseName with string supplied an argument
GradeBook( std::string name);
//function sets the course name and limits length
void setCourseName(std::string name);
void setInstructorName(std::string iName);
//function gets the course name
std::string getCourseName();
std::string getInstructorName();
//function displays a welcome message
void displayMessage();
};
#endif
This is the source file where the error " 'GradeBook' does not name a type' occurs at the first instance of GradeBook despite being linked to the header file. I feel as though this file is not completely necessary for this code but it is required for the assignment. I'm wondering if I have messed up with the communication of the files creating a loop but everything I have tried has led to the same compiling error, insisting that the class GraddeBook has not been defined.
#include <iostream>
#include "GradeBook.h"
using namespace std;
// constructor initializes courseName with string supplied an argument
GradeBook::GradeBook(string name)
{
setCourseName(name);
setInstructorName (iName);
// call set function to initialize courseName
}
//function sets the course name
void GradeBook::setCourseName(string name)
{
if (name.length() <= 30)
courseName = name;
else
{
courseName = name.substr(0, 30); //start at 0, length of 30
cout << "Course Name \" " << name << "\" exceeds maximum length (30).\n"
<< "Limiting courseName to the first 30-characters.\n" << endl;
}
}
void GradeBook::setInstuctorName(string iName)
{
if (iName.length() <= 20)
instructorName = iName;
else
{
instructorName = iName.substr(0, 30); //start at 0, length of 30
cout << "Instructor Name \" " << iName << "\" exceeds maximum length (20).\n"
<< "Limiting Instructor Name to the first 20-characters.\n" << endl;
}
}
//function gets the course name
string GradeBook::getCourseName()
{
return courseName;
}
string GradeBook::getInstructorName()
{
return InstructorName;
}
//function displays a welcome message
void GradeBook::displayMessage()
{
cout << "Welcome to the Grade book for: \n" << getCourseName() << endl;
cout << "This course is presented by: \n" << getInstructorName() << endl;
}
Be sure to use the correct classname when declaring a variable. Identifiers are case sensitive.
GradeBook gradeBook1;
GradeBook gradeBook2;