/*---- signature: main: void -> int purpose: to try out our ColorPlay derived class compile using: (all on one line) g++ ColorPoint-play.cpp Point.cpp ColorPoint.cpp -o ColorPoint-play run using: ./ColorPoint-play | more # to better look over the results 8-) by: Sharon Tuttle last modified: 2022-11-11 - cleaned up after class 2022-11-10 - created 1st version during class, W12-2 ----*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include "Point.h" #include "ColorPoint.h" using namespace std; int main() { cout << boolalpha; ColorPoint c_point1; ColorPoint c_point2(3, 4.7, "blue"); cout << endl; cout << "trying out display, no-argument version: " << endl; c_point1.display(); c_point2.display(); // look! I inherited accessors! cout << endl; cout << "NOTE: these inherited accessors work!: " << endl; cout << " c_point1's x: " << c_point1.get_x() << endl; cout << " c_point1's y: " << c_point1.get_y() << endl; // and ColorPoint also has get_color cout << endl; cout << "and so does its specific-to-ColorPoint accessor:" << endl; cout << " c_point1's color: " << c_point1.get_color() << endl; cout << endl; cout << "c_point2's x: " << c_point2.get_x() << endl; cout << "c_point2's y: " << c_point2.get_y() << endl; cout << "c_point2's color: " << c_point2.get_color() << endl; // look! I inherited mutators, too! cout << endl; cout << "NOTE: these inherited mutators work!: " << endl; c_point1.set_x(1000); cout << " c_point1's x is NOW: " << c_point1.get_x() << endl; c_point1.set_y(2000); cout << " c_point1's y is NOW: " << c_point1.get_y() << endl; // and here's a new-to-ColorPoint mutator: cout << endl; cout << "and so does its specific-to-ColorPoint mutator:" << endl; c_point1.set_color("red"); cout << " c_point1's color is NOW: " << c_point1.get_color() << endl; // does ColorPoint inherit dist_from? cout << endl; cout << "inherited dist_from: " << endl << " distance from c_point1 to c_point2: " << c_point1.dist_from(c_point2) << endl; // what about the redefined display and to_string // methods? cout << endl; cout << "result of display (no arg version) for c_point1:" << endl; c_point1.display(); cout << endl; cout << "result of to_string for c_point1:" << endl << c_point1.to_string() << endl; // how about the overloaded display, with 1 argument? cout << endl; cout << "result of display (ONE arg version) for c_point1:" << endl; c_point1.display("Aidan"); // how about ==? ColorPoint cp3(10, 20, "purple"); ColorPoint cp4(10, 20, "green"); ColorPoint cp5(10, 20, "green"); Point p1(10, 20); cout << endl; cout << "cp3: " << cp3.to_string() << endl; cout << "cp4: " << cp4.to_string() << endl; cout << "cp5: " << cp5.to_string() << endl; cout << "p1: " << p1.to_string() << endl; cout << endl; cout << "result of cp3==cp4: " << (cp3 == cp4) << endl; cout << "result of cp4==cp5: " << (cp4 == cp5) << endl; cout << "result of p1==cp5 : " << (p1 == cp5) << endl; // cannot do this! // cout << "result of cp5==p1 : " << (cp5 == p1) << endl; // demo of calling base class' version of a method ColorPoint invis_pt(13, 15, "invisible"); cout << endl; cout << "calling ColorPoint version of to_string:" << endl; cout << invis_pt.to_string() << endl; cout << endl; cout << "calling Point version of to_string for the" << endl << " same ColorPoint object:" << endl; cout << invis_pt.Point::to_string() << endl; cout << endl; return EXIT_SUCCESS; }