// CIS 235 - Review for Final fheap.cpp // Using heap memory in the driver program #include using std::ostream; using std::cout; using std::endl; class demo { friend ostream & operator << (ostream & w, const demo & d) { w << d.info; return w; } public: demo(int a) { info = a;} int f1(void) const { return info;} demo operator + (const demo & r) const { return demo( info + r.info); } private: int info; }; void main() { demo a(4),b(5),c(6); cout << a << ' ' << b << endl; if (a.f1() > b.f1() ) cout << c.f1() << endl; a = b + c; cout << a << endl; // // // rewrite the above code in main using three pointers // Besides cout, the only variable names you can use are p1, p2, p3 // You CAN NOT use a, b, or c demo * p1, * p2, * p3; p1 = new demo(4); p2 = new demo(5); p3 = new demo(6); cout << *p1 << ' ' << *p2 << ' ' << *p3 << endl; if ( p1->f1() > p2->f1() ) cout << p3->f1() << endl; *p1 = *p2 + *p3; cout << *p1 << endl; delete p1; delete p2; delete p3; } /* 4 5 11 4 5 6 11 */