Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

HDQUZ, please do not answer my tutoring questions. Complete the program using a function. The program should read all the values from the input file,

HDQUZ, please do not answer my tutoring questions.

Complete the program using a function.

The program should read all the values from the input file,

find the lowest value, and print the lowest value found.

*/

#include

#include

#include

using namespace std;

/* TODO: Write the declaration (prototype) for the function

- Name: GetLeast

Parameter(s): an ifstream called infile (pass by reference - uses the &)

Returns: an int, the lowest value found in the file

HINT: The ifstream should be opened in main, before calling this function

*/

//------------------------------------------------------------------------------

int main()

{

int smallestValue = INT_MAX; // Initialize smallest to maximum range

ifstream dataFile; // File input stream

const string filename = "data.txt"; // Input file name

cout << "Opening file...";

dataFile.open(filename.c_str()); // Open file

if (dataFile) // File opened OK?

{

cout << "file opened." << endl

<< "Begin searching for lowest value...";

/* TODO: Call function GetLeast, passing the dataFile ifstream variable

and assign the return value to the smallestValue variable.

*/

cout << "done. " << endl; // Print result

cout << "The lowest value found was "

<< smallestValue << endl;

}

else // Problem opening file

{

cout << "could not find or open file: " << filename

<< endl;

}

dataFile.close();

cout << " End Program. "

<< endl;

return 0;

}

//------------------------------------------------------------------------------

/* TODO: Define GetLeast()

Refer to the function prototype, above for parameter and

return type info.

PSEUDOCODE:

Declare two int variables (you decide on appropriate variable names):

* 1 variable to hold each value as it is read from file

* 1 variable to hold the lowest value read so far (initialize to INT_MAX)

Read the first value from the file into the appropriate local variable

Repeat while not at end of file

- Test to see if the new value is smaller than the lowest read so far

If yes, save the new value to the lowest so far variable

Read the next value from the file

End the repeat

Return the smallest value that was read

*/

//------------------------------------------------------------------------------

/* Sample program output:

Opening file...file opened.

Begin searching for lowest value...done.

The lowest value found was -9122

End Program.

Press any key to continue . . .

*/

How do i properly program this in C++ programming, please follow the TODOs as assigned.

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 Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions