A complex number has two parts: real value and imaginary value. In mathematics, we learnt how to add and multiply two complex numbers. Write a class Complex which will have two fields for real and imaginary values. The constructor will set the values in these fields (there could be multiple overloaded constructors). The class should also have method like this: Complex add (Complex c) This add() method takes a complex object and return a new complex object after adding the complex number c with itself(Use general complex number addition rule).

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 6SA
icon
Related questions
Question

A complex number has two parts: real value and imaginary value. In mathematics, we
learnt how to add and multiply two complex numbers. Write a class Complex which will
have two fields for real and imaginary values. The constructor will set the values in these
fields (there could be multiple overloaded constructors). The class should also have
method like this:
Complex add (Complex c)
This add() method takes a complex object and return a new complex object after adding
the complex number c with itself(Use general complex number addition rule). 

6.
Which of the below code contains correct overloading code? Why would the other won't
work?
Code 1
double myMultiply. (int x){
return 10 x;
Code 2
int awMultielx (int x){
return 10 x;
}
double yMultirly. (double x){ double yMultiely (int x){
return 20 x;
return 2e * x;
7.
What would be the output for the following program and why ( explain in short):
Bublis static void nain(String acsal))(
String.";
String si - "Testing Java Program
String s2 - sukstriui13);
8.
Write the code in Java for the following class from the UML diagram below:
Vehicle
-passengers: int
-maxSpeed: double
-color: String
+Vehiclelint,double.String)
+setColor(): void
+getColor(): String
+findCaracityl): double
The findCapacityl) method return the capacity of the vehicle by the following formula:
Capacity = passengers * 75 L0.20 * maxSpeed)
Transcribed Image Text:6. Which of the below code contains correct overloading code? Why would the other won't work? Code 1 double myMultiply. (int x){ return 10 x; Code 2 int awMultielx (int x){ return 10 x; } double yMultirly. (double x){ double yMultiely (int x){ return 20 x; return 2e * x; 7. What would be the output for the following program and why ( explain in short): Bublis static void nain(String acsal))( String."; String si - "Testing Java Program String s2 - sukstriui13); 8. Write the code in Java for the following class from the UML diagram below: Vehicle -passengers: int -maxSpeed: double -color: String +Vehiclelint,double.String) +setColor(): void +getColor(): String +findCaracityl): double The findCapacityl) method return the capacity of the vehicle by the following formula: Capacity = passengers * 75 L0.20 * maxSpeed)
Write a class 'Box' which has three private members height, width and depth; To set values
and use these members, write mutator(setter) and accessor(getter) functions for these
members. (Hint: there would be 3 Accessor and 3 Mutator functions). Also write a
constructor function that takes 3 parameters to initialize these fileld members.
9.
10. Write a class for 'LabRoom'; it will have member fields for no of chairs, no of tables, no of
computers. The class should also contain methods to add or remove these elements: the
amount to be added or removed should be given as parameter. There should be 2
overloaded add methods: one taking 3 parameters and the other taking no parameters
(write the body of the methods as per your wish). Now, Create 2 LabRoom objects with
arbitrary values and call and use the add() and remove() methods.
11. A complex number has two parts: real value and imaginary value. In mathematics, we learnt
how to add and multiply two complex numbers. Write a class Complex which will have two
fields for real and imaginary values. The constructor will set the values in these fields (there
could be multiple overloaded constructors). The class should also have method like this:
Complex add (Complex c)
This add() method takes a complex object and return a new complex object after adding the
complex number c with itself(Use general complex number addition rule).
12. Suppose a String name is given in a format where the firstname and lastname are separated
by a semicolon like 'Zigul;Hossain' ; the general format would be 'firstname;lastname
(firstname and lastname can be any String). Write a program which will separate the
lastname into a different string. (Hint: use a function from String class to find the positionte V
of semicolon and then take substring from that position).
Go to Setting
Transcribed Image Text:Write a class 'Box' which has three private members height, width and depth; To set values and use these members, write mutator(setter) and accessor(getter) functions for these members. (Hint: there would be 3 Accessor and 3 Mutator functions). Also write a constructor function that takes 3 parameters to initialize these fileld members. 9. 10. Write a class for 'LabRoom'; it will have member fields for no of chairs, no of tables, no of computers. The class should also contain methods to add or remove these elements: the amount to be added or removed should be given as parameter. There should be 2 overloaded add methods: one taking 3 parameters and the other taking no parameters (write the body of the methods as per your wish). Now, Create 2 LabRoom objects with arbitrary values and call and use the add() and remove() methods. 11. A complex number has two parts: real value and imaginary value. In mathematics, we learnt how to add and multiply two complex numbers. Write a class Complex which will have two fields for real and imaginary values. The constructor will set the values in these fields (there could be multiple overloaded constructors). The class should also have method like this: Complex add (Complex c) This add() method takes a complex object and return a new complex object after adding the complex number c with itself(Use general complex number addition rule). 12. Suppose a String name is given in a format where the firstname and lastname are separated by a semicolon like 'Zigul;Hossain' ; the general format would be 'firstname;lastname (firstname and lastname can be any String). Write a program which will separate the lastname into a different string. (Hint: use a function from String class to find the positionte V of semicolon and then take substring from that position). Go to Setting
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Developing computer interface
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++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning