Please write your original code in c++ Thank you   Objective Create a class named Complex to represent complex numbers. Use the main() function and create at least three complex number objects and test all member functions of the Complex class. How to use classes. Related SLO Develop properly structured multifile programs with automatic compilation. Use classes in C++. Instructions Create a program named LastnameFirstname18.cpp, that does the following: Note: This program has no user input. Define a class called Complex that will represent a complex number. Complex numbers have the form a + bi, where a is the real part and b is the imaginary part. Both the a and b coefficients are real numbers. i is the square root of negative one, but it's not actually implemented in code. For this assignment, you will only be working with a and b. Wikipedia page for Complex numbers: here Declare 2 private double data members: real and imaginary Define one default constructor that initializes real and imaginary to 0. Note: A default constructor is a constructor with no parameters. Define a member function called print that uses cout to print the complex number in the format (a + bi) followed by a newline. This function has no parameters. Include the parenthesis symbols in the print out. If the imaginary part is negative (less than 0), print in the format (a - bi) followed by a newline. For example, if real is 6 and imaginary is -3, the output should look like this: (6 - 3i) It should not look like (6 - -3i) or (6 -3i) or (6-3i) Define a member function called set that sets both the real and imaginary data members. This function has 2 double parameters, one for each data member. Assign the real and imaginary data members respectively. Define two get functions, one for each data member, getReal() and getImaginary() that returns its respective data member. Any member function that does not inheritely modify the data members are defined with the const keyword to prevent data members from being modified in the function. For example, the print function does not modify the data members, so the header of the print should look like this: void print() const { Use my main() to test the your member functions: https://laulima.hawaii.edu/x/8s55cE There should be no errors present. If the spacing is off, then you may be missing a newline at the end of your print() function. Be sure to have a program description at the top and in-line comments. Be clear with your comments and output to the user, so I can understand what the program is doing. Comments are not required in main() if you used the provided one. See the commented version of the functions.cpp to see how to comment your member functions. Be sure to have read through the assignment policy for this class.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please write your original code in c++ Thank you

 

  • Objective
    • Create a class named Complex to represent complex numbers. Use the main() function and create at least three complex number objects and test all member functions of the Complex class.
    • How to use classes.
  • Related SLO
    • Develop properly structured multifile programs with automatic compilation.
    • Use classes in C++.
  • Instructions
    1. Create a program named LastnameFirstname18.cpp, that does the following:
    2. Note: This program has no user input.
    3. Define a class called Complex that will represent a complex number.
      • Complex numbers have the form a + bi, where a is the real part and b is the imaginary part. Both the a and b coefficients are real numbers. i is the square root of negative one, but it's not actually implemented in code. For this assignment, you will only be working with a and b.
      • Wikipedia page for Complex numbers: here
    4. Declare 2 private double data members: real and imaginary
    5. Define one default constructor that initializes real and imaginary to 0.
      • Note: A default constructor is a constructor with no parameters.
    6. Define a member function called print that uses cout to print the complex number in the format (a + bi) followed by a newline.
      • This function has no parameters.
      • Include the parenthesis symbols in the print out.
      • If the imaginary part is negative (less than 0), print in the format (a - bi) followed by a newline.
        • For example, if real is 6 and imaginary is -3, the output should look like this: (6 - 3i)
        • It should not look like (6 - -3i) or (6 -3i) or (6-3i)
    7. Define a member function called set that sets both the real and imaginary data members.
      • This function has 2 double parameters, one for each data member.
      • Assign the real and imaginary data members respectively.
    8. Define two get functions, one for each data member, getReal() and getImaginary() that returns its respective data member.
    9. Any member function that does not inheritely modify the data members are defined with the const keyword to prevent data members from being modified in the function.
      • For example, the print function does not modify the data members, so the header of the print should look like this:
        void print() const {
    10. Use my main() to test the your member functions: https://laulima.hawaii.edu/x/8s55cE
      There should be no errors present. If the spacing is off, then you may be missing a newline at the end of your print() function.
    11. Be sure to have a program description at the top and in-line comments.
      • Be clear with your comments and output to the user, so I can understand what the program is doing.
      • Comments are not required in main() if you used the provided one.
      • See the commented version of the functions.cpp to see how to comment your member functions.
      • Be sure to have read through the assignment policy for this class.
  •  
### Example Output

```
% make
% ./program
Test the constructor.
Complex number complex1 is: (0 + 0i)

Test the one set() function.
Complex number complex2 is: (3.3 - 4.4i)

Test the two get() functions.
Complex number complex3's real part is: 5.5
Complex number complex3's imaginary part is: 6.6
```

### Notes

- **What goes in the public block:**
  - Constructor, getters, setter, and print function
- **What goes in the private block:**
  - Declaration of data members
- **Examples of classes from the lecture:**
  - `fraction.cpp` and `functions.cpp`
Transcribed Image Text:### Example Output ``` % make % ./program Test the constructor. Complex number complex1 is: (0 + 0i) Test the one set() function. Complex number complex2 is: (3.3 - 4.4i) Test the two get() functions. Complex number complex3's real part is: 5.5 Complex number complex3's imaginary part is: 6.6 ``` ### Notes - **What goes in the public block:** - Constructor, getters, setter, and print function - **What goes in the private block:** - Declaration of data members - **Examples of classes from the lecture:** - `fraction.cpp` and `functions.cpp`
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in 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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education