Related questions
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
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 4 images
- Using C++: Write a program that creates a Bus class that includes a bus ID number, number of seats, driver name, and current speed. Create a default constructor without any parameters that initializes the value of ID number, number of seats, and driver name. Create another constructor with three parameters of bus id number, number of seats, and driver name. Car speed should always be initialized as 0. The program will also include the member functions to perform the various operations: modify, set, and display bus information (Bus id, number of seats, driver name, and current speed). For example:- Set the bus id number- Set the number of seats- Set of driver number----------------------------------------------------- Return the bus id number by using get method- Return the number of seats- Return of driver number- Return the current speed-----------------------Member function to display the bus information- busInformation() Also write two member functions, Accelerate() and Brake()....arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forwardIn c++ Create a class named Restaurant that has two member objects: a Burger object, and a Fries object. In addition to this, it also has a member variable named name, to allow you to name your Restaurant. Burger has two member variables: double weight; int number_of_toppings; Fries has two member variables: string potato_type; char size; Write the code for all three classes. You will need to determine what functions are necessary to initialize all the members of the Restaurant class and write those necessary functions. Finally, you will write the code in the main that you would use to declare a Restaurant object, and set the different member variables.arrow_forward
- in c++arrow_forwardPYTHON Problem Statement Given a list of numbers (nums), for each element in nums, calculate how many numbers in the list are smaller than it. Write a function that does the calculation and returns the result (as a list). For example, if you are given [6,5,4,8], your function should return [2, 1, 0, 3] because there are two numbers less than 6, one number less than 5, zero numbers less than 4, and three numbers less than 8. Sample Input smaller_than_current([6,5,4,8]) Sample Output [2, 1, 0, 3]arrow_forwardWritten in Python with docstring please if applicable Thank youarrow_forward
- In C++ create a program that acts like a bank account. It asks the user whether to deposit or withdraw. That has 3 classes. The first class must be a generic class that holds basic info deposit, withdraw, calculate monthly interest rate, and a monthly service fee.The second class must be a savings account class that if the savings account falls below 25ドル it becomes inactive. The final class must be a checking account if someone withdraws more than what they have a service charge of 15ドル is added and go into a negative balance. The output should display the basic information how much someone deposited or withdrew and their monthly interest rate.arrow_forwardRewrite the calculator program using a class called calculator. Your program will keep asking the user if they want to perform more calculations or quit and will have a function displayMenu to display the different functions e.g .(1 - addition, 2- subtraction, 3- multiplication, 4- division) Your program must have appropriate constructors and member functions to initialize, access, and manipulate the data members as well as : A member function to perform the addition and return the result A member function to perform the subtraction and return the result A member function to perform the multiplication and return the result A member function to perform the division and return the resultarrow_forwardC++ Question Hello Please answer the attached C++ programming question correctly, just as the prompt states. Also, make sure that the code is working properly. Thank you.arrow_forward
- In C++ Please: The class and functions need to be on an .h file while the main needs to be small and on a seperate .cpp file. Create a class AccessPoint with the following attributes: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Also, add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overlap that checks if two access points overlap their coverage and returns true if they overlap. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Test...arrow_forward!! E! 4 2 You are in process of writing a class definition for the class Book. It has three data attributes: book title, book author, and book publisher. The data attributes should be private. In Python, write an initializer method that will be part of your class definition. The attributes will be initialized with parameters that are passed to the method from the main program. Note: You do not need to write the entire class definition, only the initializer method lili lilıarrow_forwardIn C++ Please: THE PROGRAM CANNOT CONTAIN -> OPERATORS! Create a class AccessPoint with the following: x - a double representing the x coordinate y - a double representing the y coordinate range - an integer representing the coverage radius status - On or Off Add constructors. The default constructor should create an access point object at position (0.0, 0.0), coverage radius 0, and Off. Add accessor and mutator functions: getX, getY, getRange, getStatus, setX, setY, setRange and setStatus. Add a set function that sets the location coordinates and the range. Add the following member functions: move and coverageArea. Add a function overLap that checks if two access points overlap their coverage and returns true if they do. Add a function signalStrength that returns the wireless signal strength as a percentage. The signal strength decreases as one moves away from the access point location. Represent this with bars like, IIIII. Each bar can represent 20% Test your class by writing a...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education