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
You will design and implement a program that will • analyse the various characteristics of a maze, represented by a particular coding of its basic con- stituents into numbers store

depth estimation from block matching algorithm motion estimation

C++ language introduces object-oriented programming (OOP) features to C language. It offers classes, which provide the four features commonly present in OOP (or some non-OOP) langu

Write a Program to Show Twenty Ellipses 1. Write a program to show twenty ellipses which move away from the mouse pointer. Their initial locations should be random.

how do I change a existing formula with a new formula and it show the result

WRITE A FORTRAN PROGRAMME TO GENERATE PRIME NUMBERS BETWEEN 1 AND 100.

showing work Ubuntu system or either opensuse

The aims of this assignment are to:    Provide experience in the use of a modern Integrated Development Environment (specifically NetBeans running on a Linux platform) for t

how to rewrite C++ program the DNAStrand class (DNA Project) to instead store the nucleotide sequence in a dynamically-allocated array?

I need to finish my game project within two weeks using XNA. Would you guys can help me to finish it? Thank you