Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 1 5 . 9 CIST 2 3 6 2 Programming Assignment: Building a Vector Class Replica Overview This programming assignment extends the idea that

(15.9 CIST2362 Programming Assignment: Building a Vector Class Replica
Overview
This programming assignment extends the idea that we had for SimpleVectorOfints to where you will
create a replica of the std:vector class. The std: : vectior class is what you have been using for a while
now, and it is based on C++ Templates and is considered a container class.
It will be helpful to consult the
cplusplus.com reference for the std: : vector class as you work on this
assignment. The left-navigation on this reference has the member functions. You can read the details about
the member functions and there is even a way to try some sample test code using the std:vector class. This
could be helpful as you try to replicate the behavior in your class.
File Structure
The main.cpp is to be used for testing. You can put in any code in there that you want. I suggest creating
functions for your test as it makes it easier to run the tests that you want. Your vector class will be in the
CIST2362 namespace. So it can be accessed as CIST2362: : vector when you are testing it. This helps
deconflict the vector name from the std: : vector. For example, in your main. cpp, you might have:
CIST2362: :vectorhhh>T&50%T&
************************************
write In c++ please need code the for vector.h here is the code
Main.cpp
#include
#include
#include "vector.h"
using namespace std;
int main()
{
/*
Type your test code here.
You will not be submitting this code. It's only for testing.
*/
return 0;
}
Vector.h
// vector class template
#ifndef Vector_Vector_h
#define Vector_Vector_h
#include
#include // Needed for bad_alloc exception
#include // Needed for the exit function
#include
namespace CIST2362{
template
class vector {
private:
T *aptr; // To point to the allocated array
unsigned long arraySize; // Number of elements in the array
unsigned long arrayCapacity; // number of memory locations available to the vector
// increase capacity
void increaseCapacity(unsigned long);
public:
// Default constructor
vector();
// Constructor declaration
vector(unsigned long);
// Resize the vector - changes the size attribute
void resize(unsigned long n);
// Resizes the vector and initializes the unused locations - updates the size attribute
void resize(unsigned long n, const T &val);
// Copy constructor declaration
vector(const vector &);
// Destructor declaration
~vector();
// Accessor to return the array size
unsigned long size() const;
// Accessor to return the array capacity
unsigned long capacity() const;
// Accessor to test empty status
bool empty() const;
// Accessor to return a specific element
T &at(unsigned long position);
// Overloaded [] operator declaration
T &operator[](const unsigned long &);
// back element of the vector
T &back();
// front element of the vector
T &front();
void push_back(T); // New push_back member
T pop_back(); // New pop_back member
// insert element at position
int insert(unsigned long, const T &);
// erase a range of values
void erase(unsigned long, unsigned long);
// erase one element at a position
void erase(unsigned long);
};
/* This is where your method definitions will be written. This default constructor
* the first method you need to complete. To compile the program, you should create
* empty stubs for each of the declared methods.
*/
template
vector::vector(){
}
}
#endif
post results of completed code please.
image text in transcribed

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

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

More Books

Students also viewed these Databases questions

Question

Detailed note on the contributions of F.W.Taylor

Answered: 1 week ago

Question

2. Why has the conflict escalated?

Answered: 1 week ago

Question

1. What might have led to the misinformation?

Answered: 1 week ago