1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hram777 [196]
3 years ago
10

Given two complex numbers, find the sum of the complex numbers using operator overloading.Write an operator overloading function

ProblemSolution operator + (ProblemSolution const &P)which adds two ProblemSolution objects and returns a new ProblemSolution object

Computers and Technology
1 answer:
Inessa05 [86]3 years ago
4 0

Answer:

I am writing the program in C++ programming language.  

#include<iostream>  // to use input output functions

using namespace std;   // to identify objects like cin cout

class ProblemSolution {  //class name

private:  

// private data members that only be accessed within ProblemSolution class

int real, imag;

 // private variables for real and imaginary part of complex numbers

public:  

// constructor ProblemSolution() to initialize values of real and imaginary numbers to 0. r is for real part and i for imaginary part of complex number

ProblemSolution(int r = 0, int i =0) {  

real = r; imag = i; }  

/* print() method that displays real and imaginary part in output of the sum of complex numbers */

void print(){  

//prints real and imaginary part of complex number with a space between //them

cout<<real<<" "<<imag;}  

// computes the sum of complex numbers using operator overloading

ProblemSolution operator + (ProblemSolution const &P){  //pass by ref

          ProblemSolution sum;  // object of ProblemSolution

          sum.real = real + P.real;  // adds the real part of the  complex nos.

          sum.imag = imag + P.imag;  //adds imaginary parts of  complex nos.

//returns the resulting object

          return sum;       }  //returns the sum of complex numbers

};   //end of the class ProblemSolution

int main(){    //start of the main() function body

int real,imag;  //declare variables for real and imaginary part of complex nos

//reads values of real and imaginary part of first input complex no.1

cin>>real>>imag;  

//creates object problemSolution1 for first complex number

ProblemSolution problemSolution1(real, imag);  //creates object

//reads values of real and imaginary part of first input complex no.2

cin>>real>>imag;

//creates object problemSolution2 for second complex number

ProblemSolution problemSolution2(real,imag);

//creates object problemSolution2 to store the addition of two complex nos.

ProblemSolution problemSolution3 = problemSolution1 + problemSolution2;

problemSolution3.print();} //calls print() method to display the result of the //sum with real and imaginary part of the sum displayed with a space

Explanation:

The program is well explained in the comments mentioned with each statement of the program. The program has a class named ProblemSolution which has two data members real and imag to hold the values for the real and imaginary parts of the complex number. A default constructor ProblemSolution() which initializes an the objects for complex numbers 1 and 2 automatically when they are created.

ProblemSolution operator + (ProblemSolution const &P) is the operator overloading function. This performs the overloading of a binary operator + operating on two operands. This is used here to add two complex numbers.  In order to use a binary operator one of the operands should be passed as argument to the operator function. Here one argument const &P is passed. This is call by reference. Object sum is created to add the two complex numbers with real and imaginary parts and then the resulting object which is the sum of these two complex numbers is returned.  

In the main() method, three objects of type ProblemSolution are created and user is prompted to enter real and imaginary parts for two complex numbers. These are stored in objects problemSolution1 and problemSolution2.  Then statement ProblemSolution problemSolution3 = problemSolution1 + problemSolution2;  creates another object problemSolution3 to hold the result of the addition. When this statement is executed it invokes the operator function ProblemSolution operator + (ProblemSolution const &P). This function returns the resultant complex number (object) to main() function and print() function is called which is used to display the output of the addition.

You might be interested in
In 1972, earlier designers built the
Sonbull [250]

The exercise is about filling in the gaps and is related to the History of the ARPANET.

<h3>What is the History of the ARPANET?</h3>

From the text:

In 1972, earlier designers built the <u>ARPANET </u>connecting major universities. They broke communication into smaller chunks, or <u>packets </u>and sent them on a first-come, first-serve basis. The limit to the number of bytes of data that can be moved is called line capacity, or <u>bandwidth</u>.

When a network is met its capacity the user experiences <u>unwanted pauses</u>. When the network is "slowing down", what is happening is users are waiting for their packet to leave the <u>queue</u>.

To make the queues smaller, developers created <u>mixed </u>packets to move <u>simultaneously</u>.

Learn more about the ARPANET at:
brainly.com/question/16433876

7 0
2 years ago
Functions of barriers include (mark all that apply): A. Define boundaries B. Design layout C. Deny access D. Delay access
gayaneshka [121]

Answer:

A. Define boundaries

C. Deny access

D. Delay access

Explanation:

A barrier is a material or structure used to prevent or block access. Barriers can either be natural or structural and are used for many purposes usually for security reasons. The following are functions of barriers either natural or structural:

  1. Define areas of boundaries
  2. Delay or slow access. Example is the use of speed bumps to slow down vehicles.
  3. Provide access to entrances such as the use of gates
  4. Deny access to unauthorized personnel and allowing authorized personnel.
4 0
3 years ago
___ is code that runs when a specific event happens.
Slav-nsk [51]
A callback function is code that's called, or run, when a specific event such as a click of the mouse, happens.Callback is another name for a callback function. Thank you for posting your question here at brainly. I hope the answer will help you. Feel free to ask more questions.
6 0
3 years ago
How do you find the exterior angle measure of any regular polygon? (The degree in which to turn the turtle to draw a shape)
Diano4ka-milaya [45]

Answer:

360/number of sides

Explanation:

all the exterior angles add up to 360°

so to find each angle mesure, divide the 360 by the number of sides the figure has.

7 0
3 years ago
What should you do when you encounter an active directory domain controller for the domain could not be contacted?
Nostrana [21]

Answer:

Issue the Dcdiag on all domain controller servers.

Explanation:

Active directory is a database that holds information of client's authentication for service access in a server. Domain controllers in servers holds these active directories, to replicate client's credentials for quick response to access to the server.

When a server domain can not contact the active directory domain controller, the Dcdiag command is issued on the server to check for connectivity issue to the DNS, AD replication, SYSVOL replication etc.

8 0
3 years ago
Other questions:
  • Who does Potholes effect in South Africa?
    15·1 answer
  • What are some facts about webmasters?
    10·1 answer
  • What default length is used for the ospf dead interval?
    14·1 answer
  • Assume the following instruction mix for some program:______.
    8·1 answer
  • Are mobile phones hazardous to your health?
    13·2 answers
  • If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsA
    7·1 answer
  • Ben is writing a paper for his college history class, and he wants to include some information he found on a Web site. What are
    5·1 answer
  • UPS or FedEx plays what role in the supply?
    9·1 answer
  • The chain of _____ documents that the evidence was under strict control at all times and no unauthorized person was given the op
    13·1 answer
  • It is possible to create a share that is invisible to users browsing the network simply by appending what character to the end o
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!