Problem 60

# Problem 60 - The [-] indicates that the negative sign is...

This preview shows page 1. Sign up to view the full content.

ECOR1606 Problem Solving and Computers Page 1 of 1 Department of Systems and Computer Engineering, Carleton University Summer 2003 Assignment – Imaginary numbers This program has the ability to add, subtract, and multiply two imaginary numbers. Define a structure for the imaginary number: struct Imag_num { double real_part; double imag_part; }; Write three functions in your program, which add, subtract, and multiply imaginary numbers, respectively: Imag_num add(Imag_num x, Imag_num y); Imag_num sub(Imag_num x, Imag_num y); Imag_num mult(Imag_num x, Imag_num y); The program behaves by accepting an equation for imaginary numbers which follows the format: [-]<number> [+/-] <number>i <operation> [-]<number> [+/-] <number>i
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The [-] indicates that the negative sign is optional, and the [+/-] indicates that there is either a plus or minus sign. The parameters &lt;number&gt; are a floating point number and &lt;operation&gt; is a plus, minus, or multiplication sign. See the sample output below for further clarification. Note that your program does not need to take care of inputs that do not conform to the accepted format. Sample Output Enter an imaginary equation: -1.23 + 4.56i + 2.34 - 5.67i z = 1.11 + -1.11i Continue (Y/N)Y Enter an imaginary equation: 1.23 - 4.56i - 2.34 + 5.67i z = -1.11 + -10.23i Continue (Y/N)Y Enter an imaginary equation: 1.2 - 4.5i * 2.3 + 3.4i z = 18.06 + -6.27i Continue (Y/N)n...
View Full Document

Ask a homework question - tutors are online