Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PROGRAM SPECIFICATIONS Using separate source (Vector.cpp) and header files (Vector.h) create a class to represent a vector class according to the following specifications (use the
PROGRAM SPECIFICATIONS Using separate source (Vector.cpp) and header files (Vector.h) create a class to represent a vector class according to the following specifications (use the method and attribute names as given here): The Vector.h header file (you may not alter this file and you must submit it with your code): #pragma once #include using namespace std; class Vector private: int size; // sets the # of elements used int *entries; 17 point to array of integers with size entries e.g. entries = new int[size] public: Vector(); // default constructor Vector(int s); // makes size = s, allocates s space 17 e.g. entries = new int[size], // makes all entries 0 Vector (const Vector & other); // copy constructor, makes a deep copy -Vector(); // default destructor void print(); // Prints out the vector as: [1 2 3] void set(int val, int pos); // if 0 using namespace std; int main() // REQUIRED CODE Vector a, b(3), C(3) ; Winter // outputs [] // outputs [ 000] // output error message a.print(); b.print(); c.set(0,-1); c.set(1,0); c.set(2,1); c.set(3, 2); c.set(4,3); c.print(); // outputs error message // outputs [ 1 2 3 ] Vector d(c); // outputs [ 1 2 3] d.set(0,1); d.print(); c.print(); // outputs [ 1 0 3 ] // outputs [ 1 2 3 ] proves deep copy system("pause"); return 0; PROGRAM SPECIFICATIONS Using separate source (Vector.cpp) and header files (Vector.h) create a class to represent a vector class according to the following specifications (use the method and attribute names as given here): The Vector.h header file (you may not alter this file and you must submit it with your code): #pragma once #include using namespace std; class Vector private: int size; // sets the # of elements used int *entries; 17 point to array of integers with size entries e.g. entries = new int[size] public: Vector(); // default constructor Vector(int s); // makes size = s, allocates s space 17 e.g. entries = new int[size], // makes all entries 0 Vector (const Vector & other); // copy constructor, makes a deep copy -Vector(); // default destructor void print(); // Prints out the vector as: [1 2 3] void set(int val, int pos); // if 0 using namespace std; int main() // REQUIRED CODE Vector a, b(3), C(3) ; Winter // outputs [] // outputs [ 000] // output error message a.print(); b.print(); c.set(0,-1); c.set(1,0); c.set(2,1); c.set(3, 2); c.set(4,3); c.print(); // outputs error message // outputs [ 1 2 3 ] Vector d(c); // outputs [ 1 2 3] d.set(0,1); d.print(); c.print(); // outputs [ 1 0 3 ] // outputs [ 1 2 3 ] proves deep copy system("pause"); return 0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started