Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Donald A. Carpenter Fred R. McFadden

1st Edition

8178088045, 978-8178088044

More Books

Students also viewed these Databases questions

Question

love of humour, often as a device to lighten the occasion;

Answered: 1 week ago

Question

orderliness, patience and seeing a task through;

Answered: 1 week ago

Question

well defined status and roles (class distinctions);

Answered: 1 week ago