(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
```
Enter 20 integers between 10 and 100:
10
5
Invalid number.
20
30
40
50
60
70
80
90
100
110
Invalid number.
10
Duplicate number.
11
22
33
44
55
66
77
88
99
45
The nonduplicate values are:
10 20 30 40 50 60 70 80 90 100 11 22 33 44 55 66 77 88 99 45

Computer Science & Information Technology

You might also like to view...

Answer the following statements true (T) or false (F)

1. A child process is created using the spoon function 2. A child process is created as a copy of the parent process 3. It is not possible to execute another program from within a process 4. Pipes can be used to communicate between processes on different CPU’s. 5. Threads within a process share a common memory space. [

Computer Science & Information Technology

The default importance level for all new messages is ____ importance.

A. low B. high C. normal D. urgent

Computer Science & Information Technology

____ software allows a user to access all of the possible functions of a personal computer workstation from a mobile or remote location.?

A. ?Network monitoring B. ?Sniffer C. ?Remote access D. ?Antispyware

Computer Science & Information Technology

An interface standard can consist of four parts, or components, all of which reside at the ____ layer.?

A. ?network B. ?data link C. ?physical D. ?transport

Computer Science & Information Technology