A) Write a program to print the sum of two complex numbers by creating a class named as "ComplexNumbers' containing two data members, real and imaginary and two functions. First function named as 'plus' adds the given two complex numbers and updates the first complex number with the result and the second function named as 'print' prints the given sum in the format 'a + ib' where a is the real part and b is the imaginary part. Take the real and imaginary parts of both the complex numbers as input from scanner and consider them to be positive integers. Input Format : Line 1: Two integers- real and imaginary part of 1st complex number Line 2: Two integers- real and imaginary part of 2nd complex number Sample Input : 45 (write program in java) 67 Sample Output : 10 + il2

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter12: Adding Functionality To Your Classes
Section12.3: Class Scope And Duration Categories
Problem 4E
icon
Related questions
Question
A) Write a program to print the sum of two complex numbers by creating a class named as
"ComplexNumbers' containing two data members, real and imaginary and two functions. First
function named as 'plus' adds the given two complex numbers and updates the first complex
number with the result and the second function named as 'print' prints the given sum in the format
'a + ib' where a is the real part and b is the imaginary part. Take the real and imaginary parts of
both the complex numbers as input from scanner and consider them to be positive integers.
Input Format :
Line 1: Two integers- real and imaginary part of 1 complex number
Line 2: Two integers- real and imaginary part of 2nd complex number
Sample Input :
45
67
(write program in
java)
Sample Output :
10 + il2
Transcribed Image Text:A) Write a program to print the sum of two complex numbers by creating a class named as "ComplexNumbers' containing two data members, real and imaginary and two functions. First function named as 'plus' adds the given two complex numbers and updates the first complex number with the result and the second function named as 'print' prints the given sum in the format 'a + ib' where a is the real part and b is the imaginary part. Take the real and imaginary parts of both the complex numbers as input from scanner and consider them to be positive integers. Input Format : Line 1: Two integers- real and imaginary part of 1 complex number Line 2: Two integers- real and imaginary part of 2nd complex number Sample Input : 45 67 (write program in java) Sample Output : 10 + il2
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning