# Homework 1 BLG 252E solved

\$35.00

Category:

## Description

In this assignment, you are going to implement classes for two mathematical expressions:
Polynomials and Vectors(do not confuse this with std::vector). These classes will hold
necessary information to represent the data, and will also support some of the mathematical operations of these expressions: In Polynomial class, you will implement polynomial
addition and multiplication and in Vector class, you will implement vector addition, scalar
multiplication and dot product. You will also implement a user interface for users to perform
operations with Polynomials and Vectors. More details are given below.
As a reminder, following section gives basic explanations of polynomials and vectors, and
how to perform the operations.
Polynomials and Vectors
A polynomial is an expression in the form of
anx
n + an−1x
n−1 + …a2x
2 + a1x
1 + a0 (1)
where x is a variable and ak is a real number and called the coefficient of x
k
. Such polynomial is called “n-th” degree polynomial. For example: 2x
3 + x
2 + 5x + 12 is a third degree
polynomial. Coefficients can be zero, so x
4 + 2x is also a polynomial and degree of it is four.
Polynomial addition is an operation between two polynomials and is performed by adding
the coefficients of the variables with the same exponent. An example: (x
3 + 2x
2 + 3x + 4) +
(−2x
3 + 2x − 2) = −x
3 + 2x
2 + 5x + 2
Polynomial multiplication is performed by multiplying every pair of terms between two
polynomials, such that axk
.bxl = (a+b)x
k+l
. An example: (x
2+2x+3).(x−1) = x
3+x
2+x−3.
The definition of a vector is given as “an object that has a magnitude and direction”. In this
assignment, we are only working with real numbers, so in the sense of list representation, we
can represent a vector in an n-dimensional vector space with n real numbers, each number
showing the length of vector in one axis. For example, in a 4-dimensional vector space, a
vector can be represented as (a1, a2, a3, a4), where ak is a real number.
Vector Addition can be performed with two vectors in a vector space. Since the vectors
must be in the same vector space, we can not perform vector addition with different sized
vectors(we can extend the vectors but we will assume that it can not be performed in this
homework). For example: (2, 3, 1) + (1, 5, 11) = (3, 8, 12). (3, 4, 2) + (1, 2, 3, 4) can not be
performed, since their size is not equal.
2
Homework 1
BLG 252E
Scalar multiplication of a vector and a scalar is performed by multiplying all elements of
a vector with a scalar such that (a1, a2, …, an)xc = (ca1, ca2, …, can) where c is a real number.
Dot product between two vectors is performed by multiplying the elements that represents
the same dimension and summing them together such that (a1, a2, …, an).(b1, b2, …, bn) =
a1b1 + a2b2 + … + anbn. For example: (1, 2, 3).(2, 1, 3) = 2 + 2 + 9 = 13.
You can find more sources on the internet if you are not familiar with concepts above.
Implementation Details
As explained, you will implement 2 classes and a user interface. First of all you should
implement Vector and Polynomial classes in their respective header files, “Vector.h” and
Polynomial.h. In these 2 classes, following should be included:
• In the Vector class, size of the vector and the value array should be maintained.
Similarly in Polynomial class, degree and values should be maintained.
• Both of the classes should have a constructor that initializes objects with given values. They should also have a copy constructor. If your class uses arrays, your copy
constructor should allocate new memory for arrays in the new objects.
• You need to use operator overloading feature to implement the operations. + operation
should perform vector addition in Vector class and polynomial addition in Polynomial
class, while ∗ operation should perform multiplication operations. Note that Vector
has two forms of multiplication: scalar multiplication and dot product. You need to
overload ∗ operation such that it performs scalar multiplication when given input is
integer, and dot product when given input is a Vector. Also do not forget that, for dot
product and vector addition operations, size of the vectors must be the same!