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...

  • Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and...

    Create a ComplexNo class for two imaginary numbers. Provide (in addition to add, subtract, multiply, and divide methods) a method for equals (which returns boolean), and toString( ) method (that returns a string representing the receiving object). Throw an exception if an attempt is made to divide by 0 (0 + 0i). Your implementation should return the results of each operation WITHOUT changing the operands. Exxample: Enter the first complex number's real part => 1.0 Enter the first complex number's...

  • 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...

  • C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex...

    C++ CLASS FOR DEFINING COMPLEX NUMBERS (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √ −1. You should represent a complex number here as two values of type double. You should name the variables real and imaginary. You can call the...

  • 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...

  • 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 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...

  • USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write...

    USING C++, write a simple class defining complex numbers USING the FRIEND function (READ BELOW) Write a C++ defining a class for complex numbers. A complex number is a number of the form: a + b ∗ i , where, for our purposes, a and b are numbers of type double, and i is a number that represents the quantity √−1. You should represent a complex number here as two values of type double. You should name the variables real...

  • 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;   ...

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