Question

Complete the functions for the program complex.c (Down) . The program adds, subtracts,and multiplies complex numbers....

Complete the functions for the program complex.c (Down) . The program adds, subtracts,and multiplies complex numbers. The C program will prompt the user for the choice of operations,read in the complex numbers, perform the operations, and print the results. The main programrepeatedly prints the menu, reads in the user’s selection, and performs the operation. We use pointers only for those arguments that the function intends to change. In all thefunctions, r represents the real component and i represents the imaginary component. Studythe program and complete the following functions. Do not modify the function prototypes. 1) Complete the function that reads in two complex numbers. void read_nums(double *r1, double *i1, double *r2, double *i2); The function should prompt for the user to enter the real component and imaginarycomponent of the first number and the second number and store the values in the variablespointed by r1, i1, r2, i2, respectively. 2) Complete the following functions that calculate the addition, subtraction, and multiplicationof two complex numbers. The functions take real component and imaginary component ofthe first number and the second number and store the values in the variables pointed by r3 and i3, respectively. #include void read_numbers(double *r1, double *i1, double *r2, double *i2); void add(double r1, double i1, double r2, double i2, double *r3, double *i3); void subtract(double r1, double i1, double r2, double i2, double *r3, double *i3); void multiply(double r1, double i1, double r2, double i2, double *r3, double *i3); void print_complex(double r3, double i3); int main(void) { double r1, r2, r3, i1, i2, i3; int option; printf("Complex Number Arithmetic Program: \n\n"); for(;;) { printf("1. Add two complex numbers\n"); printf("2. Subtract two complex numbers\n"); printf("3. Multiply two complex numbers\n"); printf("4. Quit\n\n"); printf("Choose an option (1 - 4): "); scanf("%d", &option); switch(option){ case 1: read_numbers(&r1, &i1, &r2, &i2); add(r1, i1, r2, i2, &r3, &i3); print_complex(r3, i3); break; case 2: read_numbers(&r1, &i1, &r2, &i2); subtract(r1, i1, r2, i2, &r3, &i3); print_complex(r3, i3); break; case 3: read_numbers(&r1, &i1, &r2, &i2); multiply(r1, i1, r2, i2, &r3, &i3); print_complex(r3, i3); break; case 4: return 0; default: printf("Invalid option. Choose an option (1-4):\n"); } } return 0; } void read_numbers(double *r1, double *i1, double *r2, double *i2) { //add your code here } void add(double r1, double i1, double r2, double i2, double *r3, double *i3) { //add your code here } void subtract(double r1, double i1, double r2, double i2, double *r3, double *i3) { //add your code here } void multiply(double r1, double i1, double r2, double i2, double *r3, double *i3) { //add your code here } void print_complex(double r3, double i3) { if(i3 >= 0) printf("The operation yields %.3f + %.3fi\n\n", r3, i3); else printf("The operation yields %.3f %.3fi\n\n", r3, i3); }

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Complete the functions for the program complex.c (Down) . The program adds, subtracts,and multiplies complex numbers....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Please, I need help, I cannot figure out how to scan variables in to the function...

    Please, I need help, I cannot figure out how to scan variables in to the function prototypes! ******This is what the program should look like as it runs but I cannot figure out how to successfully build the code to do such.****** My code: #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> #include <conio.h> float computeSeriesResistance(float R1, float R2, float R3); float computeParallelResistance(float R1, float R2, float R3); float computeVoltage(int current, float resistance); void getInputR(float R1, float R2, float R3); void getInputCandR(int...

  • need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re,...

    need the code in .c format #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <math.h> struct _cplx double re, im; // the real and imaginary parts of a complex number }; typedef struct _cplx Complex; // Initializes a complex number from two real numbers Complex CmplxInit(double re, double im) Complex z = { re, im }; return z; // Prints a complex number to the screen void CmplxPrint(Complex z) // Not printing a newline allows this to be printed in the middle of...

  • The main method of your calculator program has started to get a little messy. In this...

    The main method of your calculator program has started to get a little messy. In this assignment, you will clean it up some by moving some of your code into new methods. Methods allow you to organize your code, avoid repetition, and make aspects of your code easier to modify. While the calculator program is very simple, this assignment attempts to show you how larger, real world programs are structured. As a new programmer in a job, you will likely...

  • Create a class for working with complex numbers. Only 2 private float members are needed, the...

    Create a class for working with complex numbers. Only 2 private float members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class: a. A default constructor that uses default arguments in case no initializers are included in the main. b. Add two complex numbers and store the sum. c. Subtract two complex numbers and store the difference. d. Multiply two complex numbers and store...

  • Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form:...

    Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form: realPart + imaginaryPart * i where i is √-1 Use double variables to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should contain default values of (1,1) i.e. 1 for the real part and 1 for the imaginary part. Provide public member functions that perform the following...

  • Could someone re-write this code so that it first prompts the user to choose an option...

    Could someone re-write this code so that it first prompts the user to choose an option from the calculator (and catches if they enter a string), then prompts user to enter the values, and then shows the answer. Also, could the method for the division be rewritten to catch if the denominator is zero. I have the bulk of the code. I am just having trouble rearranging things. ------ import java.util.*; abstract class CalculatorNumVals { int num1,num2; CalculatorNumVals(int value1,int value2)...

  • SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1...

    SEE THE Q3 for actual question, The first Two are Q1 and Q2 answers . Q1 #include<iostream> using namespace std; // add function that add two numbers void add(){    int num1,num2;    cout << "Enter two numbers "<< endl;    cout << "First :";    cin >> num1;    cout << "Second :";    cin >>num2;    int result=num1+num2;    cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;   ...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • Please provide source code, make a program that follows everything on this doc. te a complete...

    Please provide source code, make a program that follows everything on this doc. te a complete program that accomplishes the following tasks Wri Display a friendly greeting to the user Prompt the user for a complex number, call it a. Accept that complex number using cin. Display that complex number using cout. Prompt the user for a complex number, call it b Accept that complex number using cin. Display that complex number using cout. Display a line of code that...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT