Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

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!

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;
}
expand button
Transcribed Image Text: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; }
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY