Create a class called Complexno for performing arithmetic with complex numbers in C++. The definition of the class is split into two files. complexno.h : Contains the declaration of the Complex class, you need to add some methods as asked below. complexno.cpp  : Contains definitions of the functions belonging to class Complexno, you need to finish all the definitions of the class members. The ADT class uses double variables to represent the private data of the class—the real component and the complex component of a complex number. provides constructors that enable an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. provides public member functions for each of the following: Addition of two complex numbers. See the solution as an example below. Subtraction of two complex numbers. Multiplication of two complex numbers. Negation of a complex number. Computes and returns the magnitude of a complex number. Read a complex number from the user Prints out a complex number in a readable format. The third file calls the driver Assign3Driver.cpp  Download Assign3Driver.cpp: Contains main() function that uses the Complexno class. To compile this program, all three files need to be put together under the same directory or folder of the project. Note: 1. You are asked to complete the skeleton codes in two files: the interface complexno.h  Download complexno.hand the implementation complexno.cpp  Download complexno.cpp. 2. You use this driver program (do not change it!) to test your class: Assign3Driver.cpp  Download Assign3Driver.cpp. Please copy and paste your sample run as comments at the end of this driver Need help with skelton codes, lost on what to do. complex.cpp // Adds two complex numbers and returns the answer. Complexno Complexno::add(const Complexno& num2) { Complexno answer; answer.real = real + num2.real; answer.complex = complex + num2.complex; return answer; } // (2) --------------------------------- subtract------------------ // Define sub to subtracts two complex numbers and returns the answer. Complexno Complexno::sub(const Complexno& num2) { /* add your codes */ } // (3) --------------------------------- Multiply------------------ // Multiplies two complex numbers and returns this answer. Complexno Complexno::mult(const Complexno& num2) { /* add your codes */ } // Negates a complex number. Complexno Complexno::negate() { Complexno answer; answer.real = -real; answer.complex = -complex; return answer; } // (4) --------------------------------- Magnitude ------------------ // Computes and returns the magnitude of a complex number. double Complexno::magnitude() { /* add your codes */ } // (5) --------------------------------- Print ------------------ // Prints out a complex number in a readable format. void Complexno::shownum() { /* add your codes */ } complex.h #ifndef COMPLEX_H #define COMPLEX_H #include #include using namespace std; class Complexno { public : Complexno(); // Default constructor Complexno(double r); // Second constructor - creates a complex number of equal value to a real. Complexno(double r, double c); // (1) Standard constructor - sets both of the real and complex // components based on parameters. Complexno add(const Complexno& num2); // Adds two complex numbers and returns the answer.    /* Your codes to add the prototypes of required methods here.    (2) Subtracts two complex numbers and returns the answer. (3) Multiplies two complex numbers and returns this answer. (4) Computes and returns the magnitude of a complex number. (5) Prints out a complex number in a readable format. */    Complexno negate(); // Negates a complex number. void enternum(); // Reads in a complex number from the user.    private : double real; // Stores real component of complex number double complex; // Stores complex component of complex number }; // Displays the answer to a complex number operation. void display(Complexno, Complexno, Complexno, char); #endif

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

Create a class called Complexno for performing arithmetic with complex numbers in C++.

The definition of the class is split into two files.

complexno.h : Contains the declaration of the Complex class, you need to add some methods as asked below.

complexno.cpp  : Contains definitions of the functions belonging to class Complexno, you need to finish all the definitions of the class members.

The ADT class

  • uses double variables to represent the private data of the class—the real component and the complex component of a complex number.
  • provides constructors that enable an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided.
  • provides public member functions for each of the following:
    • Addition of two complex numbers. See the solution as an example below.
    • Subtraction of two complex numbers.
    • Multiplication of two complex numbers.
    • Negation of a complex number.
    • Computes and returns the magnitude of a complex number.
    • Read a complex number from the user
    • Prints out a complex number in a readable format.

The third file calls the driver Assign3Driver.cpp  Download Assign3Driver.cpp: Contains main() function that uses the Complexno class. To compile this program, all three files need to be put together under the same directory or folder of the project.

Note:

1. You are asked to complete the skeleton codes in two files: the interface complexno.h  Download complexno.hand the implementation complexno.cpp  Download complexno.cpp.

2. You use this driver program (do not change it!) to test your class: Assign3Driver.cpp  Download Assign3Driver.cpp. Please copy and paste your sample run as comments at the end of this driver

Need help with skelton codes, lost on what to do.

complex.cpp

// Adds two complex numbers and returns the answer.
Complexno Complexno::add(const Complexno& num2) {
Complexno answer;
answer.real = real + num2.real;
answer.complex = complex + num2.complex;
return answer;
}
// (2) --------------------------------- subtract------------------
// Define sub to subtracts two complex numbers and returns the answer.
Complexno Complexno::sub(const Complexno& num2) {
/*
add your codes
*/
}
// (3) --------------------------------- Multiply------------------
// Multiplies two complex numbers and returns this answer.
Complexno Complexno::mult(const Complexno& num2) {
/*
add your codes
*/
}
// Negates a complex number.
Complexno Complexno::negate() {
Complexno answer;
answer.real = -real;
answer.complex = -complex;
return answer;
}
// (4) --------------------------------- Magnitude ------------------
// Computes and returns the magnitude of a complex number.
double Complexno::magnitude() {
/*
add your codes
*/
}
// (5) --------------------------------- Print ------------------
// Prints out a complex number in a readable format.
void Complexno::shownum() {
/*
add your codes
*/
}

complex.h

#ifndef COMPLEX_H
#define COMPLEX_H
#include <iostream>
#include <cmath>
using namespace std;
class Complexno {
public :
Complexno(); // Default constructor
Complexno(double r); // Second constructor - creates a complex number of equal
value to a real.
Complexno(double r, double c); // (1) Standard constructor - sets both of the
real and complex
// components based on parameters.
Complexno add(const Complexno& num2); // Adds two complex numbers and returns
the answer.
  
/* Your codes to add the prototypes of required methods here.
  
(2) Subtracts two complex numbers and returns the answer.
(3) Multiplies two complex numbers and returns this answer.
(4) Computes and returns the magnitude of a complex number.
(5) Prints out a complex number in a readable format.
*/
  
Complexno negate(); // Negates a complex number.
void enternum(); // Reads in a complex number from the user.
  
private :
double real; // Stores real component of complex number
double complex; // Stores complex component of complex number
};
// Displays the answer to a complex number operation.
void display(Complexno, Complexno, Complexno, char);
#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Data members
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