Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone help me write a .h and .ccp File for these methods please!. Im hav

ID: 674444 • Letter: C

Question

Could someone help me write a .h and .ccp File for these methods please!. Im having a hard time declaring them in a .h file and writing the methods in a .cpp file. I would be grateful to anyone who could help me ! Thank you!

Methods and associated functions

Vector::Vector()

The class should have a default constructor that takes no arguments. The constructor should set the vector size and vector capacity to 0 and the vector array to nullptr. Alternately, the data members can be initialized in the class declaration, in which case this method's body can be empty.

Vector::~Vector()

The class should have a destructor that deletes the dynamic memory for the vector array. The destructor should NOT call the clear() method.

Vector::Vector(const Vector& other)

The class should also have a proper copy constructor. Your code should account for the possibility that you might be copying an empty Vector object.

Vector& Vector::operator=(const Vector& rhs)

The assignment operator should be properly overloaded to allow one Vector object to be assigned to another. Your code should account for the possibility that you might be copying an empty Vector object.

ostream& operator<<(ostream& lhs, const Vector& rhs)

The output operator should be overloaded so that a Vector can be printed on the standard output. As in Assignment 4, this will need to be a standalone friend rather than a method.

The items stored in the vector should be printed starting with the front item and ending with the back item.

void Vector::clear()

This method should set the vector size to 0. It should not change the vector capacity or the vector array.

size_t Vector::size() const

This method should return the vector size.

size_t Vector::capacity() const

This method should return the vector capacity.

bool Vector::empty() const

This method should return true if the vector size is equal to 0; otherwise it should return false.

int Vector::front() const

This method should return the first element of the vector array (the one at the subscript 0). You may assume this method will not be called if the vector is empty.

int Vector::back() const

This method should return the last valid element of the vector array (the one at the subscript (vector size - 1). You may assume this method will not be called if the vector is empty.

void Vector::push_back(int item)

This method takes an integer argument, the item to insert into the vector. If the vector is full (the vector size is equal to the vector capacity), this method will need to call the reserve() method to increase the capacity of the vector array and make room for the item to insert. If the vector capacity is currently 0, pass a new capacity of 1 to the reserve() method. Otherwise, pass a new capacity of twice the current vector capacity to the reserve() method.

Using the vector size as the subscript, copy the item to be inserted into the vector array. The vector size should then be incremented by 1.

void Vector::pop_back()

This method should decrement the vector size by 1, which effectively removes the last item from the vector array. No changes need be made to the vector array contents. You may assume this method will not be called if the vector is empty.

void Vector::reserve(size_t newCapacity)

This method increases the capacity of the vector array. It takes a single integer argument, the new capacity. The logic for this method should look something like this:

Set the vector capacity to the new capacity.

Declare a local pointer to an int and use it to allocate a new temporary array of integers. The number of elements for this new array should be equal to the vector capacity.

Loop through the vector array from subscript 0 up to the vector size, copying elements from the vector array to the temporary array.

Delete the vector array.

Assign the temporary array pointer to the vector array pointer.

int Vector::operator[](int sub) const

This method should return the element of the vector array at subscript sub. You may assume this method will not be called if the vector is empty.

int& Vector::operator[](int sub)

This method should return the element of the vector array at subscript sub. You may assume this method will not be called if the vector is empty.

bool Vector::operator==(const Vector& rightOp) const

This method is used to compare two Vector objects. The method should return true if the Vector objects are equal; otherwise, it should return false. The logic for this method should look something like this:

If the two Vector objects do not have the same vector size, they can not be equal and the method should return false.

Otherwise, the method should loop through the vector arrays of the two objects from 0 up to the vector size. If an element of the left operand's vector array does not equal the corresponding element of the right operand's vector array, return false. Otherwise, simply continue the loop.

If the loop finishes without having returned false, all the elements of both vector arrays are equal and the method should return true.

Explanation / Answer

/*PROGRAM TO PERFORM VARIOUS OPERATION ON A VECTOR
       USING OPERATOR OVERLOADING*/

#include "Vector.cpp"

void main()
{
   system("cls");
   Vector A,B,C;
   int k,ch;
   char choice = 'y';
   do
   {
       if(choice == 'y' || choice == 'Y')
       {
           cout<<"
   INPUT VECTOR
";
           cout<<"
ENTER THE FIRST VECTOR.
";
           A.GetData();
           cout<<"
ENTER THE SECOND VECTOR.
";
           B.GetData();
       }

       system("cls");
       cout<<"
       PROGRAM FOR VECTOR OPERATIONS.
";
       cout<<"

First Vector(A)= "<<A<<"   Second Vector(B)= "<<B<<"

";
       cout<<"   1.Addition Of Two Vectors.
";
       cout<<"   2.Subtraction Of Two Vectors.
";
       cout<<"   3.Multiplication Of A Vector With The Scalar.
";
       cout<<"   4.Cross Product Of Two Vectors.
";
       cout<<"   5.Scalar(or Dot) Product Of Two Vectors.
";
       cout<<"   6.Negative Of Vectors.
";
       cout<<"   7.Exit
";
       cout<<"  
Enter The Choice. ";
       cin>>ch;
        switch(ch)
       {
           case 1:
               cout<<"
ADDITION OF TWO VECTORS.
";
               C = A + B;
               cout<<"
The Value Of A+B Is: "<<C;
               break;
           case 2:
               cout<<"
SUBTRACTION OF TWO VECTORS.
";
               C = A - B;
               cout<<"
The Value Of A-B Is: "<<C;
               break;
           case 3:
               cout<<"
MULTIPLICATION OF A VECTOR WITH A SCALAR.
";
               cout<<"
Enter The Value Of The Scalar: ";
               cin>>k;
               C = A * k;
               cout<<"
The Value Of Ak Is (k Is the Scaler): "<<C;
               C = k * B;
               cout<<"
The Value Of kB Is (k Is the Scaler): "<<C;
               break;
           case 4:
               cout<<"
CROSS PRODUCT OF TWO VECTORS.
";
               C = A * B;
               cout<<"
The Value Of A*B(Cross Product) Is: "<<C;
               break;
           case 5:
               cout<<"
SCALAR(OR DOT) PRODUCT OF TWO VECTORS.
";
               A.DotProd(B);
               break;
           case 6:
               cout<<"
NEGATIVE OF A VECTOR.
";
               C = -A;
               cout<<"The Value Of -A Is: "<<C;
               C = -B;
               cout<<"
The Value Of -B Is: "<<C;
               break;
           case 7:
               return;
           default:
               cout<<"
WRONG CHOICE.
";
               break;
               getch();
       }
       cout<<"

DO YOU WANT TO ENTER A NEW VECTOR (y/n): ";
       cin>>choice;
       system("cls");
   }while(1);
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
                             //VECTOR.CPP

#include"Vector.h"


Vector::Vector():x(0),y(0),z(0)
{
   //cout<<"This Is A Default Constructor.";
}

Vector Vector::operator +(const Vector &v)const //Addition
{
   Vector res;
   res.x = x + v.x;
   res.y = y + v.y;
   res.z = z + v.z;
   return res;
}

Vector Vector::operator -(const Vector &v)const //Subtraction
{
   Vector res;
   res.x = x - v.x;
   res.y = y - v.y;
   res.z = z - v.z;
   return res;
}

Vector Vector::operator *(const int k)const //Multiplication By Scalar
{
   Vector res;
   res.x = k * x;
   res.y = k * y;
   res.z = k * z;
   return res;
}

void Vector::GetData()           //Input The Vector
{
   cout<<"
Enter The Value Of x : ";
   cin>>x;
   cout<<"
Enter The Value Of y : ";
   cin>>y;
   cout<<"
Enter The Value Of z : ";
   cin>>z;
}

Vector operator *(int k,const Vector &v)
{
   return v * k;
}

Vector Vector::operator -()const   //Negative Of A Vector
{
   Vector res;
   res.x = -x;
   res.y = -y;
   res.z = -z;
   return res;
}

Vector Vector::operator *(const Vector &v)const //Cross (or Vector)
Product
{
   Vector res;
   res.x = (y * v.z) - (z * v.y);
   res.y = (z * v.x) - (x * v.z);
   res.z = (x * v.y) - (y * v.x);
   return res;
}

void Vector::DotProd(Vector v2)    //Dot(Or Scalar) Product
{
   int v1v2;
   v1v2 = (x * v2.x)+(y * v2.y)+(z * v2.z);
   cout<<"
The Value Of A.B Is: "<<v1v2;
}

ostream & Vector::Show(ostream & out)const
{
   if((x<0) && (y<0) && (z<0))
   out<<x<<"I"<<y<<"J"<<z<<"K";

   if((x<0) && (y<0) && (z>=0))
   out<<x<<"I"<<y<<"J+"<<z<<"K";

   if((x<0) && (y>=0) && (z<0))
   out<<x<<"I+"<<y<<"J"<<z<<"K";

   if((x<0) && (y>=0) && (z>=0))
   out<<x<<"I+"<<y<<"J+"<<z<<"K";

   if((x>=0) && (y<0) && (z<0))
   out<<x<<"I"<<y<<"J"<<z<<"K";

   if((x>=0) && (y<0) && (z>=0))
   out<<x<<"I"<<y<<"J+"<<z<<"K";

   if((x>=0) && (y>=0) && (z<0))
   out<<x<<"I+"<<y<<"J"<<z<<"K";

   if((x>=0) && (y>=0) && (z>=0))
   out<<x<<"I+"<<y<<"J+"<<z<<"K";

   return out;
}


////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
                       // VECTOR.H

#include<iostream>
#include<conio.h>
#include<stdlib.h>

using namespace std;

class Vector
{
private:
   int x,y,z;
public:
   Vector(int,int,int);
   Vector();
   void GetData();
   Vector operator+(const Vector &v)const;
   Vector operator-(const Vector &v)const;

   Vector operator*(const int k)const;       //Multiplication by Scalar
   Vector operator*(const Vector &v)const; //Cross Product
   Vector operator-()const;               //Negative Of A Scaler
   void DotProd(Vector);                   //Dot Product

   ostream & Show(ostream & out)const;
   friend Vector operator*(const int k,const Vector &v);
   friend ostream & operator<<(ostream & out,const Vector &v)
   {
       v.Show(out);
        return out;
   }
};