![Consider that individual nodes in an unsorted linked list have the following definition class Vector public: Vector(int s = 0)( // makes Size //allocates s space, // makes all entries s, kes all entries e Vector (const Vector & rhs) // copy constructor // makes self a deep copy of rhs Vector operator (const Vector & rhs)(// makes self a deep copy of rhs nVector default destructor int & operator[] (int index){ if 0く-posくsize // // returns entries[index] int sz(){// returns the # of entries private: int size; int *entries; //store the # of elements used 3; ostream & operator<< (ostream & out, Vector & rhs);](http://img.homeworklib.com/questions/cf87c1f0-7729-11eb-ba64-ef847f26b5b7.png?x-oss-process=image/resize,w_560)

Please give a answer to both
tasks with a screenshot of the running file.
Thanks
Vector.h
-------------------------------
#ifndef VECTOR_H
#define VECTOR_H
#include"iostream"
using namespace std;
class Vector
{
private:
int size;
int * entries;
public:
Vector(int s=0);
Vector(const Vector &rhs);
Vector operator = (const Vector &rhs);
friend ostream & operator <<
(ostream& os,const Vector & rhs);
~Vector();
int & operator[](int index);
int sz();
};
#endif // VECTOR_H
Vector.cpp
-------------------------
#include "vector.h"
#include <cstring>
Vector::Vector(int s)
{
this->size = s;
this->entries = new int[s];
}
Vector::Vector(const Vector &rhs){
this->size = rhs.size;
this->entries = new int[this->size];
memccpy(this->entries,rhs.entries,rhs.size,sizeof(int));
}
Vector Vector:: operator = (const Vector &rhs){
this->size = rhs.size;
this->entries = new int[this->size];
//memcpy(this->entries,rhs.entries,rhs.size);
for(int i = 0 ; i< rhs.size ; i++){
this->entries[i] =
rhs.entries[i];
}
return *this;
}
Vector::~Vector(){
}
ostream& operator << (ostream& os,const Vector
&rhs){
os<<"printing Vector"<<endl;
for(int i = 0 ; i < rhs.size;i++){
cout<<rhs.entries[i]<<endl;
}
return os;
}
int & Vector::operator[](int index){
return entries[index];
}
int Vector::sz(){
return size;
}
Main.cpp
------------------------
#include <iostream>
#include<vector.h>
using namespace std;
int main(int argc, char *argv[])
{
Vector test(10);
Vector *vecPtr;
Vector exam(5);
for(int i = 0 ; i < test.sz();i++){
test[i]= i;
}
cout<<"test initially is:";
cout<<test<<endl;
exam = test;
cout<<"After exam = test, exam is
:";
cout<<exam <<endl;
{
Vector sqrs(10);
cout<<"The Squares
are :";
for(int i = 0 ; i <
sqrs.sz();i++){
sqrs[i] = i*i;
}
vecPtr= &sqrs;
cout<<sqrs<<endl;
}
return 0;
}
Output
Please give a answer to both tasks with a screenshot of the running file. Thanks Consider...
Please do it carefully Using the header file ( MyArray.h ) Type the implementation file MyArray.cpp, and a test file to test the functionality of the class. Hint: read all the explanations in the header with attention. MyArray.h : #ifndef MYARRAY_H #define MYARRAY_H #include <iostream> using namespace std; class MyArray { friend ostream& operator<<( ostream & output, const MyArray & rhs); // to output the values of the array friend istream& operator>>( istream & input, MyArray & rhs); // to...
// thanks for helping // C++ homework // The homework is to complete below in the stack.h : // 1. the copy constructor // 2. the assignment operator // 3. the destructor // 4. Write a test program (mytest.cpp) to test copy and assignment // 5. Verify destructor by running the test program in Valgrind // This is the main.cpp #include <iostream> #include "stack.h" using namespace std; int main() { Stack<int> intStack; cout << "\nPush integers on stack and dump...
How do i Overload the & operator to concatenate two arrays?, so elements from both arrays will be seen Below is code i have so far. everything works except the operator overload of &. The & operator only works when both array are equal, first array smaller then second, fails when first array is the largest. class smartArray{ public: int *elements; // dynamic array, memory is allocated in the constructor. Use *this to access size member. int length(); // returns...
C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...
Create an h file called list. It should have the following
features:
lisi's funnc In no particular order: List(): Default constructor. This should construct an empty List, the member variables should be initialized to reflect this state. This function is already fully implemented. 1. List(const List<Type>& other): Copy constructor for the linked list. This should create an entirely new linked list with the same number of Nodes and the Values stored these Nodes in the same order as seen the...
Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator: prints "Move assignment" and endl in addition...
please write the code in
C++
2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...
C++ Write a MyString class that stores a (null-terminated) char* and a length and implements all of the member functions below. Submit your completed source (.cpp) file. Default constructor: empty string const char* constructor: initializes data members appropriately Copy constructor: prints "Copy constructor" and endl in addition to making a copy Move constructor: prints "Move constructor" and endl in addition to moving data Copy assignment operator: prints "Copy assignment" and endl in addition to making a copy Move assignment operator:...
C++ problem to use dynamic memory allocation (of arrays) and pointer manipulation in order to implement the Inner and Outer classes (Circular Buffer of circular buffers using Queues). No need of any classes from the Standard Template Library (STL), not even vector. Add the member functions of those classes by following the codes of InnerCB.h and CBofCB.h below: // file: InnerCB.h // Header file for Inner Circular Buffer. // See project description for details. // #ifndef _INNERCB_H_ #define _INNERCB_H_ class...
C++ Assignment - Only Implementation file( VectorDouble.cpp file) required. The header file is already given. Please help, thumbs up guaranteed. Chapter 8 discussed vectors, which are like arrays that can grow in size. Suppose that vectors were not defined in C++. Define a class called VectorDoublethat is like a class for a vector with base type double. Your class VectorDoublewill have a private member variable for a dynamic array of doubles. It will also have two member variables of type...