ABSOLUTE C++ -TEXT
ABSOLUTE C++ -TEXT
6th Edition
ISBN: 2810017515514
Author: SAVITCH
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 8, Problem 3PP

Define a class for complex numbers. A complex number is a number of the form

a + b * i

where for our purposes, a and b are numbers of type double, and i is a number that represents the quantity 1 . Represent a complex number as two values of type double. Name the member variables real and imaginary. (The variable for the number that is multiplied by i is the one called imaginary.) Call the class Complex. Include a constructor with two parameters of type double that can be used to set the member variables of an object to any values. Include a constructor that has only a single parameter of type double; call this parameter realPart and define the constructor so that the object will be initialized to realPart + 0 * i . Include a default constructor that initializes an object to o (that is, to 0 + 0 * i ) . Overload all the following operators so that they correctly apply to the type = = , + , , * , > > , and < < . You should also write a test program to test your class. Hints: To add or subtract two complex numbers, add or subtract the two member variables of type double. The product of two complex numbers is given by the following formula:

( a + b * i ) * ( c + d * i ) = = ( a * c b * d ) + ( a * d + b * c ) * i

In the interface file, you should define a constant i as follows:

const Complex i ( 0 , 1 ) ;

This defined constant i will be the same as the i discussed above.

Blurred answer
Students have asked these similar questions
Define a class named Employee. This class should extend the Person class from the previous question. The class should have a constructor, which takes the name, age, employer (String) and salary (int) as parameters (in that order). The first two parameters should be passed to the constructor of the superclass and the value of the last two parameters should be stored in instance variables. The class should define the methods, getSalary which returns the salary of the employee and getEmployer which returns the name of the employer. Any methods from the previous question that need to be overridden should be overridden! Use super and instanceof as appropriate. I.e., for the following methods you should be able to call the method in the superclass for specific situations (e.g. the compareTo method in the superclass can be called if you receive anything other than an Employee, and this also holds for the equals method). The toString method only needs to append details and as such can also…
Define a class that captures airline tickets. Name the class as Airline Ticket. Each ticket lists the departure and arrival cities, a flight number, and a seat assignment. A seat assignment has both a row and a letter for the seat within the row (such as 12F). Include appropriate constructor, destructor and a print fucntion in your class definition. Make two examples of tickets and print the values using the print member function.
Create a Right Triangle class that has two sides. Name your class rightTraingle. Code getter and setters for the base and the height. (Remember class variables are private.) The class should include a two-argument constructor that allows the program to set the base and height. The constructor should verify that all the dimensions are greater than 0. before assigning the values to the private data members. If a side is not greater than zero, set the value to -1. The class also should include two value-returning methods. One value-returning method should calculate the area of a triangle, and the other should calculate the perimeter of a triangle. If either side is -1, these functions return a -1. The formula for calculating the area of a triangle is 1/2 * b*h, where b is the base and h is the height. The formula for calculating the perimeter of a triangle is b+h+sqrt (b*b+h*h). Be sure to include a default constructor that initializes the variables of the base, height to -1. To test…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY