#include #include using namespace std; #include "point.h" #include "dotToDot.h" #include "myio.h" dotToDot shift(const dotToDot&); void print(const dotToDot&); int main( ) { ifstream fin; // for the input file cout << "Enter the name of the file of points -- "; openIn(fin); // ask user for file name and open it dotToDot pic1, pic2; point pt; while ( true ) { fin >> pt; // try to read a point from the file if (fin.eof()) break; // found end of file so outta here pic1.append(pt); // insert it into the diagram } fin.close(); // test the assignment operator pic2 = shift(pic1); // remove the last two points pic2.remove(); pic2.remove(); pic1.clear(); // remove all dots from pic1 // print both pictures cout << "Picture 1 is " << endl; print(pic1); cout << endl; cout << "Picture 2 is " << endl; print(pic2); cout << endl; return 0; } // this will test the copy constructor and the destructor dotToDot shift(const dotToDot& pic) { dotToDot copy(pic); // make a copy of the pic; test the copy constructor // shift the copy to the left 3.5 and down -2.4 for (int i = 0; i < pic.size(); i++) copy[i].shift(3.5,-2.4); // this requires you to overload the [] operator // and since copy is not const, will call // the l-value version return copy; // this will also use the copy constructor // note: that since copy is declared locally, it is out of scope // after the function exits so the destructor is called // so this will test the destructor } // print the dotToDot puzzle void print(const dotToDot& pic) { int numDots = pic.size(); // test the size function if (numDots == 0) cout << "No Picture!!" << endl; else for (int i = 0; i < numDots; i++) cout << pic[i] << endl; // since pic is const, this will call // the r-value version of [] overload }