Comp 220 ilab 6 of 7


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Comp 220 ilab 6 of 7

  1. 1. COMP/220 iLab 6 of 7 - C++ CourseiLab 6 of 7: Overloaded OperatorsiLAB OVERVIEWScenario and SummaryThis lab is to introduce students to the concept of operator overloading as member functions of aclass. This will be done in the context of creating a class that will perform four basic mathematicaloperations on complex numbers.The C++ compiler has defined operators for all the arithmetic and assignment operations for itsnative data types, such as integer, float, double, and so forth. However, for user-defined data types,such as classes and structures, these operations are undefined.C++ allows the programmer to create new definitions for these operators so that they can operatespecifically on these user-defined data types. Which set of operators is actually called andimplemented is decided during the compilation, and it is based on the data types of the operandsinvolved in the operation.The ability to define a new set of data-type, dependent operations on existing operators, orfunctions, is called operator overloading.Deliverables1. Submit a single Notepad file containing the source code for all files of the lab to the Week5 Dropbox. Your source code should use proper indentation and be error free. Be sure that your lastname and the lab number are part of the file name: for example, YourLastName_Lab5.txt.Each program should include a comment section that includes, at a minimum, your name, the laband exercise number, and a description of what the program accomplishes.2. Submit a lab report (a Word document) containing the following information to the Week6 Dropbox.o Include your name and the lab or lab exercise number.o Specification: Include a brief description of what the program accomplishes, including itsinput, key processes, and output.o Test Plan: Include a brief description of the method you used to confirm that yourprogram worked properly. If necessary, include a clearly labeled table with test cases, predictedresults, and actual results.
  2. 2. o Summary and Conclusions: Write a statement summarizing your predicted and actualoutput, and identify and explain any differences. For conclusions, write at least one nontrivialparagraph that explains, in detail, either a significant problem you had and how you solved it or, ifyou had no significant problems, something you learned by doing the exercise.o A UML diagram: This should show all the classes, class members, access specifiers, datatypes, and function arguments, along with any and all class-to-class relationships.o Answers to Lab Questions: Include the answers to any and all lab questions asked in thelab steps.Each lab exercise should have a separate section in the lab-report document.Your lab grade is based upon1. the formatting of your source code;2. the use of meaningful identifiers;3. the extent of internal documentation;4. the degree to which an exercises’ specifications are met; and5. the completeness of your lab report.iLAB STEPSSTEP 1: Create a New Multifile ProjectCreate a new multifile project, and create a class to model complex-number, mathematicaloperations using overloaded operators and add main() test functions to test the operations.1. Create a class for complex numbers that will provide the means to store both the real andthe imaginary values of a complex number.2. Design and add overloaded operators to perform correct and complex mathematicaloperations on objects of the complex-number class.STEP 2: Create and Add the Overloaded Operators1. Overload the addition operator (+) to perform complex mathmatical addition on twoobjects of the complex-number class.2. Overload the subtraction operator (-) to perform complex mathmatical subtraction on twoobjects of the complex-number class.3. Overload the multiplication operator (*) to perform complex mathmatical multiplication ontwo objects of the complex-number class.4. Overload the division operator (/) to perform complex mathmatical division on two objectsof the complex-number class.
  3. 3. 5. Overload the assignment operator (=) to assign all the data values of an object in thecomplex-number class to another object in the complex-number class.STEP 3: Test the Overloaded OperatorsCreate at least three objects of the complex-number class in function main() and use them toperform the following operation tests.1. Demonstrate the correct operation of the complex addition overloaded operator.2. Demonstrate the correct operation of the complex subtraction overloaded operator.3. Demonstrate the correct operation of the complex division overloaded operator.4. Demonstrate the correct operation of the complex multiplication overloaded operator.CLICK HERE TO GET THE SOLUTION !!!!!!