Create a function named smallestCapital as follows: The function returns an integer. The function has 5 parameters: Two string arrays One integer array An ifstream object An integer for the length of the arrays The function should be coded as follows: If the ifstream object did not open the file, return a value of -1. Otherwise, use a while loop to read data from the file and store each data value into its corresponding array. The ifstream object must be used in the loop condition. Use any type of loop to find the index of the smallest population and return it.
Assume the <iostream>, <fstream>, and <string> headers have already been included and that main() looks like this:
(picture 1)
Each row of the capitals.txt file contains the following data, in this order:
- The city (string, one word)
- The state (string, one word)
- The population (integer)
Here are the exact contents of the "capitals.txt" file to copy:
Phoenix Arizona 1660272
Austin Texas 964254
Ohio Columbus 892553
Indianapolis Indiana 867125
Denver Colorado 716492
Boston Massachusetts 694583
Nashville Tennesseee 635710
Sacramento California 466488
Atlanta Georgia 420003
Honolulu Hawaii 359870
Create a function named smallestCapital as follows:
The function returns an integer.
The function has 5 parameters:
Two string arrays
One integer array
An ifstream object
An integer for the length of the arrays
The function should be coded as follows:
If the ifstream object did not open the file, return a value of -1.
Otherwise, use a while loop to read data from the file and store each data value into its corresponding array. The ifstream object must be used in the loop condition.
Use any type of loop to find the index of the smallest population and return it.
Rules:
Submit only the code you are asked to write. You do not have to create a main program or a function prototype.
The code you submit must still follow all C++ syntax rules and compile.
You must use the exact type of loop specified in each part that requires a loop.
The test conditions for all loops must contain a boolean expression with a comparison operator (==, <=, >=, and so on).
No break or continue statements are allowed.
You may create as many local variables in the function as you believe are needed.
will upvote!
Step by step
Solved in 2 steps with 2 images