// CIS 235 Exercise 3 #include #include using namespace::std; class recording { public: void setTitle(const string &); void setArtist(const string &); string getTitle(void) const; string getArtist(void) const; private: string title; string artist; }; // write the 4 member functions void recording::setTitle(const string & titleParameter) { title = titleParameter; } void recording::setArtist(const string & artistParameter) { artist = artistParameter; } string recording::getTitle(void) const { return title; } string recording::getArtist(void) const { return artist; } void print(ostream &, const recording &); void main() { recording one; // set the title and artist to "Msirlou" and "Dick Dale" one.setTitle("Msirlou"); one.setArtist("Dick Dale"); // call the print function print(cout, one); recording * p1; // allocate memory for a recording and store the address in p1 p1 = new recording; // set the title and artist to "Take a Chance on Me" and "ABBA"; (*p1).setTitle("Take a Chance on Me"); // (*p1). works but is NOT elegant - who likes parentheses? p1->setArtist("ABBA"); // Use -> membership-access operator is elegant and concise // call the print function for the recording pointed to by p1 print(cout, *p1); // Return all heap memory delete p1; } // write the print function void print(ostream & out, const recording & recordingPointer) { out << "Title is " << recordingPointer.getTitle() << endl; out << "Artist is " << recordingPointer.getArtist() << endl; } /* OUTPUT Title is Msirlou Artist is Dick Dale Title is Take a Chance on Me Artist is ABBA Press any key to continue . . . */