Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

lab / C++ (complete the main.cpp) main.cpp //------------------------------ // DO NOT MODIFY NEXT LINE //------------------------------ #include catch.hpp //------------------------------ // Put the assignment code here class

lab / C++ (complete the main.cpp)
main.cpp
//------------------------------
// DO NOT MODIFY NEXT LINE
//------------------------------
#include "catch.hpp"
//------------------------------
// Put the assignment code here
class Quaternion {
};
//------------------------------
// DO NOT MODIFY TEST CASES
//------------------------------
TEST_CASE( "Assignment" ) {
SECTION( "q1" ) {
Quaternion q{1.0, 2.0, 3.0, 4.0};
Quaternion p{1.0, 2.0, 3.0, 4.0};
REQUIRE( q == p );
}
SECTION( "q2" ) {
Quaternion q{1.0, 2.0, 3.0, 4.0};
Quaternion p{1.0, 2.0, 3.0, 4.0};
Quaternion r{2.0, 4.0, 6.0, 8.0};
REQUIRE( (q + p) == r );
}
SECTION( "q3" ) {
Quaternion q{1.0, 2.0, 3.0, 4.0};
Quaternion p{1.0, 2.0, 3.0, 4.0};
Quaternion r{0.0, 0.0, 0.0, 0.0};
REQUIRE( (q - p) == r );
}
SECTION( "q3" ) {
Quaternion q{1.0, 2.0, 3.0, 4.0};
Quaternion r{2.0, 4.0, 6.0, 8.0};
REQUIRE( (q * 2.0) == r );
}
}
//------------------------------
image text in transcribed
Lab 3 Task: Quaternion The quaternion number system extends the complex numbers. It's the quotient of two directed lines in a three-dimensional space, or, equivalently, as the quotient of two vectors. Quaternions are generally represented in the form a+bi+g+dk where a, b, c, and d are real numbers, and i, j, and k are the basic quaternions. Write a class that defines a quaternion and operations with it. Details Define a class Quaternion that will store 4 coefficients of quaternion The default constructor must accept four double-typed parameters. Overload an equality operation for your class to compare two quaternion objects. Compare corresponding coefficients of the quaternion objects, and return true if they are equal: otherwise return false. The operator must accept constant reference to the Quaternion object. Overload an addition operation for your class to add two quaternion objects. The operator must accept constant reference to the quaternion object. o Add corresponding coefficients of the quaternion objects and return result. The operator must return the Quaternion object. Do not modify current object. Overload a subtraction operation for your class to subtract two quaternion objects. The operator must accept constant reference to the Quaternion object. Subtract corresponding coefficients of the quaternion objects. The operator must return the Quaternton object. Do not modify current object. Overload a multiplication operation for your class to multiply the quaternion object by a scalar number. Multiply all coefficients of the quaternion object by the double-typed value The operator must return the Quaternion object. Do not modify current object. All operators must be const members Make sure that your program compiles without errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions