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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started