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
rusak2 [61]
3 years ago
5

Write a function namedadd_complex that adds the correspondingnumbers of its arguments (both complexstructures), then returns the

result (anothercomplex structure)
Computers and Technology
1 answer:
amid [387]3 years ago
3 0

Answer:

#include <iostream>

using namespace std;

struct complex{//structure of comlex number..

double real;

double img;

};

complex add_complex(complex n1,complex n2)//add_complex functrion to add 2 complex numbers..

{

   double a,b;//variables to hold the sum of real and imaginary.

   complex sum;//result sum complex number.

   a=n1.real+n2.real;//adding real parts.

   b=n1.img+n2.img;//adding imaginary parts..

   sum.real=a;//assinging values to sum.

   sum.img=b;

   return sum;//returning complex number sum.

}

int main()

{

 complex c1,c2,sum;

 double a,b;

 cout<<"Enter values of c1"<<endl;

 cin>>a>>b;

 c1.real=a;

 c1.img=b;

 cout<<"Enter values of c2"<<endl;

 cin>>a>>b;

 c2.real=a;

 c2.img=b;

 sum=add_complex(c1,c2);

 cout<<"The sum is : "<<sum.real<<" + i"<<sum.img<<endl;

 return 0;

}

OUTPUT:-

Enter values of c1

8.5 7.2

Enter values of c2

4.5 3.9

The sum is : 13 + i11.1

Explanation:

First I have created a structure for complex number.Then created a function to add two complex numbers according to the question which returns a complex number.

You might be interested in
What are the benefits if you pay off all your high-interest debt such as credit
lesya [120]
D. All of the above
7 0
4 years ago
Read 2 more answers
Why is it necessary to include units when measuring and dimensioning?
antoniya [11.8K]
Because the measurement is relative to the unit. For example:

A measurement is six. But could be 6 inches, 6 yards, 6 nm, 6 feet, six as a quantity, six packages, six items, etc.

So until you specify the unit, that number means nothing.
7 0
3 years ago
Construct a class that will model a quadratic expression (ax^2 + bx + c). In addition to a constructor creating a quadratic expr
stich3 [128]

Answer:

Following are the code to this question:

#include <iostream>//header file

#include<math.h>//header file

using namespace std;

class Quadratic//defining a class Quadratic  

{

private:

double a,b,c;//defining a double variable

public:

Quadratic()//defining default constructor

{

a = 0;//assigning value 0  

b = 0;//assigning value 0  

c = 0;//assigning value 0  

}

Quadratic(double a, double b, double c)//defining a parameterized constructor  

{

this->a = a;//use this keyword to hold value in a variable

this->b = b;//use this keyword to hold value in b variable

this->c = c;//use this keyword to hold value in c variable

}

double getA() //defining a get method  

{

return a;//return value a

}

void setA(double a)//defining a set method to hold value in parameter

{

this->a = a;//assigning value in a variable

}

double getB() //defining a get method  

{

return b;//return value b

}

void setB(double b)//defining a set method to hold value in parameter  

{

this->b = b;//assigning value in b variable

}

double getC() //defining a get method

{

return c;//return value c

}

void setC(double c)//defining a set method to hold value in parameter

{

this->c = c;//assigning value in c variable

}

double Evaluate(double x)//defining a method Evaluate to hold value in parameter

{

return ((a*x*x)+(b*x)+c);//return evaluated value

}

double numberOfReal()//defining a method numberOfReal to calculates the real roots

{

return (b*b)-(4*a*c);//return real roots

}

void findroots()//defining a method findroots

{

double d=numberOfReal();//defining double variable to hold numberOfReal method value

if(d<0)//use if block to check value of d less than 0

cout<<"Equation has no real roots"<<endl;//print message

else

{

double r1=(-b+sqrt(numberOfReal()))/(2*a);//holding root value r1

double r2=(-b-sqrt(numberOfReal()))/(2*a);//holding root value r2

if(r1==r2)//defining if block to check r1 equal to r2

cout<<"Equation has one real root that is "<<r1<<endl;//print message with value

else//else block

cout<<"The equation has two real roots that are "<<r1<<" and "<<r2<<endl;////print message with value

}

}

void print()//defining a method print  

{

cout<< a << "x^2 + " << b << "x + " << c <<endl;//print Quadratic equation

}

};

int main()//defining main method  

{

Quadratic q(5,6,1);//creating Quadratic class object that calls parameterized constructor

q.print();//calling print method

cout<<q.numberOfReal()<<endl;//calling method numberOfReal that prints its value

q.findroots();//calling method findroots

cout<<q.Evaluate(-1);//calling method Evaluate that prints its value

return 0;

}

Output:

5x^2 + 6x + 1

16

The equation has two real roots that are -0.2 and -1

0

Explanation:

In the above code, a class "Quadratic" is declared, which is used to define a default and parameter constructor to holds its parameter value.

In the next step, the get and set method is defined that holds and returns the quadratic value, and "Evaluate, numberOfReal, findroots, and print" in the evaluate method a double variable is used as a parameter that returns evaluated value.

In the "numberOfReal" method it calculates the real roots and returns its value. In the "findroots" method a double variable "d" is declared that hold "numberOfReal" value,

and use a conditional statement to check its value, and in the print method, it prints the quadratic equation.

In the main method, the lass object it calls the parameterized constructor and other methods.

5 0
3 years ago
What is the operating system in a computer?
vaieri [72.5K]

The answer to this question would be the last choice. The master program that controls the system hardware.

All computers require a software known as the <em>operating system</em> to properly function and allow you to use the computer. This operating system works as a "master program" that manages the computer's processes and memory.

3 0
3 years ago
Read 2 more answers
PLZ ANSWER ASAP WILL GIVE BRAINLYEST
malfutka [58]

Answer: Navigation

Explanation:

the Navigation pane

3 0
2 years ago
Other questions:
  • What are rules that we use on the internet called, and what are some of them?
    6·1 answer
  • VW discovered that its engineers had developed a software program that allowed some of its car models to run without emissions c
    14·2 answers
  • Whats the difference between copying a file to my desktop and creating a shortcut?
    8·1 answer
  • What is the name of the interface that uses graphics as compared to a command-driven interface?
    11·1 answer
  • What are the different ways to represent compounds? Check all that apply. a structural formula a ball model a space-filling mode
    13·2 answers
  • What are the answers to 14 and 15
    10·1 answer
  • HTML and CSS are computer languages used to create what?
    11·1 answer
  • একটা ছবি কতটি কথার সমান?
    6·1 answer
  • Discuss why it is important to know the history of social media​
    10·1 answer
  • A data in database can be presented in _____ format​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!