Using code from repl.it create a more robust MyVector
class that will include more functionality. You will achieve this by writing additional methods to add values, remove values, and maintain sorted values if needed. This class also needs the ability to be initialized with different data sources (files, other vectors, and arrays).C++
Right now the example code is a mish-mash of disconnected code snippets collected as we review last semester. There is a basic linked list class that has half the functionality of a stack. There are methods to print files, and load files into arrays. The class even has an overloaded constructor that loads an array into the linked list. But we need to clean up this code and turn it into a usable class that you or anyone would want to use. To do this we need to define exactly what we want our class to do. I will list out the requirements for you to fulfill below. Right now we will assume that we store integers, but we will rectify this in the upcoming programs when we overload operators and add type templates to our class.
V1 = new MyVector(int *A, int size)
: adds each item from an array typeV1 = new MyVector(string FileName)
: read until eof loading each value into listV2 = new MyVector(MyVector V1)
: traverse other.list
adding each value to this.list
V.pushFront(int val)
: adds single value to front of this.list
V.pushFront(MyVector V2)
: adds entire other.list
to front of this.list
V.pushRear(int val)
: adds single value to rear of this.list
V.pushRear(MyVector V2)
: adds entire other.list
to rear of this.list
V.pushAt(int loc,int val)
V.inOrderPush(int val)
: adds single value to proper location in order to maintain order (ascending or descending)val = V.popFront()
: removes single value from front of listval = V.popRear()
: removes single value from rear of listval = V.popAt(int loc)
: removes single value from an indexed location if index between 0 and size of list -1
loc = V.find(int val)
: find location of item (index) if it existsval = V.popAt(int loc)
) : then use index to remove itemRun this code with your class and make sure you get same output. The example below is writing to stdout only. I want your test program to write to stdout AND a file called test.out
. Your name, date and course (Fall 2143) should be written at top of output file (with your code):
Example Output File (portion of)
Name Date Fall 2143 [25, 20, 18, 18, 20, 25] [11, 25, 33, 47, 51] [9, 11, 25, 27, 33, 47, 51, 63] [25, 20, 18, 18, 20, 25, 9, 11, 25, 27, 33, 47, 51, 63] etc...
Example Code Run
int x = 0; MyVector v1; v1.pushFront(18); v1.pushFront(20); v1.pushFront(25); v1.pushRear(18); v1.pushRear(20); v1.pushRear(25); v1.print();// [25, 20, 18, 18, 20, 25]int A[] = {11,25,33,47,51}; MyVector v2(A,5); v2.print();// [11, 25, 33, 47, 51] v2.pushFront(9); v2.inOrderPush(27); v2.pushRear(63); v2.print();// [9, 11, 25, 27, 33, 47, 51, 63] v1.pushRear(v2); v1.print();// [25, 20, 18, 18, 20, 25, 9, 11, 25, 27, 33, 47, 51, 63] x = v1.popFront(); x = v1.popFront(); x = v1.popFront(); v1.print();// [18, 20, 25, 9, 11, 25, 27, 33, 47, 51, 63]cout<
Enjoy 24/7 customer support for any queries or concerns you have.
Phone: +1 213 3772458
Email: support@gradeessays.com