Print Friendly and PDF
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 specify course name and instructor name parameters. d) Modify function displayMessage to output the welcome message and course name, then the
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 specify course name and instructor name parameters.
d) Modify function displayMessage to output the welcome message and course name, then the string

 "This course is presented by: " followed by the instructor’s name.
Use your modified class in a test program that demonstrates the class’s new capabilities.

Solution:

Part:A

#include <string> 
using std: : string;
//GradeBook class definition
class GradeBook
{
public:
GradeBook( string, string ) ; // constructor that initializes courseName and courseInstructorName
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
void setCourseInstructorName( string ) ; // b) function that sets the course instructor name
string getCourseInstructorName() ; // b) function that get the course instructor name
private:
string courseName; // course name for this GradeBook
string courseInstructorName; // a) course instructor name for this GradeBook
}; // end class GradeBook

// GradeBook member‐function definitions. This file contains
// implementations of the member functions prototyped in GradeBook. h.

Part:B

#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, string insName ) { setCourseName( name ) ; // call set function to initialize courseName setCourseInstructorName( insName ) ; // c) } // 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 set the course instructor name void GradeBook: : setCourseInstructorName( string insName ) { courseInstructorName = insName; // 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 getCourseName // function to get the course instructor name string GradeBook: : getCourseInstructorName() { return courseInstructorName; // } // end function // display a welcome message to the GradeBook user void GradeBook: : displayMessage() { // call getCourseName to get the courseName cout << "Welcome to the grade book for\n" << getCourseName() << "! " << endl; cout << "This course is presented by " << getCourseInstructorName() << ". " << endl; } // end function displayMessage // GradeBook class demonstration after separating // its interface from its implementation.

Part:c

#include <iostream>

using std: : cout; using std: : endl; using std: : string; #include "GradeBook. h" // include definition of class GradeBook // function main begins program execution int main() { // create two GradeBook objects GradeBook gradeBook1( "CS101 Introduction to C++ Programming", "Paul Deitel" ) ; GradeBook gradeBook2( "CS102 Data Structures in C++", "Harvey Deitel" ) ; // display initial value of courseName for each GradeBook cout << "gradeBook1 created for course: " << gradeBook1. getCourseName() << "\ngradeBook2 created for course: " << gradeBook2. getCourseName() << endl; gradeBook1. displayMessage() ; gradeBook2. displayMessage() ; return 0; // indicate successful termination } // end main
zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

0 comments: