EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 1, Problem 2PA
Program Plan Intro
Quaternion
Program plan:
- Define a class named “Quaternion” that defines basic operations of quaternion
- Define a function named “operator+()” that adds two input terms and displays the result.
- Define a function named “operator-()” that subtracts two input terms and displays the result.
- Declare a function named “operator*()” that multiplies two input terms and displays the result.
- Define a function named “operator/()” that divides one input term with the other and displays the result.
- Define a function named “operator<<()” that overloads the output operator to output the fraction.
- Declare a function named “operator=()” that performs the function of assignment operation.
- Declare a function named “operator~()” that computes the conjugate of given input quaternion term.
- Declare a function named “normSquared()” that computes the squared norm of an input term and displays the result.
- Declare a function named “operator+=()” that denotes the operation of add AND assignment operators.
- Declare a function named “operator-=()” that denotes the operation of subtract AND assignment operators.
- Declare a function named “operator*=()” that denotes the operation of multiply AND assignment operators.
- Declare a function named “operator/=()” that denotes the operation of divide AND assignment operators.
- Declare a function named “operator==()” that denotes the operation of equality comparison operators.
- Declare a function named “operator!=()” that denotes the operation of add equality operators of comparison type.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Design a Java class named LinearEquation for a 2-by-2 system of linear equations:ax + by = e x=(ed-bf)/(ad-bc)cx + dy = f y=(af-ec)/(ad-bc)
The class contains:• Private double data fields a, b, c, d, e, and f.• A constructor with the arguments for a, b, c, d, e, and f.• Six getter methods for a, b, c, d, e, and f.• Methods getX() and getY() that return the solution for the equation.• A method named isSolvable() that returns true if ad - bc is not 0. The method isSolvable() willbe called in the main, if it returns true display the calculated values for x and y by calling getX()and getY(). If the call to isSolvable() returns false, display a message that “the equation has nosolution”.
Write a Java program that prompts the user to enter a, b, c, d, e, and f and displays the result. After the valuesfor a through f are entered, create a LinearEquation object. Check to seeIf ad - bc is 0, report that “The equation has no solution”, otherwise print out the values for x and y.
In Java:
The program extends the representation for rational numbers
Add a test class TestSimplifiedRational
Define the simplified rationals r1..r4 and initialize them with 1/2, -3/9, 10/12 and 1
Compute sum=r1+r2 and diff=r4-r3
Simplify both results
Check if they are equal, using equals and comparing their numerators and denominators. What do you observe?
Compare r1 with r2, r3 and r4.
Print all the rational numbers and partial results.
By implementing the concepts of Classes and Objects, write a C++ program that converts the value of Delta-connected resistances to their equivalent Wye- connected resistances. Use the following formulas:
R1 = R12(R31)/(R12+R23+R31) R2 = R12(R23)/(R12+R23+R31)
and R3 = R31(R23)/(R12+R23+R31)
The values of the 3 Delta-connected resistances, R12, R23 and R31 are to be entered from the keyboard.
Sample Input:
Enter the value of each Delta-connected resistances:
Enter the value for R12:
Enter the value for R23:
Enter the value for R31:
The equivalent Wye-connected resistances are:
R1 =
R2 =
R3 =
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
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
Although the book focused on the normalization process only up to the Third Normal Form (3NF), there are actually four more commonly recognized normal forms – Boyce-Codd Normal Form (BCNF), Fourth Normal Form (4NF), Fifth Normal Form (5NF), and Sixth Normal Form (6NF). Research the uses of these other normal forms, then pick one to give a brief explanation of to the class. please pick one .
arrow_forward
Create a program in Java that implements Polymorphism and asks the users input to compute the wages of regular and contractual employees
arrow_forward
In three sentences, explain why it's preferable to have accessors for private types rather than public types.
arrow_forward
Write a Number class that holds a double, and add overloaded operators for +, –, *, /, and assignment. Choose the return values for these functions so that expressions can be chained together, and for efficiency. Write an automatic type conversion operator int( ). Please submit code in
arrow_forward
Solve the problem in C++
(Extend MyPoint)
In Programming Exercise 9.4, the MyPoint class was created to model a point in a two-dimensional plane. The MyPoint class has the properties x and y that represent x- and y-coordinates, two getter functions for x and y, and the function for returning the distance between two points.
Create a class named ThreeDPoint to model a point in a three-dimensional space. Let ThreeDPoint be derived from MyPoint with the following additional features:
- A data field named z that represents the z-coordinate.- A no-arg constructor that constructs a point with coordinates (0, 0, 0).- A constructor that constructs a point with three specified coordinates.- A constant getter function that returns the z value.- A constant distance(const MyPoint&) function to return the distance between this point and the other point in the three-dimensional space.
Draw the UML diagram for the classes involved. Implement the classes. Write a test program that creates two…
arrow_forward
I need help in coding these two classes(dorm and room) in JAVA from the following information->
*A dormitory has a name and has several rooms. When a dormitory is built, the name and the number of rooms should be provided. In some cases, the maximum capacity of the rooms is also provided. If there is no maximum capacity set, each room can accommodate at most 6 guests.
*The rooms are then automatically created and added to the dormitory, numbered from 1, 2, 3, and so on, representing the room number. Once the room number is assigned to the created room, this information cannot be edited anymore.
*The dormitory can accept guests into a given room number. Each guest has a name and nationality. If the capacity is full or an invalid room number is provided, the guest will not be added and this method returns false. Otherwise, this method returns true.
*The dormitory also has a method to return the guests in a given room number. If an invalid room number is provided, the method will…
arrow_forward
i need it urgently in java not in java c++
Create an Abstract class Student that contains a method take exam, implement the method in the child classes PhdStudent and GradStudent in which PhdStudent takes exam by giving his final defense presentation while the graduate student gives a written paper.
arrow_forward
In Java, a class can only inherit from one other ------- . A class can, however, extend many ----------.
arrow_forward
Write an abstract data type for rational numbers (a numerator and a denominator). Include a constructor and methods for getting the numerator, getting the denominator, addition, subtraction, multiplication, division, equality testing, and display. Use Java or C++.
arrow_forward
The union of two sets A and B is a set that contains all the elements that are in A together with all the elements that are in B. The intersection of A and B is the set that contains elements that are in both A and B. The difference of A and B is the set that contains all the elements of A except for those elements that are also in B.Suppose that A and B are variables of type set in Java. The mathematical operations on A and B can be computed using methods from the Set interface. In particular: A.addAll(B) computes the union of A and B; A.retainAll(B) computes the intersection of A and B; and A.removeAll(B) computes the difference of A and B. Write a program that can be used as a "set calculator" for simple operations on sets of non-negative integers. (Negative integers are not allowed.) A set of such integers will be represented as a list of integers, separated by commas and, optionally, spaces and enclosed in square brackets. For example: [1,2,3] or [17, 42, 9, 53,108]. The…
arrow_forward
USING JAVA,
specify, design, and implement a class called statistician. After a statistician is initialized, it can be given a sequence of double numbers. Each number in the sequence is given to the statistician by activating a member function called next_number. For example, we can declare a statistician called s, and then give it the sequence of numbers 1.1, -2.4, 0.8 as shown here:
statistician s;
s.next_number(1.1);
s.next_number(-2.4);
s.next_number(0.8);
After a sequence has been given to a statistician, there are various member funcitons to obtain infomration about the sequence. Include member functions that will provide the length of the sequence, the last number of the sequence, the sum of all the numbers in the sequence, the arithmetic mean of the numbers(i.e the sum of the numbers divided by the length of the sequence), the smallest number inthe sequence, and the largest number in the sequence. Notice that the length and sum functions can be called at any time,…
arrow_forward
Please implement in Java
implement a keyed bag in which the items to be stored are strings (perhaps people’s names) and the keys are numbers (perhaps Social Security or other identification numbers). So, the in- sertion method has this specification:
public void insert(String entry, int key);// Precondition: size( ) < CAPACITY, and the // bag does not yet contain any item// with the given key.// Postcondition: A new copy of entry has// been added to the bag, with the given key.
When the programmer wants to remove or retrieve an item from a keyed bag, the key of the item must be specified rather than the item itself. The keyed bag should also have a boolean method that can be used to determine whether the bag has an item with a specified key.
In a keyed bag, the pro- grammer using the class specifies a particular key when an item is inserted.
Here’s an implementation idea: A keyed bag can have two private arrays, one that holds the string data and one that holds the corresponding…
arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License