I'm trying to do a program that takes two vectors and computes the alternating sum, appends the vectors, checks whether two vectors have the same elements in some order, ignoring multiplicities, and removes duplicates. Any help would be appreciated.

``````#include <iostream>
#include <vector>

using namespace std;

/*
Functions on Vectors.
*/

//computes the alternating sum of all elements in a vector.  Should be -2
int alternating_sum(vector<int> a)
{
?
}

//appends vector b after a.
vector<int> append(vector<int> a, vector<int> b)
{
?
}

//checks whether two vectors have the same elements,
//ignoring multiplicities
bool same_set(vector<int>a, vector<int> b)
{
?
}

//removes duplicates from vector a     ???don't know if this is right???
void remove_duplicates(vector<int>& a)
{
int x;
bool match;
for (unsigned int i=0; i<a.size(); i++)
{
x=a[i];
match=false;
for (unsigned int j=0; j<b.size()) && (!match); j++)
{
if (b[j]==x)
match=true;
}
if(!match)
return false;
}
return true;
}

void display_vector( string vector_name,  vector<int> a)
{
cout << vector_name << " contains the following data: \n";
for (int i=0; i<a.size(); i++)
cout<< a[i] << "  ";
cout<<"\n\n";
}

int main()
{
vector<int>  a(9);
vector<int>  b(7);

a = 1;
a = 4;
a = 9;
a = 16;
a = 9;
a = 7;
a = 4;
a = 9;
a = 11;

b = 11;
b = 11;
b = 7;
b = 9;
b = 16;
b = 4;
b = 1;

// test "alternating_sum" function:

cout << "The alternating sum of vector a is: ";

cout << alternating_sum (a)  << "\n\n";

//test "same_set" function

cout << "The elements of the vectors a and b form ";

if (!same_set(a, b)) cout << "not ";

cout << "the same set.\n\n";

//test "append" function:

display_vector ("Appending a after b generates a new vector that", append(b, a) );

//test "remove duplicates" function:

remove_duplicates(a);
display_vector ("The vector a without duplicates", a );

return 0;
}``````