Question: Using Vectors to Process an Array of Numbers Continuing with the first exercise, write a program to read in any number of real numbers from

Using Vectors to Process an Array of Numbers Continuing with the first exercise, write a program to read in any number of real numbers from the command line, using a vector to save such numbers, and printing them out afterwards. Following this scan the vector and determine the smallest number and build a new vector of size N-1 removing one of the smallest numbers. The following shows a sample of inputs and outputs:

$./lab4 88 62.4 5 6 8 5 92.1 63.12 Original array :

Numbers[0] : 88

Numbers[1] : 62.4

Numbers[2] : 5

Numbers[3] : 6

Numbers[4] : 8

Numbers[5] : 5

Numbers[6] : 92.1

Numbers[7] : 63.12

New array with smallest element removed :

Numbers[0] : 88

Numbers[1] : 62.4

Numbers[2] : 6

Numbers[3] : 8

Numbers[4] : 5

Numbers[5] : 92.1

Numbers[6] : 63.12

Hint: your code could look like the following:

// lab4.cpp #include  #include  #include  using namespace std; int smallestIndex ( vector  v ) { double min = 10000.0; int j = 0; .......... return j; } void print ( vector  v ) { for ( int i = 0; i < v.size(); i++ ) { ............... } } int main( int argc, char *argv[] ) { vector v; if ( argc < 2 ) { cout << "Usage: " << argv[0] << " number1 number2 ...." << endl; exit ( 0 ); } int N = argc - 1; for ( int i = 0; i < N; i++ ) v.push_back ( atof ( argv[i+1] ) ) ; cout << "Original array : " << endl; print ( v ); int j = smallestIndex ( v ); vector  v1; ............. cout << "New array with smallest element removed : " << endl; print ( v1 ); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!