Please submit one zip file containing all source code, header, and output files. Exercise 1: 30 Points (Duplicate Elimination with vector) Use a vector to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the vector only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Begin with an empty vector and use its pushback function to add each unique value to the vector. SAMPLE RUN: Enter an integer: 105 Enter an integer: 5 Enter an integer: 10 Enter an integer: 11 Enter an integer: 11 Enter an integer: 12 Enter an integer: 13 Enter an integer: 14 Enter an integer: 15 Enter an integer: 15 Enter an integer: 16 Enter an integer: 17 Enter an integer: 18 Enter an integer: 19 Enter an integer: 20 Enter an integer: 21 Enter an integer: 22 Enter an integer: 23 Enter an integer: 24 Enter an integer: 25 Enter an integer: 26
Enter an integer: 27
Enter an integer: 28
Enter an integer: 29
Unique values in the vector are:
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 294

Respuesta :

Answer:

The program in C++ is as follows:

#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

int main(){

   vector <int> inTs;

   int num;

   int count = 0;

   int temp; int chk = 0;

   while(count < 20){

       temp = count;

       cout<<"Enter an integer: ";

       cin>>num;

       if(num>=10 && num<=200){

           for(int i = 0; i<count;i++){

               if(num == inTs.at(i)){ chk = 1; break;}

           }

       if(chk == 0){ inTs.push_back(num); count++; }

       else{ count = temp; }

       chk = 0;

       }

   }

   for(int i=0; i < 20; i++){  cout << inTs.at(i) << ' ';    }

   return 0;

}

Explanation:

See attachment for complete code where comments are used as explanation

Ver imagen MrRoyal
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE