Ive been at it for quite a while...possibly because my understand of C++ is not very good or maybe i just suck at it.

Well here it goes,

Problem:

Write the following function, including a main() function, in index.cpp:

vector<int> noDupeIndex(vector<int> indexlist)

which function returns the integers in indexlist, with duplicate indices removed.

For example, if the vector indexlist is: 1 4 9 16 9 7 4 9 11, then the

function noDupeIndex would return the vector: 1 4 9 16 7 11.

Solution:

This is what i have so far...

#include <iostream> #include <vector> using namespace std; vector<int> noDupeIndex(vector<int> indexlist) { vector<int> b(indexlist.size()); //Defines the size of the new vector int i = 0; //Variable used to count the entries in vector indexlist int j = 0; //Variable used to count the entries in vector B //While i is less than the total number of entries in vector indexlist the following loop will assign entry n from vector indexlist to entry n of //vector B. Each time it does this it addes 1 to the entry counters for the respective vectors indexlist and B. for (int i = 0; i < indexlist.size(); i++) { b[j] = indexlist[i]; j++; } return b; } int main() { //This variable is a counting variable used later to manage a loop. int x; //Defining vector size and entries for indexlist vector<int> indexlist(9); indexlist[0] = 1; indexlist[1] = 4; indexlist[2] = 9; indexlist[3] = 16; indexlist[4] = 9; indexlist[5] = 7; indexlist[6] = 4; indexlist[7] = 9; indexlist[8] = 11; vector<int> b = noDupeIndex(indexlist); cout << "Result of no duplicate index is: "; // While the counting variable is less than the total length of vector B, the following loop displays that corresponding entry. //Everytime the loop is run, a integer of 1 is added to the counter. Thus each proceeding time, a new corresponding entry is displayed //until there are no more entries left. for (x = 0; x < b.size(); x++) cout << b[x] << " "; cout << "\n"; return 0; }