program10_1 - } void Person:: operator = (Person...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "iostream.h" #include "string.h" class Person { private: int age; char *name; public: Person(int a, char *s); ~Person( ); void display( ); void assign(int a, char *s); void operator = (Person &other_object); friend void show_older(Person &a, Person &b); }; Person::Person( int a, char *s) { cout << "Creating " << s << "\n"; age = a; name = new char[80]; strcpy (name,s); } Person::~Person() { cout << "Deleting " << name << "\n"; delete name; name = NULL; } void Person::assign( int a, char *s) { age = a; if (name == NULL) strcpy (name,s); } void Person::display() { cout << name << " is " << age << " years old \n";
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } void Person:: operator = (Person &amp;other_object) { age = other_object.age; strcpy(name,other_object.name); } void show_older(Person &amp;a, Person &amp;b) // I am a friend of Person { // so I can access private data cout &lt;&lt; &quot;The older person is : &quot;; if (a.age &gt; b.age) a.display(); else b.display(); } void main() { Person fred(37 ,&quot;fredy&quot;), bill(42, &quot;billy&quot;); fred.display(); bill.display(); show_older(bill,fred); bill = fred; // Our &quot;=&quot;, not the usual one. bill.display(); bill.assign(56, &quot;new guy&quot;); bill.display(); }...
View Full Document

This note was uploaded on 09/16/2011 for the course EGN 3210 taught by Professor Fernando during the Spring '05 term at University of Central Florida.

Page1 / 2

program10_1 - } void Person:: operator = (Person...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online