Discount Get COMP 220 ALL WEEKS Solution ONLY $92.95 $123.93
COMP 220 Week 1 - Blackjack Program C++ [$19.99]
COMP 220 Week 2 - Resistor Program C++ [$15.99]
COMP 220 Week 3 - Bank Account Program C++ [$19.99]
COMP 220 Week 4 - Filter Program C++ [$19.99]
COMP 220 Week 5 - Pointers and Pointer Operations C++ [$15.99]
COMP 220 Week 6 - Filter Program C++ [$15.99]
COMP 220 Week 7 - Polymorphism C++ [$15.99]
Get Selected Weeks Solution with ONLY NOT Add Selected Tutorials To Cart
COMP220 COMP 220 COMP/220 Week 6 - Lab 6 - iLab 6 - Complex Program C++
    COMP220 COMP 220 COMP/220 Week 6 - Lab 6 - iLab 6 - Complex Program C++ COMP220 COMP 220 COMP/220 Week 6 - Lab 6 - iLab 6 - Complex Program C++

COMP220 COMP 220 COMP/220 Week 6 - Lab 6 - iLab 6 - Complex Program C++

$15.99

iLab 6 of 7: Overloaded Operators

i L A B  O V E R V I E W      

Scenario and Summary 

This lab is to introduce students to the concept of operator overloading as member functions of a class. This will be done in the context of creating a class that will perform four basic mathematical operations on complex numbers.

The C++ compiler has defined operators for all the arithmetic and assignment operations for its native 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 operate specifically on these user-defined data types. Which set of operators is actually called and implemented is decided during the compilation, and it is based on the data types of the operands involved in the operation.

The ability to define a new set of data-type, dependent operations on existing operators, or functions, is called operator overloading.

Deliverables

1.            Submit a single Notepad file containing the source code for all files of the lab to the Week 5 Dropbox. Your source code should use proper indentation and be error free. Be sure that your last name 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 lab and exercise number, and a description of what the program accomplishes.

2.            Submit a lab report (a Word document) containing the following information to the Week 6 Dropbox.

o             Include your name and the lab or lab exercise number.

o             Specification: Include a brief description of what the program accomplishes, including its input, key processes, and output.

o             Test Plan: Include a brief description of the method you used to confirm that your program worked properly. If necessary, include a clearly labeled table with test cases, predicted results, and actual results.

o             Summary and Conclusions: Write a statement summarizing your predicted and actual output, and identify and explain any differences. For conclusions, write at least one nontrivial paragraph that explains, in detail, either a significant problem you had and how you solved it or, if you 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, data types, 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 the lab steps.

Each lab exercise should have a separate section in the lab-report document.

Your lab grade is based upon

1.            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; and

5.            the completeness of your lab report.

i L A B  S T E P S  

STEP 1: Create a New Multifile Project  

Create a new multifile project, and create a class to model complex-number, mathematical operations 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 and the imaginary values of a complex number.

2.            Design and add overloaded operators to perform correct and complex mathematical operations on objects of the complex-number class.

STEP 2: Create and Add the Overloaded Operators         

1.            Overload the addition operator (+) to perform complex mathmatical addition on two objects of the complex-number class.

2.            Overload the subtraction operator (-) to perform complex mathmatical subtraction on two objects of the complex-number class.

3.            Overload the multiplication operator (*) to perform complex mathmatical multiplication on two objects of the complex-number class.

4.            Overload the division operator (/) to perform complex mathmatical division on two objects of the complex-number class.

5.            Overload the assignment operator (=) to assign all the data values of an object in the complex-number class to another object in the complex-number class.

STEP 3: Test the Overloaded Operators

Create at least three objects of the complex-number class in function main() and use them to perform 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.

Use this driver file to TEST your week 6 assignment...

// COMP 220 Week 6 Overloaded Operators

// Complex Math Operator Overload Lab Assignment

// This program asks the user to enter two complex numbers in real, imag format

// and then uses overloaded operators to perform complex math operations.

#include <iomanip>

#include <iostream>

#include <math.h>

#include <windows.h>

#include "complexnumber.h"

using namespace std;

int main(void)

{

 cout << "This program performs complex math addition, subtraction, "

  << endl << "multiplication and division operations on complex data"

  << endl << "utilizing operator overloading." << endl << endl;

 cout << "Instantiate three objects of class complex number" << endl << endl;

 ComplexNumber compOne(5.0, 6.0);

 ComplexNumber compTwo(3.0, 9.0);

 ComplexNumber compThree;

 cout << fixed << setprecision(3) << showpoint;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "Set compThree equal to compOne using overloaded assignment operator." << endl << endl;

 compThree = compOne;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "Set compThree = compOne + compTwo using overloaded + operator." << endl << endl;

 compThree = compOne + compTwo;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "Set compThree = compOne - compTwo using overloaded - operator." << endl << endl;

 compThree = compOne - compTwo;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "Set compThree = compOne * compTwo using overloaded * operator." << endl << endl;

 compThree = compOne * compTwo;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "Set compThree = compOne / compTwo using overloaded / operator." << endl << endl;

 compThree = compOne / compTwo;

 cout << "Comp One real part   = " << setw(8) << compOne.getRealPart() << endl;

 cout << "Comp One imag part   = " << setw(8) << compOne.getImagPart() << "j" << endl;

 cout << "Comp Two real part   = " << setw(8) << compTwo.getRealPart() << endl;

 cout << "Comp Two imag part   = " << setw(8) << compTwo.getImagPart() << "j" << endl;

 cout << "Comp Three real part   = " << setw(8) << compThree.getRealPart() << endl;

 cout << "Comp Three imag part = " << setw(8) << compThree.getImagPart() << "j" << endl;

 cout << endl << "End Complex Number Program" << endl << endl;

}

My tutorial contains Visual C++ 2010 Project.

If you have more questions, please contact me via email support@extutorials.com

I will help you any time

Thank you !

Attached Files

Move over [ preview ] file name to preview content in it!

Write a review

Your Name:


Your Review: Note: HTML is not translated!

Rating: Bad           Good

Enter the code in the box below:



PURCHASE SAVE
2 Tutorials 10%
3 Tutorials 13%
4 Tutorials 16%
5 Tutorials 19%
6 Tutorials 22%
7 Tutorials 25%
8 Tutorials 28%
9 Tutorials 31%
10 Tutorials 34%
add url more

9MZQASHWN73B