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

Jsp, how can we get the data from data base to combo box in jsp page dynami...

how can we get the data from data base to combo box in jsp page dynamically

Program for simulate part of the game of yahtzee, This assignment will make...

This assignment will make use of arrays and functions to simulate a game. ASSIGNMENT DESCRIPTION This program will simulate part of the game of Yahtzee! The player will

Shopping Cart, Shopping Cart Purpose – Allows user to browse while keeping ...

Shopping Cart Purpose – Allows user to browse while keeping track of the items in which they will purchase at the end on the order page link and this will give a final price for al

MATLAB, Who can help with MATLAB?

Who can help with MATLAB?

What is .net?, What is .NET? It is a foundation fairly neutral structure...

What is .NET? It is a foundation fairly neutral structure. Is a coating between the son and the selection language? It can handle many selection dialects, such as VB.NET,

Program for a single new-line character, The following function calls suppo...

The following function calls supposedly write a single new-line character, but some are incorrect. Identify which calls don't work and explain why.     printf("%c", '\n');

Oop, Using OOP,write a sample program to get the factorial of a number ente...

Using OOP,write a sample program to get the factorial of a number entered by a user

Overview of procedure-oriented programming paradigm, Procedure-oriented pro...

Procedure-oriented programming (POP):- This is a top-down programming approach, where the problem is viewed as a sequence of tasks to be done such as calculating, printing etc. A n

What are the characteristics of a good algorithm, What is an algorithm? Wha...

What is an algorithm? What are the characteristics of a good algorithm? An algorithm is defined as “a step-by-step procedure of accomplishing some task'''' An algorithm may be sh

Program to finds central individuals in arbitrary networks, Identifying the...

Identifying the Central Individual in a Social Network 1. Introduction You have just been hired by a social networking company! The division you are working in is particul

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