INSTRUCTIONS FOR THE SUBMISSION
Submit your code on Canvas as zip:
Submit as a single zip file containing all code for the problem.
The source files should compile without errors or warnings on Visual Studio 2019 as installed on the clusters, and
the resulting executables should run without problems. You do not have to submit the executable. Using debug
and x64 build options.
If you use another compiler other than Visual Studio, you should take your final code and compile it on
Visual Studio on the remote clusters.
Unfortunately, different compilers follow slightly different rules, and even a small difference may cause the code to
fail on Visual Studio. The source code should also be well formatted. This means that opening and closing brackets
should be aligned in a readable way, and we will discuss such styles briefly in the lectures. A good guide would be:
Google C++ Style Guide
but Consistency is what will be checked. Also, it is crucial that you comment your code well. For this problem sheet,
this means that you should explain every single line of code with a comment. Later in this module, it will not be
necessary to comment basic code (e.g. what each for loop is doing, as long as it is obvious). But it is your
responsibility to make sure the marker can understand what your code is doing. Also, please give variables
meaningful names. This greatly increases readability of the code. Finally, the programs you write should run in a
self-explanatory way. If you are asked that the program provides some input, it should first have some output on
the command line telling the user what kind of input is required.
For instance, if you are supposed to read in the price of a interest rate, do the following:
std::cout << “ Please enter the interest rate: “ << std::endl;
std::cin >> interest_rate;
This way, a user of the program who does not know about the code knows what numbers one has to enter.
PROBLEM 1 Create a C++ class to implement vectors
When you finish this problem, you should have fullfilled these requirements:
The design is to be object-oriented and the program was to be written in C++.
The code has to be efficient, well structured, commented and maintainable.
The design is to include a cVector class to encapsulate the behaviour of a three-dimensional point or vector,
and a Ray class to encapsulate the behaviour of an infinite three-dimensional line or ray.
The classes are to provide constructors, selectors, input and output streaming, and various mathematical
operators and functions.
Implemented atleast two C++ classes in a library MathsLib-Start1.
Implemented a test Project _MathsLib-test__ that employs a library and C++ class and utility functions.
Implemented a program Raycalc that tests your utillity operators and functions.
The Raytest program should ask the user to enter two rays via the commandline and then test if they
When this assignment is complete, your code should produce an executable program: Raycalc an exe console
program, a static library MathsLib-Start1 and test Project MathsLib-test.
Your solution Sould have the following layout (which is based on the work in the labs):
│ └───Header Files
│ │ └─── consts.h
│ │ cVector.h
│ │ cRay.h
│ └───Source Files
│ └─── MathsLib_Start1.cpp
│ └───Source Files
│ └─── test.cpp
A vector can have many meanings, depending on whether we are talking geometrically or numerically. In either
case, vectors have dimensionality; this represents the number of dimensions that the vector has. A two-dimensional
vector is restricted to a single plane, while a 3D vector can point in any physical space. In terms of geometry, a
vector can represent one of two concepts: a position or a direction within a particular space. A vector position
represents a specific location in space. A vector can also represent a direction. Direction vectors do not have an
origin; they simply specify a direction in space. Each of the numbers within a vector is called a component. Each
component usually has a name. The first component of a vector is the X component. The second component is the Y
component, the third is the Z, and if there is a fourth, it is called W. When writing vectors in text, they are written
with parenthesis. So a 3D vector could be (0, 2, 4); the X component is 0, the Y component is 2, and the Z
component is 4.
Vector Addition with Numbers
Any operation where you perform an operation on each component of a vector is called a component-wise
operation. Vector addition is componentwise. Any component-wise operation on two vectors requires that the two
vectors have the same dimensionality.
Vector Negation and Subtraction
You can negate a vector. This reverses its direction. Numerically, this means negating each component of the
Multiplying two vectors numerically is simply component-wise multiplication, much like vector addition
Vectors can be operated on by scalar values. This magnifies or shrinks the length of the vector, depending on the
Scalars can also be added to vectors. It is a component-wise addition of the scalar with each component of the
Vectors have a length. The length of a vector direction is the distance from the starting point to the ending point.
Vector Length uses the Pythagorean theorem to compute the length of the vector.
Unit Vectors and Normalization
A vector that has a length of exactly one is called a unit vector. This represents a pure direction with a standard,
unit length. A vector can be converted into a unit vector by normalizing it. This is done by dividing the vector by its
length. Or rather, multiplication by the reciprocal of the length.
A ray is a direction and a position;(two vector) it represents a line extending from the position along that direction.
The points on the ray can be expressed as the following equation: The Ray Equation is then given by: D^ = a vector
representing Ray Direction O# = a vector representing Ray Origin P(t) = D^t + O#
The scalar t value can be positive or negative.
For the first part, implement a cVector class for a vector with dimensions (X, Y,Z, W) a 3D vector. Your class should
be defined by cVector.h and cVector.cpp.
The cVector class is to include mathematical operators and functions for addition, subtraction, scalar
multiplication, negation, cross product, dot product, length, normalise, and the distance between two points.
All functions of the class cVector should be tested
For the second part, implement a cRay class. Your class should be defined by cRay.h and cRay.cpp.
The Ray class is to include the mathematical operators and functions for negation, the distance between a
point and a line, the distance between two lines, and the intersection between two rays. This intersection could
also be used to construct a Vector object.
All functions of the class cRay should be tested