Here's the code:
GradeBook.h
PHP Code:
#include <iostream>;
#include <string>;
class GradeBook {
public:
GradeBook(string); // constructor
void setCourseName(string);
string getCourseName();
void displayMessage();
void inputGrades();
void displayGradeReport();
int maximum(int, int, int);
private:
string courseName;
int maximumGrade;
}
Recursion.cpp (don't worry about the title, no connection with recursion)
PHP Code:
#include "stdafx.h"
#include <iostream>;
using std::endl;
using std::cout;
using std::cin;
#include <string>;
using std::string;
using std::getline;
#include "GradeBook.h";
GradeBook::GradeBook(string name) {
setCourseName(name);
maximumGrade = 0;
}
void GradeBook::setCourseName(string name) {
if (name.length() <= 25) {
courseName = name;
} else {
courseName = name.substr(0, 25);
cout << "Name \"" << name << "\" exceed maximum length of 25.\n"
<< "Only gets the first 25 characters";
}
}
string GradeBook::getCourseName() {
return courseName;
}
void GradeBook::displayMessage() {
cout << "Welcome to " << getCourseName() << "!\n" << endl;
}
void GradeBook::inputGrades() {
int grade1, grade2, grade3;
cout << "Grade 1: ";
cin >> grade1;
cout << "Grade 2: ";
cin >> grade2;
cout << "Grade 3: ";
cin >> grade3;
maximumGrade = maximum(grade1, grade2, grade3);
}
int GradeBook::maximum(int x, int y, int z) {
int max = x;
if (y > max) {
max = y;
}
if (z > max) {
max = z;
}
return max;
}
void GradeBook::displayGradeReport() {
cout << "Max grade: " << maximumGrade << endl;
}
int main() {
GradeBook myGradeBook("C++ PROGRAMMING");
myGradeBook.displayMessage();
myGradeBook.inputGrades();
myGradeBook.displayGradeReport();
return 0;
}
They said that there's something wrong with the constructor, I have no clue why...
