The program needs to use Classes and its functions to manipulate data members and print the information to the screen.
More specifically, the Class is supposed to be of a simple GradeBook for an instructor to use. The program should instantiate 2 objects of GradeBook, and set default string values for both the courseName and instructorName. It should then pass that information along to the set and get functions for both instructorName and courseName, and display a message to the user displaying the class information.
I am a brand new beginner and this is really weird for me. I've never done C++ progamming outside of basic arithmetic operations and displaying/getting info using the <iostream>. Also, the assignment says to separate the interface from the implementation, so this is what I have so far for 3 of my files:
GradeBook.h
GradeBook.cppCode:#include <string> using std::string; // Gradebook Class Definition class GradeBook { public: GradeBook::GradeBook( string, string ); // Constructor that initializes courseName and instructName. void setCourseName ( string name1 ); // function that sets course name. string getCourseName(); // function that gets the course name void setInstructName ( string name2 ); // function that sets instructor name string getInstructName(); // function that gets the instructor name private: string courseName; // course name for this GradeBook string instructName; // instructor name for this GradeBook }; // end definition of class GradeBook
GradeBookFinal.cppCode:#include <iostream> using std::cout; using std::endl; #include "GradeBook.h" // include definition of class gradebook. //constructor initializes courseName and instructName with string supplied as argument GradeBook::GradeBook( string name1, string name2 ) { setCourseName( name1 ); // call set function to initialize courseName setInstructName( name2 ); // call set function to initialize instructName } // end GradeBook constructor // function to set the course name void GradeBook::setCourseName( string name1 ) { courseName = name1; // store the course name in the object } // end function setCourseName // function to set the instructor name void GradeBook::setInstructName( string name2 ) { instructName = name2; // store the instructor name in the object } // end function setInstructName // function to get the course name string GradeBook::getCourseName() { return courseName; // returns object's course name } // end function getCourseName //function to get the instructName string GradeBook::getInstructName() { return instructName; // returns object's instructName } // end function getInstructName // function to display a welcome message to the GradeBook user void GradeBook::displayMessage() { // call getCourseName and getInstructName to get the names cout << "Welcome to the gradebook for\n" << getCourseName() << "!" << endl << "\n This course is provided by: " << getInstructName() << endl; } // end function displayMessage
I'm really stuck, I re read the content in my book and I just do not understand. Why must this all be so complicated. Can anyone help me?Code:#include <iostream> using std::cout; using std::endl; #include "GradeBook.h" // include definition of class GradeBook // function main begins program execution int main() { // creae two GradeBook objects GradeBook gradeBook1( "CS101 Intro to C++ Program", "Mary" ); GradeBook gradeBook2( "CS102 Data Structs in C++", "Mary" ); // display initial value of courseName and instructName for each GradeBook cout << "gradeBook1 created for course: " << gradeBook1.getCourseName() << "\ngradeBook2 created for course: " << gradeBook2.getCourseName() << endl; return 0; // indicate successful termination. } // end function main


Reply With Quote


Bookmarks