Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a) Show how to declare a tag named complex for a structure with two members, rea

ID: 3614661 • Letter: A

Question

a) Show how to declare a tag namedcomplex for a structure with two members,real andimaginary, of type double. b) Use the complex tag to declarevariables named c1,c2 and c3. c) Write a function namedmake_complex that stores its twoarguments (both of type double) in acomplex structure, then returns thestructure. d) Write a function namedadd_complex that adds the correspondingnumbers of its arguments (both complexstructures), then returns the result (anothercomplex structure) a) Show how to declare a tag namedcomplex for a structure with two members,real andimaginary, of type double. b) Use the complex tag to declarevariables named c1,c2 and c3. c) Write a function namedmake_complex that stores its twoarguments (both of type double) in acomplex structure, then returns thestructure. d) Write a function namedadd_complex that adds the correspondingnumbers of its arguments (both complexstructures), then returns the result (anothercomplex structure) c) Write a function namedmake_complex that stores its twoarguments (both of type double) in acomplex structure, then returns thestructure. d) Write a function namedadd_complex that adds the correspondingnumbers of its arguments (both complexstructures), then returns the result (anothercomplex structure)

Explanation / Answer

#include<iostream>
using namespace std;
struct complex
{
double real,imag;
}c1,c2,c3;              //1

struct complexmake_complex(double real,doubleimag)         //2
{
struct complex c;
c.real = real;
c.imag = imag;
return c;
}

struct complexadd_complex(struct complex c2,struct complexc3)     //3
{
struct complex c;
c.real = c2.real + c3.real;
c.imag = c2.imag + c3.imag;
return c;
}
int main()
{
    c2=make_complex(2,3);
    c3=make_complex(4,5);
    c1 = add_complex(c2,c3);
    cout<<"Added value are:"<<c1.real<<" + "<<c1.imag<<" i"<<endl;
    system("pause");
}