Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this in C++ Class Attributes: Node: A private, embedded struct. Members: value - stores the integer being stored in the MyVector object. next -

Write this in C++

image text in transcribed

Class Attributes:

Node:

A private, embedded struct.

Members:

  • value - stores the integer being stored in the MyVector object.
  • next - stores the memory address of the next node of the linked list.

Variables:

  • head - a Node pointer that stores the memory address of the first node in the linked list.
  • tail - a Node pointer that stores the memory address of the last node in the linked list.

Methods:

  • constructor - initializes head and tail to nullptr.
  • destructor - frees all memory used by the list.
  • push_back - Creates a new node, stores it's argument in the node, and appends it to the list.
  • pop_back - if the list isn't empty (head == nullptr), removes the last node from memory. Throws an exception otherwise. The exception is a c-string: "EMPTY VECTOR".
  • at - uses it's argument as a subscript for the MyVector. Returns the value from that corresponding node. It's return type is an integer reference (int&). Throws an exception if the argument is an invalid index. The exception is a c-string: "OUT OF BOUNDS". If the MyVector object is empty, throws "EMPTY VECTOR" exception.
  • clear - removes all nodes from memory, and sets head and tail back to nullptr.
  • size - counts and returns the number of nodes in the list.
  • insert - inserts new value i before position pos in the MyVector list. So, if the list contained the values : 8 6 7 and the method was invoked as: v.insert(2, 9) then the list would be updated to: 8 6 9 7 Throws an exception "OUT OF BOUNDS" if an invalid position is specified.

None of the above methods interacts with the user in any way. You are not writing a program, just a class in it's own header file.

Place the class declaration in it's own header file named MyVector.h. Place the method definitions in it's own file named MyVector.cpp.

Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use an unordered, pointer-based linked list to store a collection of integers. UML Diagram: MyVector Node value: int next Node -head: Node tail: Node +MyVector) +-MyVector) push backin): void pop back() void at(i: int): int& +clear): void size(int +insert(pos: int, i int): void

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

Computer Aided Database Design

Authors: Antonio Albano, Valeria De Antonellis, A. Di Leva

1st Edition

0444877355, 978-0444877352

More Books

Students also viewed these Databases questions

Question

What is the preferred personality?

Answered: 1 week ago