SlideShare ist ein Scribd-Unternehmen logo
1 von 3
COMP/220 iLab 6 of 7 - C++ Course

iLab 6 of 7: Overloaded Operators

iLAB OVERVIEW

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.



iLAB STEPS

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.


CLICK HERE TO GET THE SOLUTION !!!!!!

Weitere ähnliche Inhalte

Was ist angesagt?

stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structurefaran nawaz
 
Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17Fahadaio
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...licservernoida
 
Assignment java workshop
Assignment java workshopAssignment java workshop
Assignment java workshopJaya Jeswani
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingVIKASH MAINANWAL
 
UnCoRe-YvesSerena
UnCoRe-YvesSerenaUnCoRe-YvesSerena
UnCoRe-YvesSerenaSerena King
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structuresMicheal Ogundero
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1Syed Farjad Zia Zaidi
 
9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sortTerry Yoast
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#Ali Hassan
 

Was ist angesagt? (17)

stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 
Java programlist (1)
Java programlist (1)Java programlist (1)
Java programlist (1)
 
Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17
 
Oop sample ktu
Oop sample ktuOop sample ktu
Oop sample ktu
 
Experiment 9(exceptions)
Experiment 9(exceptions)Experiment 9(exceptions)
Experiment 9(exceptions)
 
Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...Writea program that defines a template function named add(). Thisfunction tak...
Writea program that defines a template function named add(). Thisfunction tak...
 
Fundamental
FundamentalFundamental
Fundamental
 
Assignment java workshop
Assignment java workshopAssignment java workshop
Assignment java workshop
 
Implicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handlingImplicit and explicit sequence control with exception handling
Implicit and explicit sequence control with exception handling
 
UnCoRe-YvesSerena
UnCoRe-YvesSerenaUnCoRe-YvesSerena
UnCoRe-YvesSerena
 
Templates1
Templates1Templates1
Templates1
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
 
selection structures
selection structuresselection structures
selection structures
 
Introduction To Programming with Python-1
Introduction To Programming with Python-1Introduction To Programming with Python-1
Introduction To Programming with Python-1
 
Pa1 session 2
Pa1 session 2 Pa1 session 2
Pa1 session 2
 
9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort9781111530532 ppt ch14_quick_sort
9781111530532 ppt ch14_quick_sort
 
Command Line Arguments in C#
Command Line Arguments in C#Command Line Arguments in C#
Command Line Arguments in C#
 

Ähnlich wie Comp 220 ilab 6 of 7

Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7ashhadiqbal
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7helpido9
 
Comp 220 i lab 6 overloaded operators lab report and source code
Comp 220 i lab 6 overloaded operators lab report and source codeComp 220 i lab 6 overloaded operators lab report and source code
Comp 220 i lab 6 overloaded operators lab report and source codepradesigali1
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesccis224477
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02auswhit
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Abdul Hannan
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablessdjdskjd9097
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablescis247
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxalfred4lewis58146
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1ReKruiTIn.com
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comledlang1
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSnikshaikh786
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxfestockton
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Tiểu Hổ
 

Ähnlich wie Comp 220 ilab 6 of 7 (20)

Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
Comp 220 i lab 6 overloaded operators lab report and source code
Comp 220 i lab 6 overloaded operators lab report and source codeComp 220 i lab 6 overloaded operators lab report and source code
Comp 220 i lab 6 overloaded operators lab report and source code
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Lewis jssap3 e_labman02
Lewis jssap3 e_labman02Lewis jssap3 e_labman02
Lewis jssap3 e_labman02
 
Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual Object Oriented Programming Lab Manual
Object Oriented Programming Lab Manual
 
Cis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variablesCis247 i lab 3 overloaded methods and static methods variables
Cis247 i lab 3 overloaded methods and static methods variables
 
Cis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variablesCis247 a ilab 3 overloaded methods and static methods variables
Cis247 a ilab 3 overloaded methods and static methods variables
 
Instant DBMS Homework Help
Instant DBMS Homework HelpInstant DBMS Homework Help
Instant DBMS Homework Help
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
ECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.comECET 370 Success Begins/Newtonhelp.com
ECET 370 Success Begins/Newtonhelp.com
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
 
Lab Manual-OOP.pdf
Lab Manual-OOP.pdfLab Manual-OOP.pdf
Lab Manual-OOP.pdf
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 

Mehr von ashhadiqbal

Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6ashhadiqbal
 
Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6ashhadiqbal
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6ashhadiqbal
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6ashhadiqbal
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6ashhadiqbal
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7ashhadiqbal
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7ashhadiqbal
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7ashhadiqbal
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7ashhadiqbal
 

Mehr von ashhadiqbal (13)

Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6Cis 355 ilab 4 of 6
Cis 355 ilab 4 of 6
 
Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6
 
Ilab 2 of 7
Ilab 2 of 7Ilab 2 of 7
Ilab 2 of 7
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7CIS/336 ilab 5 of 7
CIS/336 ilab 5 of 7
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7
 
PRG/421 Week 4
PRG/421 Week 4PRG/421 Week 4
PRG/421 Week 4
 
PRG/421 Week 2
PRG/421 Week 2PRG/421 Week 2
PRG/421 Week 2
 
PRG/421 Week 1
PRG/421 Week 1PRG/421 Week 1
PRG/421 Week 1
 

Comp 220 ilab 6 of 7

  • 1. COMP/220 iLab 6 of 7 - C++ Course iLab 6 of 7: Overloaded Operators iLAB OVERVIEW 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.
  • 2. 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. iLAB STEPS 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.
  • 3. 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. CLICK HERE TO GET THE SOLUTION !!!!!!