(Duplicate Elimination)Use a one-dimensional array 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 array only if it is not a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.
What will be an ideal response?
```
#include
using namespace std;
int main()
{
const int SIZE = 20; // size of array
int a[ SIZE ] = {};
int subscript = 0;
int duplicate;
int value; // number entered by user
cout << "Enter 20 integers between 10 and 100:\n";
// get 20 nonduplicate integers in the range between 10 and 100
for ( int i = 0; i < SIZE; )
{
duplicate = 0;
cin >> value;
// validate input and test if there is a duplicate
if ( value >= 10 && value <= 100 )
{
for ( int j = 0; j < subscript; j++ )
{
if ( value == a[ j ] )
{
duplicate = 1;
break;
} // end if
} // end for
// if number is not a duplicate, enter it in array
if ( !duplicate )
{
a[ subscript++ ] = value;
++i;
} // end if
else
cout << "Duplicate number.\n";
} // end if
else
cout << "Invalid number.\n";
} // end for
cout << "\nThe nonduplicate values are:\n";
// display array of nonduplicates
for ( int i = 0; i < SIZE; i++ )
cout << a[ i ] << ' ';
cout << endl;
} // end main
```
You might also like to view...
How do you know where to find a Web service?
What will be an ideal response?
When you create a dump file, you'll need a(n) ____ tool to open and read the file.
A. sector editing B. application development C. debugging D. translating
Fax machines can be considered part of VoIP
Indicate whether the statement is true or false
View that enables the user to create and modify a table design.
What will be an ideal response?