Finish a C++ code. Assume the , , and 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) (picture 2, of the capitals.txt text) Text to copy for the capitals.txt file: 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.
Finish a C++ code.
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)
(picture 2, of the capitals.txt text)
Text to copy for the capitals.txt file:
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
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! Thank you

![### Sample C++ Program for Finding the Smallest State Capital by Population
```cpp
int main() {
ifstream inFile;
inFile.open("capitals.txt");
string city[10];
string state[10];
int population[10];
int here = smallestCapital(city, state, population, inFile, 10);
if (here == -1) {
cout << "File did not open." << endl;
} else {
cout << "Smallest state capital is " << city[here] << ", " << state[here]
<< " with population " << population[here] << endl;
}
inFile.close();
return 0;
}
```
### Explanation:
This C++ program is designed to find the smallest state capital by population. Here is a step-by-step explanation:
1. **Include Necessary Libraries:** The `ifstream` library is included to read from files.
2. **Open the File:** The program attempts to open a file named `capitals.txt`. This file is expected to contain information about state capitals, their states, and their populations.
3. **Declare Arrays:**
- `city[10]`: This array will hold the names of 10 cities.
- `state[10]`: This array will hold the names of 10 states.
- `population[10]`: This array will hold the population of each city.
4. **Find Smallest Capital:** The `smallestCapital` function (not shown in the provided code) is called. This function is supposed to scan through the cities, states, and populations arrays and return the index of the city with the smallest population.
5. **Check File Status:**
- If `smallestCapital` returns `-1`, it means the file did not open correctly. The program then outputs "File did not open."
- Otherwise, it prints the name of the smallest state capital, along with its state and population.
6. **Close File:** The program closes the file `capitals.txt` to free system resources.
7. **Return Statement:** The `return 0;` statement indicates that the program has executed successfully.
### Diagram and Graphs:
No diagrams or graphs are included in the provided code snippet. The primary focus of this code is to read data from a file, process it, and output relevant information based on the data.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fad3ee529-81b1-486a-8459-b4eea2f68af5%2F0eeee817-aa58-4291-b1c3-d93a43d093e1%2Fe7yzfsx_processed.png&w=3840&q=75)

Step by step
Solved in 2 steps with 3 images









