question archive (Vector class is provided at below)Check for proper indentation as questions will receive a mark of 0 if the proper indentation is not done or instructions for completing questions are not followed
Subject:Computer SciencePrice: Bought3
(Vector class is provided at below)Check for proper indentation as questions will receive a mark of 0 if the proper indentation is not done or instructions for completing questions are not followed. Copy only the declaration of your Vector class. Be careful that you do not include the implementation as that would show that you do not know the difference and will lead to the mark being halved for this question.
------------------------- Start of your template Vector.h declaration only------------------------
What is your source of this answer? _______
Remove all Doxygen comments before copy/paste and then check for correct indentation and case sensitivity.
-------------------------End of your template Vector.h declaration only -------------------------
a. Develop an efficient approach/algorithm where your Vector data structure would store all data, including duplicated data, using as little memory as possible. Note that storing each duplicated data in its own memory location is not memory efficient. Your approach/algorithm must not change the Vector data structure itself (do not change Vector.h). Use numerical examples to explain your approach/algorithm.
------------------Start: Explanation of your efficient approach ------------------
------------------End: Explanation of your efficient approach ------------------
b. Given n data items, suppose that the number of unique data items is represented by the letter u and the number of duplicates is represented by the letter d, derive an algebraic relationship between n, d and u that would specify the situation where the data structure is being used in a memory efficient way. Show your working with explanation.
------------------Start: derivation of relationship between n, d and u for an efficient usage of data structure ------------------
------------------End: derivation of relationship between n, d and u for an efficient usage of data structure ------------------
c. Write a C++ program that uses your template Vector class to demonstrate your memory efficient approach. Use numerical data that comes from a data file called data.txt. In the designated space below, write your answer. Build and run in Codeblocks first. Check indentation and capitalisation when copying here from Codeblocks.
----------------Start: C++ demonstration of memory saving scheme ------------------
Demonstration code including main routine and any other data structure/type:
-----------------End: C++ demonstration of memory saving scheme ------------------
#ifndef VECTOR
#define VECTOR
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Vector{
public:
Vector()
{
m_data = new T[10];
m_size = 10;
m_current = -1;
}
Vector(int s)
{
m_data = new T[s];
m_size = s;
m_current = -1;
}
void push(T e)
{
m_current++;
if (m_current == m_size)
{
int new_size = m_size * 1.5;
T *m_data_resize = new T[new_size];
for (int i = 0; i < m_size; i++)
{
m_data_resize[i] = m_data[i];
}
m_size = new_size;
delete [] m_data;
m_data = m_data_resize;
}
m_data[m_current] = e;
}
void pop(T &e)
{
e = m_data[m_current];
m_current--;
}
T selectAt(int i)
{
return m_data[i];
}
int GetSize()
{
return m_size;
}
int GetCurrent()
{
return m_current;
}
private:
T *m_data;
int m_size, m_current;
};
#endif