Description of the data file ( data.txt) - Format of the table: Country Year Lif
ID: 3617643 • Letter: D
Question
Description of the data file (data.txt)
- Format of the table:
Country Year Life_exp_both_sexes Life_exp_male Life_exp_female
Life_exp: Life expectancy
- The format of the table has been simplified so that all country names consist of only a single word.
- You may assume that the number of countries in the data file never exceeds 500.
Option 1: If the user selects 1, then the program asks the user to enter the filename of the data file. If the file exists, then the program loads the data into an array of structured data (struct) and prints the number of entries; otherwise, it prints out an error message. After that, the program displays the main menu again.
1. Load data from file
Please enter the data filename: wrong.txt
Error in opening wrong.txt
1. Load data from file
Please enter the data filename: data.txt
222 entries read successfully
Option 2: If the user selects 2:
- If the data has been read by the program, then the program asks the user to enter a country name. If the input country name is found (use the binary search algorithm), the program displays the corresponding data; otherwise, it prints out a message saying that the country is not found.
- If the data has not been read by the program, then the program asks the user to load data from file first.
- After that, the program is back to the main menu.
Suppose the user has not selected option 1 (has not read the data from file):
2. Search data by country
Please enter a country name: Canada
Data has not been loaded.
Please load data from file first (select option 1).
Suppose the user has selected option 1 (has read the data from file):