Question: in C++ Please In the class definition, initialize the data members, string title, integer year, and integer numWords, with the default values Incomplete, -1, and

in C++ Please

In the class definition, initialize the data members, string title, integer year, and integer numWords, with the default values "Incomplete", -1, and -1, respectively.

Ex: If the input is Daisy 2003 26500, then the output is:

Title: Incomplete, Year: -1, Number of words: -1 Title: Daisy, Year: 2003, Number of words: 26500

Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters.

#include #include using namespace std;

class Play { public: void SetTitle(string playTitle); void SetYear(int playYear); void SetNumWords(int playNumWords); void Print();

private:

/* Your code goes here */

};

void Play::SetTitle(string playTitle) { title = playTitle; }

void Play::SetYear(int playYear) { year = playYear; }

void Play::SetNumWords(int playNumWords) { numWords = playNumWords; }

void Play::Print() { cout << "Title: " << title << ", Year: " << year << ", Number of words: " << numWords << endl; }

int main() { string newTitle; int newYear; int newNumWords; Play favoritePlay;

favoritePlay.Print();

cin >> newTitle; cin >> newYear; cin >> newNumWords;

favoritePlay.SetTitle(newTitle); favoritePlay.SetYear(newYear); favoritePlay.SetNumWords(newNumWords);

favoritePlay.Print();

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!