Write a program to perform an arithmetic operation, Programming Languages

Write a program (calculation.ccp) to allow the user to perform an arithmetic operation on the two complex numbers entered.  The user can key in one of the four operations: addition (+), subtraction (-), multiplication (*) and division (/).  Overload the operators to meet the requirements as stated below.    

To sum two complex numbers, you have to sum the real and imaginary parts separately.

E.g. (4 + 5i) + (3 + 2i) = (4+3) + (5+2)i  = 7 + 7i.

To subtract one complex number from another, you have to subtract the real and imaginary parts separately. 
E.g. (4 + 5i) - (3 + 2i) = (4-3) + (5-2)i = 1 + 3i .

To multiply two complex numbers, please use the following formula.

(a + bi) x (c + di) = ac + adi + bci - bd = (ac - bd) + (ad + bc)i

E.g. (4 + 5i) * (3 + 2i) = (12-10) + (8 + 15)i = 2 + 23i

To divide one complex number with another complex number, multiply the numerator and the denominator by the conjugate of the denominator. 

(a + bi) / (c + di) = [(a + bi) * (c - di)] / [(c + di) * (c - di)]

E.g. (4 + 5i) / (3 + 2i) = [(4 + 5i) * (3 - 2i)] / [(3 + 2i) * (3 - 2i)] = (12 + 7i + 10) / (9+4)

                                                                                                   = (22 + 7i) / 13

Your program shall perform the following:

1. Prompt user to enter the first number, an operator and the second number. The program should print out the result of the operation.

2. The program shall catch multiple exceptions by implementing try and catch blocks

3. The program should be able to tackle the following exceptions:

a.  If the user types an invalid operator, the program should be able to detect that and the catch block should be able to display a message: an invalid operator.

b. If the user types in an invalid number (i.e. anything apart from a character from 0 to 9), the program should throw an error and the catch block should be able to display a message: an invalid numeric number.

c. If the user enters a forward slash ''/" to perform a division, the program should check to see if the second number is a 0.  The denominator should not be a 0.  If it is, the program presents a throw that sends a complex number.  The program will implement another catch that takes the complex number as an argument.  It will display a message: division by 0 is not allowed. 

4. The program requires you to test the overloading operators to check if you get the same output as given by the examples above.

Posted Date: 2/27/2013 2:41:14 AM | Location : United States







Related Discussions:- Write a program to perform an arithmetic operation, Assignment Help, Ask Question on Write a program to perform an arithmetic operation, Get Answer, Expert's Help, Write a program to perform an arithmetic operation Discussions

Write discussion on Write a program to perform an arithmetic operation
Your posts are moderated
Related Questions
I need help with this question. The problem i''m having is that what''s the syntax for using dynamic memory allocation of objects of one class in the constructor of some other clas

The Lost Bay Software Coop purchased EnviroMeasurements, a small startup with a product, GreenStation, that measures pollen count and air quality. The company has ventured

what is a microprocessor? types of microprocessors? advantages disadvantages

I have to create a calorie counter and I am totally lost

Hi, Can you do exercises: D2, D3, D4, and D5 on page 230 of the following book: http://www.daimi.au.dk/~bra8130/Wiley_book/wiley.html . The book can be downloaded for free from t

A manager at the local Walmart needs to determine how many workers to hire to cover a 24-hour period. Each worker must work 9 consecutive hours but may only start work at the begin

The program presents mainframe contains two button new user, existing user PART ONE: CLICKING ON NEW USER New window appear contains: text field represent username,

Create a Money data structure that is made up of amount and currency.  (a) Write a constructor for this data structure   (b)  Create accessors for this data structure (c)

The assignment has two parts: first you generate a simple application for a MID that operates independently of other MIDs. As a second part, the application is extended to keep so

My kinect hand cursor only works for main menu but when it goes to another page it wouldn''t work.. especially when there is for camera feed