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
COS-101: INTRODUCTION TO COMPUTERS PROJECT DESCRIPTION The Computer Fundamentals Project provides you with a chance to apply what you have learned about computer fundamentals to

Write a program to calculate amount after n number of years by inputting principal at the rate of 8% interest.

Develop a socket program in UNIX/Linux that uses (i) TCP as the transport protocol and  (ii) UDP as the transport protocol for transferring  a short message between a client and  s

hi, can you help me with testing java classes I have wrote using java and jsp and servlet in eclipse ? I want to use JUnit for testing

how to store an url in a dartabase(sql server 2005)? (or) create table b(url what is the datatype for url?

After studying the concept, terminology, and implementation of CSS stylesheets, create a stylesheet to accompany your solutions to Question 1. A rich collection of styles should be

In this assignment you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application. You

We now require starting looking into finding a particular solution for n th order differential equations. The two ways which we'll be looking at are similar as those which we look

Question: (a) What do you understand by the term Postback? (b) Describe five benefits of creating virtual directories while developing an ASP.NET application. (c) Exp

Calculate the total price based on several key parts required to build a state-of-the-art gaming computer. The user will have the option of selecting different parts.