Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please answer with full written code in c++ question in c++: In this exercise we will deal with the representation of vectors. A vector can

please answer with full written code in c++

question in c++:

In this exercise we will deal with the representation of vectors. A vector can be represented as a one-dimensional array of real numbers, for example [1.3, -4.3, 5.8, 2.4]. Vectors are used in many applications, including image processing, machine learning, and more. We will define a number of operations on vectors - multiplying a vector in a scalar - the product multiplies each member of the vector in a scalar. For example if the vector is a = [2.1, 3.5, 6.2, 4.8] then the product a*3 = 3 * a = [6.3, 10.5, 18.6, 14.4] Connecting a vector to a scalar - the connection adds a scalar to each member of the vector. For example for the vector a above, the connection a+2 = 2+a = [4.1, 5.5, 8.2, 6.8] Multiplication of vectors - given two vectors, the product between them is defined as a new vector in which each term i is equal to the product of the term i of the first vector times the term i of the second vector. For example, for the vectors a = [2.1, 3.5, 6.2, 4.8], b = [4.2, 3.1, 5.2, 9.4] Their product is: a * b = b * a = [2.1 * 4.2, 3.5 * 3.1, 6.2 * 5.2, 4.8 * 9.4] = [8.82, 10.58, 32.24, 45.12] Note that both vectors must be the same size. Scalar product (dot product) - the scalar product between two vectors is defined as a number equal to the sum of the products of a member by a member. For example, for the two vectors a, b above, the scalar product is defined as follows: ab = ba = 2.1*4.2 + 3.5 * 3.1 + 6.2 * 5.2 + 4.8 * 9.4 = 96.76

Question 1 (%100) Write a class called Vector that will represent a one-dimensional vector. The class will contain two private properties: double* elements; which will represent the array of members of the vector. int size; which will represent the number of elements in the vector. Also define a global constant (using a variable or define) named ERROR that will be equal to -999 The department will contain the following builders - Vector(int n) the constructor will create a vector of size n with all elements 0. Vector(double a[], int n) the constructor will receive as a parameter an array of double and its size n and will create a vector of size n whose members are the members of array a. Vector(Vector& v) the copy constructor. Add the following functions to the class: int getSize() the function will return the size of the vector (the number of elements in it). Vector operator=(Vector& v) the placement operator. The operator will copy the v data to this. Pay attention to avoid aliasing and make a deep and not flat copy. double operator[](int ind) the function will accept as an index parameter and will return the member found in the ind index or ERROR if the index is invalid (outside the size of the vector). Vector operator+(double d) the function will perform a scalar connection d to the vector and return a new vector with the result. friend Vector operator+(double d, Vector& v) the function will perform a scalar connection d to the vector v and return a new vector with the result. Vector operator*(double d) the function will perform a scalar multiplication d in a vector and return a new vector with the result. friend Vector operator*(double d, Vector& v) the function will multiply a scalar d by v and return a new vector with the result. Vector operator*(const Vector& v) the function will perform a multiplication between two vectors and return a new vector with the result. bool operator==( Vector& v) the function will compare two vectors. Two vectors will be called equal if they are the same size and contain the same terms in the same order. friend ostream& operator<<(ostream& out, Vector& v) the function will print out the vector. The vector will be printed by printing square brackets with the members of the vector inside them, each member separated by a comma. double dot(Vector& v) the function will perform a scalar multiplication between two vectors. ~Vector() the constructor of the class, will release the dynamically allocated memory. You can use the following main: #include #include using namespace std;

void main() { Vector a(4); double arr[] =[2.1, 3.5, 6.2, 4.8]; Vector b(arr, 4); Vector c = b * 2; cout<

Submission guidelines 1. You must submit a word file with a link to the code written in onlineGDB as described in the instructions for submitting the exercises on the website. 2. Submit the file in the college's assignment system. Do not submit in pairs. 3. The exercise must be submitted by January 22, 2023 at 11:59 p.m.

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

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

why do consumers often fail to seek out higher yields on deposits ?

Answered: 1 week ago