#pragma once
#include <iostream>
// GradeBook class definition
#include <string> // class GradeBook uses C++ standard string class
// GradeBook class definition
class GradeBook
{
public:
explicit GradeBook( std::string, std::string,int); // constructor initialize courseName
void setCourseName( std::string ); // sets the course name
std::string getCourseName() const; // gets the course name
void setInstructorName( std::string ); // sets the instructor name
std::string getInstructorName() const; // gets the instructor name
void displayMessage() const; // displays a welcome message
void setNumberCredits(int x) const;//sets the number of credit
int getNumberCredits() const;//gets the number of credits
private:
std::string courseName; // course name for this GradeBook
std::string instructorName; // instructor name
int numberCredits; //number of credits
}; // end class GradeBook
#include <iostream>
#include "GradeBook.h" // include definition of class GradeBook
usingnamespace std;
// constructor initializes courseName with string supplied as argument
GradeBook::GradeBook( string cName, string iName,int credits )
{
setCourseName(cName);
setInstructorName(iName);
setNumberCredits(credits);
// empty body
} // end GradeBook constructor
// function to set the course name
void GradeBook::setCourseName( string name )
{
if ( name.size() <= 25 ) // if name has 25 or fewer characters
courseName = name; // store the course name in the object
if ( name.size() > 25 ) // if name has more than 25 characters
{
// set courseName to first 25 characters of parameter name
courseName = name.substr( 0, 25 ); // start at 0, length of 25
cerr << "Name \"" << name << "\" exceeds maximum length (25).\n"
<< "Limiting courseName to first 25 characters.\n" << endl;
} // end if
} // end function setCourseName
// function to get the course name
string GradeBook::getCourseName() const
{
return courseName; // return object's courseName
} // end function getCourseName
void GradeBook::setInstructorName( std::string name) // sets the instructor name
{
instructorName = name;
}
std::string GradeBook::getInstructorName() const // gets the instructor name
{
return instructorName;
}
void GradeBook::setNumberCredits(int x) const // sets the number of credits
{
numberCredits = x;
}
int GradeBook::getNumberCredits() const
{
return numberCredits;
}
// 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;
cout << "Instructor is " << getInstructorName() << endl;
cout << "The Number of credit is " << getNumberCredits() << endl;
} // end function displayMessage