Hello Im tring to compile an example from my C++ book but its faulting with this error
Code:
mike@laptop:~/code/C++/chapter_3$ g++ grade_3.cpp -o grade3
grade_3.cpp:18: error: expected primary-expression before ‘void’
grade_3.cpp:18: error: ISO C++ forbids declaration of ‘pubilc’ with no type
grade_3.cpp:18: error: expected ‘;’ before ‘void’
grade_3.cpp:23: error: expected `;' before ‘string’
grade_3.cpp: In function ‘int main()’:
grade_3.cpp:23: error: ‘std::string GradeBook::getCourseName()’ is private
grade_3.cpp:42: error: within this context
grade_3.cpp:46: error: ‘class GradeBook’ has no member named ‘setCourseName’
grade_3.cpp:28: error: ‘void GradeBook::displayMessage()’ is private
grade_3.cpp:48: error: within this context
and here is the source
Code:
// GradeBook example
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
class GradeBook
{
pubilc:
void setCourseName( string name )
{
courseName = name;
}
string getCourseName()
{
return courseName;
}
void displayMessage()
{
cout << "Welcome to the grade book for\n" << getCourseName() << "!" << endl;
}
private:
string courseName;
};
int main()
{
string nameOfCourse;
GradeBook myGradeBook;
cout << "Inital course name is: " << myGradeBook.getCourseName() << endl;
cout << "\nPlease enter the course name:" << endl;
getline( cin, nameOfCourse );
cout << endl;
myGradeBook.setCourseName( nameOfCourse );
cout << endl;
myGradeBook.displayMessage();
}