Gradebook.h
include <string.h>
class GradeBook
{
public:
GradeBook(string);
void setCourseName(string);
string getCourseName();
void displayMessage();
void determineClassAverage();
private:
string courseName;
};
GradeBook.cpp
#include <iostream>
#include "gradebook.h"
using namespace std;
GradeBook::GradeBook(string name)
{
setCourseName(name);
}
void GradeBook::setCourseName(string name)
{
if (name.length()<=25)
courseName=name;
else
{
courseName=name.substr(0,25);
cout<<"Name\""<<name<<"\"exceeds maximum lenght (25).\n"
<<"Limiting courseName to first 25 characters.\n"<<endl;
}
}
string GradeBook::getCourseName()
{
return courseName;
}
void GradeBook::displayMessage()
{
cout<<"Welcome to the grade book for\n"<<getCourseName()<<"!\n"
<<endl;
}
void GradeBook::determineClassAverage()
{
int total;
int gradeCounter;
int grade;
int average;
total=0;
gradeCounter=1;
while (gradeCounter<=10)
{
cout<<"Enter grade: ";
cin>>grade;
total=total+grade;
gradeCounter=gradeCounter+1;
}
average=total/10;
cout<<"\nTotal of all 10 grades is"<<total<<endl;
cout<<"Class average is"<<average<<endl;
}
int main()
{
GradeBook myGradeBook ("sanseverino raffaele");
myGradeBook.displayMessage();
myGradeBook.determineClassAverage();
return 0;
}