The purpose of this lab is to gain further experience with defining, implementing, and using classes in C++, in particular, with overloading operators. This lab also involves further aspects of managing multiple-source-file programs.
The ASSIGNMENT:
Students with WebCT accounts should can complete this lab by filling out the Quiz Form. If you do not have a WebCT account, you can turn in a paper version of the lab. However, you should also notify your TA that you do not have a WebCT account so we can get one for you!
Contents:
For this lab, you will modify a multi-file program. You will use a pre-defined class called POINT whose declaration and definition are stored in separate files. You will also modify a pre-defined class called LINE and write a main() program which uses these classes.
You will be given classes for POINT and LINE that are extensions of the structs you developed for those concepts a few weeks ago. Today, you will take the given definitions of those classes and extend them to define your own ">>" and "<<" operators. Download the following files for the lab.to test this.) Continue until your code works properly. Following the logic used in overloading the "<<" operator, see if you can write the " >>" operator and corresponding facilitator "Extract()" for the POINT class. (Hint: do you think you will use ostream for input, or perhaps some other type?)// cout << "\nLine1: " << line1 << ";\nLine2: " << line2 << endl;
Compile it again and run the program. Finish the LINE class for the ">>" operator and corresponding facilitator "Extract()". (Hint: you may find it useful to use the ">>" operator given by the POINT class in your definition of the ">>" operator for the LINE class.)cout << "Please input the first point in the format (x,y): "; cin >> p1; ...
The ability to overload standard operators such as ">>" and "<<" allows user-defined classes in C++ to behave like first-class objects that are built-in to the language. The process of creating a public facilitator method which is a member of the class, then defining the overloaded operator by calling the facilitator, permits the overloaded operator to access private data objects while allowing their actual implementation details to remain hidden.