Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

home / study / engineering / computer science / questions and answers / all code

ID: 3695301 • Letter: H

Question

home / study / engineering / computer science / questions and answers / all code with the ***...*** needs to be implemented!! ...

Question

Edit question

All code with the ***...*** needs to be implemented!!

Vectors. This lab is to be done using Unix. To familiarize yourself with Unix, read this tutorial.

To prove that you used Unix tools, as part of your first project submission, you need to submit a typescript file with the record of at least one successful compilation of the second project programs below (the execution of the compiler on your source code file).

Create a project titled Lab12_Vectors. Implement the dynamically expanding and contracting container functionality described in previous labs using vectors. In the main() function, you may declare the vector to hold the integers input. Specifically, your program has to support this dialog:

Hint: use iterators for number removal. Refer to this code for example usage. ***http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/Lab12/iterators.cpp***

The typescript file should also be submitted.

Explanation / Answer

Given below are the code with comments to expalin the working of the code:

#include <iostream>

#include <vector>

#include <algorithm>

typedef vector<int> VEC;

//function declare//

int VectorFunc (VEC &v, int n);

int main(){

  

VEC v;

VEC::iterator ip;

int i;

int n;

bool Done;

char Choice;

//select choice and enter number//

for (Done = false; !Done; ) {

   cout << " Enter Operation [Add (A/a)OR Remove(R/r)]”;

cin >> Choice;

if (Choice == 'a' || Choice == 'A') {

   

cout << "Your Number=";

cin >> n;

v.push_back (n);

}

else if (Choice == 'r' || Choice == 'R') {

   

cout << "Your Number=";

cin >> n;

if((i = VectorFunc(v,n)) != 1) {

   

ip = v.begin ();

advance (ip, i);

v.erase (ip);

}

}

cout << "done [y/n]?";

cin >> Choice;

Done = (Choice == 'y' || Choice == 'Y'? true:false);

}

sort(v.begin(),v.end());

cout << endl;

for (i = 0; i < v.size(); i++)

cout << v.at(i) << " ";

}

//function for process//

int VectorFunc (VEC &v, int n){

   

int i;

VEC v;

for (i = 0; i < v.size() ; i++)

if (v.at(i) == n )

return i;

return 1;

}