Exercices of C++ Book.

Hello there!.

Could not compile with error:

root@supernova-MacBookPro:/home/supernova/Desktop/Impetus/Prog/Nov# g++ GradeBook.cpp -o GradeBookcpp
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

GradeBook.H
GradeBook.cpp

GradeBook.H
1
2
3
4
5
6
7
8
9
10
11
12
      #include <string> // class GradeBook uses C++ standard string class
// GradeBook class definition
class GradeBook
{
public:
explicit GradeBook( std::string ); // constructor initialize courseName
void setCourseName( std::string ); // sets the course name
std::string getCourseName() const; // gets the course name
void displayMessage() const; // displays a welcome message
private:
std::string courseName; // course name for this GradeBook
}; // end class GradeBook  


GradeBook.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
using namespace std;
// constructor initializes courseName with string supplied as argument
GradeBook::GradeBook( string name )
: courseName( name ) // member initializer to initialize courseName
{
// empty body
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName( string name )
{
courseName = name; // store the course name in the object
} // end function setCourseName
// function to get the course name
string GradeBook::getCourseName() const
{
return courseName; // return object's courseName
} // end function getCourseName
// display a welcome message to the GradeBook user
void GradeBook::displayMessage() const
{
// call getCourseName to get the courseName
cout << "Welcome to the grade book for\n" << getCourseName()
<< "!" << endl;
} // end function displayMessage 

https://www.prepaidgiftbalance.vip/www-prepaidgiftbalance-com/
Last edited on
To compile a c/c++ program, you need a main() function.

1
2
3
int main() {
    // Code goes here that is used when the program starts
}

Topic archived. No new replies allowed.