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

All code with the ***...*** needs to be implemented!! Vectors. This lab is to be

ID: 3694420 • Letter: A

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



#include

using namespace std;

int main(){ vector v;

// inputing the numbers cout << "Enter numbers, 0 to quit: "; int num; cin >> num; while(num!=0){ vector::iterator ip=v.end(); v.insert(ip,num); cin >> num; }

// removing the minimum element

// initally, assume the first element is smallest vector::iterator toRemove=v.begin(); int min = *toRemove;

// start with the second element and iterate for(vector::iterator ip=toRemove + 1; ip < v.end(); ip++) if(min > *ip){ // found smaller element toRemove=ip; min = *ip; }

v.erase(toRemove); // removing the element to which toRemove points

sort(v.begin(),v.end()); // sorting elements

// printing the sorted numbers cout << "Your numbers sorted: "; for(vector::iterator ip=v.begin(); ip<<="" *ip="" "="" ";="" }="" endl;="" }

*2. Vectors, Object-Oriented.*

Re-implement the above functionality using the [LINK: http://vega.cs.kent.edu/~mikhail/classes/csi.s13/Labs/Lab12/vectorsoo.h] the following class definition.

#ifndef VECTORSOO_H_ #define VECTORSOO_H_

#include using std::vector;
class vectorsoo{ public: void addNumber(int); // adds number to the array void removeNumber(int); // deletes the number from the array void output(void); // prints the values of the array in sorted order
int vectorSize(void)const; // returns vector size
// note that the big three member functions are not needed // as vector class handles dynamic allocation properly // by itself
private: container;};

#endif /*VECTORSOO_H_*/






Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote