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

program design in C Please answer parts B and C from the following question: Pro

ID: 645412 • Letter: P

Question

program design in C

Please answer parts B and C from the following question:

Program Design Exam 3 Practice Questions 3. (a) Write a typed ef for a struct with two members, re and im, that can be used as the representation of a complex number with nonnegative integer real and imaginary parts. Your type should be named Complex integer. (b) Complete the code to input a Complex lnt. For example, if the user enters 5+201, the function returns the Complex object representing that number. The user s required to enter an expression n the format shown above. For example, the user might enter any of the following: Do not do input validation. (c) Write the code for the print Complex lnt function that prints the string representing the Complex argument. Only print as much data a necessary the only time a O should appear n your output should be when both the real and imaginary parts are O, and in that case your output should be one zero. Thus, you should not have output like 1 +01 or 0 + 2i or 0 + 01.

Explanation / Answer

#include<stdio.h>

#include<conio.h>

#include<ctype.h>


typedef struct

{

int re;

int im;

}ComplexInt;


void printComplexInt(ComplexInt *z)

{

if(z->re==0 && z->im==0)

printf("Invalid String");

else

printf("%d + %d i",z->re,z->im);

}



void get_complexint(ComplexInt *z)

{

char c[10];

char r[5],im[5];

int i,k,j,l,len,m,n=0,b;

clrscr();

printf("Enter the complex no:");

scanf("%s",&c);


len=strlen(c);


for(i=0;i<len;i++)

{

if(c[i]=='+')

{

for(j=0;j<i;j++)

r[j]=c[j];

l=i;

}



if(c[i]=='i')

m=i;

}



for(k=l+1;k<m;k++,n++)

{

if(k==n)

{

im[n]=c[k];

break;

}

else

im[n]=c[k];

}


z->re=atoi(r);

z->im=atoi(im);


}


void main()

{


struct CompexInt *y;


get_complexint(y);

printComplexInt(y);


getch();

}