Write a program to perform an arithmetic operation, Programming Languages

Assignment Help:

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.


Related Discussions:- Write a program to perform an arithmetic operation

Program 3, An apartment complex has several apartments to rent. The apartme...

An apartment complex has several apartments to rent. The apartments are all similar, and all rent for $750 per month. Currently, all units are occupied. The management, being in bu

Matlab programming, I need help with some simple matlab statements

I need help with some simple matlab statements

Write simple scripts programs , Write 3 somewhat simple scripts / programs ...

Write 3 somewhat simple scripts / programs in any language, combination of languages, and/or software. Please tell me the task you are trying to accomplish in the scripts. Idea

Algorithem for create game application, Play is as follows: 1.) Player p...

Play is as follows: 1.) Player places a bet a. Bet is on one of three choice i. "Player" will win ii. "Banker" will win iii. Tie between the "Player" and the "Banker

Program converts character array to signed decimal integer, 1. Write a func...

1. Write a function that converts a character array to a signed decimal integer. Function prototype must be as follows: int asciiToInt( char *str, unsigned char* eflag) YOU MAY NO

Shell script to count of five character words, Normal 0 false ...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Get back data from database by user as search, i have a database having fie...

i have a database having field name title and comm. I want to search by name and get the all data remaining title and comm(comm is integer)

Assignment help, Write your own version of the strcmp function string_compa...

Write your own version of the strcmp function string_compare. Supply a main program that will test each of the 3 differing outcomes. int string_compare(char *s, char *t); retu

Mobile application in android platform phones, Recent problems in finishing...

Recent problems in finishing implementation: This mobile application is built with Sencha Touch framework. Source code is attached in this zip package. The daily rest calc

Explain what is html language with an example, Explain what is HTML languag...

Explain what is HTML language with an example? HTML is the HyperText Markup Language. HTML files are text files featuring semantically tagged elements. HTML filenames are suff

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd