C++ All in same program Use cin instead of scanf Use cout instead of printf 2. l
ID: 3711607 • Letter: C
Question
C++
All in same program Use cin instead of scanf Use cout instead of printf
2. l . Create a struct called Complex to Represent complex numbers that include two pieces of information as members: Real part. (type float) and Imaginary part (type float.) . 2.2. De?ne a function called displaycomplex that displays the complex number in the ’ fomtat: x+iy. (where: x and y are real and imaginary parts, respectively)
2.2. De?ne function AddComplcx that take two Complex variables and retum their summation.
2.3, Write a C++ program (main() function )that uses struct Complex's capabilities and the de?ned functions
2.4. Create a Dynamic Array of Complex numbers (using struct Complex de?ned above) asking the user to enter its size (N) then accepts user inputs for the N complex numbers from the user then display the addition of each complex number to itself (using functions AddComplex and DisplayComplex de?ned above).
C++
All in same program Use cin instead of scanf Use cout instead of printf
2. l . Create a struct called Complex to Represent complex numbers that include two pieces of information as members: Real part. (type float) and Imaginary part (type float.) . 2.2. De?ne a function called displaycomplex that displays the complex number in the ’ fomtat: x+iy. (where: x and y are real and imaginary parts, respectively)
2.2. De?ne function AddComplcx that take two Complex variables and retum their summation.
2.3, Write a C++ program (main() function )that uses struct Complex's capabilities and the de?ned functions
2.4. Create a Dynamic Array of Complex numbers (using struct Complex de?ned above) asking the user to enter its size (N) then accepts user inputs for the N complex numbers from the user then display the addition of each complex number to itself (using functions AddComplex and DisplayComplex de?ned above).
C++
All in same program Use cin instead of scanf Use cout instead of printf
2. l . Create a struct called Complex to Represent complex numbers that include two pieces of information as members: Real part. (type float) and Imaginary part (type float.) . 2.2. De?ne a function called displaycomplex that displays the complex number in the ’ fomtat: x+iy. (where: x and y are real and imaginary parts, respectively)
2.2. De?ne function AddComplcx that take two Complex variables and retum their summation.
2.3, Write a C++ program (main() function )that uses struct Complex's capabilities and the de?ned functions
2.4. Create a Dynamic Array of Complex numbers (using struct Complex de?ned above) asking the user to enter its size (N) then accepts user inputs for the N complex numbers from the user then display the addition of each complex number to itself (using functions AddComplex and DisplayComplex de?ned above).
Explanation / Answer
#include<iostream.h>
#include<conio.h>
typedef struct
{
float x;
float y;
}complex;
void displaycomplex(complex c1)
{
cout<<c1.x<<"+i"<<c1.y<<endl;
}
complex addComplex(complex c1,complex c2)
{
complex sum;
sum.x=c1.x+c2.x;
sum.y=c1.y+c2.y;
return sum;
}
void main()
{
complex *a=NULL;
int n;
clrscr();
cout<<"enter the no of complex numbers:";
cin>>n;
a=new complex[n];
for(int i=0;i<n;i++)
{ cout<<"enter "<<i<<" complex no:"<<endl;
float dummyx,dummyy;
cout<<" enter the complex no real part:"<<endl;
cin>>dummyx;
a[i].x=dummyx;
cout<<" enter the complex no imaginary part:"<<endl;
cin>>dummyy;
a[i].y=dummyy;
}
for(int j=0;j<n;j++)
{ cout<<"sum of "<<j<<" complex numbers to it self:" ;
complex dummy=addComplex(a[j],a[j]);
displaycomplex(dummy);
cout<<" ";
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.