In the UK from 1994 to 2014 there were 2166 UFO Sighting Reported. Details of these sightings are included in the ufo_sighting.csv file.
The contents of the file is in chronological order, the most recent sightings is at the bottom. This file has been imported into your program using the ImportFile() function - there is no need for you to edit this function
In this project you are going to implement a range of Functions & Procedures that do the following ...
Calculate & Display the Number of Sightings in Each Country.
Find & Display the Number of Sightings in Each Year.
Display the details of any sightings for a specific location.
The ufo_sighting.csv file contains the sightings for each country - England, Scotland, Wales & Northern Ireland.
You are required to implement the Functions & Procedures that will calculate and then display the number of sightings for each country within the United Kingdom.
TOP LEVEL DESIGN
CountSightings()
Count the number for sightings for a specified country.
IN: country[], specifiedCountry
OUT: numSightings
DisplaySightings()
Display the number of sightings for specific country.
IN: specifiedCountry, numSightings
OUT:
Attempt to implement these two Functions/Procedures, if you are not sure use the Hints below to help.
The output of the program should be as follows ...
There were 1824 sightings in England
There were 201 sightings in Scotland
There were 117 sightings in Wales
There were 24 sightings in Northern Ireland
💡 Hint: CountSightings() Pseudocode
CREATE CountSightings FUNCTION (countryArray, specifiedCountry)
count = 0
loop through countryArray with counter
if country in countryArray matches specifiedCountry
increase count by 1
end if
end loop
RETURN count
💡 Hint: DisplaySightings() Pseudocode
CREATE DisplaySightings FUNCTION (specifiedCountry, numSightings)
DISPLAY 'there were ' & numSightings & ' in ' & specifiedCountry
🔍 Solution: Main Program (Easier - More Code)
date, country, location, shape, description = ImportFile()
engSightings = CountSightings(country, 'England')
DisplaySightings('England',engSightings )
# Repeat the above for Scotland, Wales & Northern Ireland
🔍 Solution: Main Program (More Complicated - Less Code)
def CountAllCountries(country):
specifiedCountry = ['England', 'Wales', 'Scotland', 'Northern Ireland']
for counter in range (0, 4):
sightings = CountSightings(country, specifiedCountry[counter])
DisplaySightings(specifiedCountry[counter],sightings )
## MAIN PROGRAM
date, country, location, shape, description = ImportFile()
CountAllCountries(country)
The ufo_sighting.csv file contains sightings from 1994 to 2014 in chronological order, this mean sightings from 1994 are first.
You are required to implement a function that will identify the number of sightings in each year. The output of the program will look something like this ...
1994: 11
1995: 16
1996: 27
1997: 40
1998: 43
1999: 62
...
...
TOP LEVEL DESIGN
CountYearSightings()
Count the sightings each year.
IN: date[]
OUT:
Note: the date is stored in the dd/mm/yyyy format, so a sub-string will be required to extract the year.
To implement this function you will be required to look at each date. If a date matches the following date, then increment the count by 1. If it doesn't match, display the date and the count, then reset it.
Attempt to implement this function, if you are not sure use the Hint below to help.
💡 Hint: CountYearSightings() Pseudocode
CREATE CountSightings FUNCTION (dateArray)
count = 0
loop through dateArray[] with counter
currentDate = date at counter in dateArray[]
currentYear = substring to extract year from currentDate
nextDate = date at counter+1 in dateArray[]
nextYear = substring to extract year from nextYear
if currentYear = nextYear then
add 1 to count
else
print currentYear & count
reset count
To Follow