Computer Sciences Department logo

CS 368-1 (2011 Summer) — Day 7 Homework

Due Friday, July 22, at the start of class.

Description

Read two input data files containing data about the countries of the world and store the data into useful data structures. Then, ask for user input and print a simple report based on the stored data.

Details

Your script should be divided into two main parts:

  1. Reading and storing the country data
  2. Reporting on that data

Phase I: Reading and Storing Data

There are two separate data files containing country data. The first file is called input-07-country.txt, and looks like this:

ABW : Aruba : Aruba : Latin America & Caribbean
ADO : Andorra : Principality of Andorra : Europe & Central Asia
AFG : Afghanistan : Islamic State of Afghanistan : South Asia
AGO : Angola : People's Republic of Angola : Sub-Saharan Africa
ALB : Albania : Republic of Albania : Europe & Central Asia

That is, there are 4 data fields, separated by the string “ : ” (space - colon - space):

The second data file is called input-07-population.txt, and looks like this:

ABW : 1960 : 49205
ABW : 1961 : 50244
ABW : 1962 : 51258
ABW : 1963 : 52224
ABW : 1964 : 53117

There are 3 data fields, separated by the string “ : ” (space - colon - space):

Read both data files and store all of the data in well-considered data structures. Some hints:

Phase II: Reports

Now that you have data, we can analyze it a bit and produce reports based on user input.

Note: Pick just one of the following reports! They are listed below in roughly increasing order of difficulty.

Report 1: World Population for a Year

Ask the user for a year, the calculate the total world population for that year. Sample output:

Calculate world population for what year? 1970
World population in 1970 was 3665297114 (202 countries).

Calculate world population for what year?

Report 2: Population Growth for a Country

Ask the user for a country code, start year, and end year. Calculate and display the population growth in that country from the start year to end year, both as an absolute amount and percentage growth; display the short or long name for the country, not the code. Sample output:

Calculate population growth for what country code? JPN
Starting in what year? 1970
Ending in what year? 2000
From 1970-2000, Japan grew by 22525000 (21.6%).

Calculate population growth for what country code?

Report 3: Top Population Growth

Ask the user for a start year and end year. Calculate and display the top N (5–10 is best) countries based on growth (either absolute growth or percentage growth, your pick). Display short or long names for countries, not codes. Sample output:

Starting in what year? 1970
Ending in what year? 2000
From 1970-2000, the following countries grew the most:
  468354000  India
  444330000  China
   88359301  Indonesia
   78183086  Brazil
   77473000  Pakistan
   77120000  United States
   71588515  Bangladesh
   68374892  Nigeria
   47370000  Mexico
   41122025  Philippines

Starting in what year?

Extra Challenges

Reminders

Do the work yourself, consulting reasonable reference materials as needed; any reference material that gives you a complete or nearly complete solution to this problem or a similar one is not OK to use. Asking the instructors for help is OK, asking other students for help is not.

Hand In

A printout of your code on a single sheet of paper. Be sure to put your own name in the initial comment block of the code. Identifying your work is important, or you may not receive appropriate credit.