• 0

[C++] Modifying Class GradeBook


Question

Hai guys!

As some of you may know I am very new to the C++ programming world and need help getting started.

Here is my problem:

(Modifying Class GradeBook) Modify class GradeBook as follows:

A) Include a second string data member that represents the course instructor's name.

B) Provide a set function to change the instructor's name and a get function to retrieve it.

C) Modify the constructor to sepcify two prameters--one for the course name and one for the instructor's name.

D) Modify member function displayMessage to output the welcome message and course name, then the string "This is presented by: "followed by the instructor's name, then the string "This course is presented by "followed by the instructor's name.

This is what I have so far, I need allot of assistance piecing the rest of the stuff so if any of you guys can give me the "full picture" I'd appreciate it greatly

GradeBook.cpp

  Quote
// Fig. 3.12: GradeBook.cpp

// GradeBook member-function definitions. This file contains

// implementations of the member functions prototyped in GradeBook.h.

#include <iostream>

using std::cout;

using std::endl;

#include "GradeBook.h" // include definition of class GradeBook

// constructor initializes courseName with string supplied as argument

GradeBook::GradeBook( string name )

{

setCourseName( name ); // call set function to initialize courseName

} // 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()

{

return courseName; // return object's courseName

} // end function to getCourseName

// display a welcome message to the GradeBook user

void GradeBook::displayMesasge()

{

// call getCourseName to get the courseName

cout << "Welcome to the grade book for\n" << getCourseName()

<< "!" << endl;

} // end function displayMessage

GradeBook.h

  Quote
// Fig. 3.11: GradeBook.h

// GradeBook class definition. This file presents GradeBook's public

// interface without revealing the implementations of GradeBook's member

// fucntions, which are defined in GradeBook.cpp.

#include <string> // classs GradeBook uses C++ standard string class

using std::string;

// GradeBook class definition

class GradeBook

{

public:

GradeBook( string ); // constructor that initializes courseName

void setCourseName( string ); // function that sets the course name

string getCourseName(); // function that gets the course name

void displayMessage(); // function that displays a welcome message

private:

string courseName; // course name for this GradeBook

}; // end class GradeBook

Link to comment
https://www.neowin.net/forum/topic/670616-c-modifying-class-gradebook/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Your first step is to make the class schema changes in the header:

class GradeBook
{
	public:
		GradeBook( string );
		void setCourseName( string );
		string getCourseName();
		void displayMessage();

		void setInstructorName(string);
		string getInstructorName();

	private:
		string courseName;
		string instructorName;
};

After you have done this, its just simply making additions to the .cpp file:

void GradeBook::setInstructorName(string name)
{
	instructorName = name;
}

string GradeBook::getInstructorName()
{
	return instructorName;
}

void GradeBook::displayMessage()
{
	cout &lt;&lt; "Welcome to the gradebook for: " &lt;&lt; getCourseName() &lt;&lt; endl;
	cout &lt;&lt; "This couse is presented by " &lt;&lt; getInstructorName() &lt;&lt; endl;
}

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.