تم الحل ✓
categoryبرمجة وتطوير البرمجيات
schoolبكالوريوس
event_available2026-07-15
السؤال
Transcribed Image Text:
Q1- Complex numbers
The numbers that are written z = x + iy (with real x and y) form
the set of complex numbers. x is its real part and its imaginary
part.
Two complex numbers are equal if the real parts are equal and the
imaginary parts are equal. To add two complex numbers, we sum
their real parts and their imaginary parts. Likewise for subtraction.
A. Define a Complex class where each instance represents a
complex number. Such an object has members to represent its real
part and imaginary part (use double type), and the following
public methods:
1. Complex (double re, double im) and Complex () are
constructors of a complex number.
2. String toString() which returns a textual representation of the
complex in question.
3. Complex add (Complex z), Complex sub (Complex z) that
express two arithmetic operations on complex numbers.
4. boolean equal (Complex z) which makes it possible to
compare two complex numbers.
B. Add a main() method doing some basic tests for complex
numbers and their operations.
1. Create two different objects z1 and 22 with zl = 2.0 + i 7.9
and z2 = 1.5+1 9.3
2. Call the method toString() and print the result for the two
objects zl and z2.
3. Calculate z1 + 22 and save the result into a new object called
z3.
4. Call the method toString()) and print the result for the object
z3.
5. Calculate z1 - 22 and save the result into a new object called
z4.
6. Call the method toString() and print the result for the object
z4.
7. Compare 23 and 24 and print the result.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.