chegg wont let me upload txt files so this is the contents Write an awk script t
ID: 3778041 • Letter: C
Question
chegg wont let me upload txt files so this is the contents
Write an awk script that will parse the data, and for each county, print the county name, the population per square mile of land, and the percentage of the county that is water. (Note that the total area of the county is the sum of the land and water areas At the end, your script should print the county name and the value for the following criteria: Highest population density Lowest population density Highest percentage of land Lowest percentage of land So, for example, you might print out "Highest population density: Adams County, 9999 people/square mile"Explanation / Answer
#! /usr/bin/awk -f
#used for the highest population density
BEGIN {
FS = " "
maxPopulation = 0
maxPopCounty = "Addams"
#used for the highest percentage of land
maxLand = 0
maxLandCounty = "Addams"
#used for lowest population density
minPopulation = 1000000000
minPopCounty = "Addams"
#used for lowest percentage of land
minLand = 10000000
minLandCounty = "Addams"
waterPercentage = 0
}
{
print $1 " " $2 " " $3 " " $4
if ( maxPopulation < $2 ){
maxPopulation = $2
maxPopCounty = $1
}
if ( maxLand < waterPercentage ){
maxLand = landPercentage
maxLandCounty = $1
}
if (minPopulation > $2 ){
minPopulation = $2
minPopCounty = $1
}
if (minLand > waterPercentage){
minLand = waterPercentage
minLandCounty = $1
}
}
END {
print "Highest population density: " maxPopCounty " County , " maxPopulation " people/square mile"
print "Lowest population density: " minPopCounty " County , " minPopulation " people/square mile"
print "Highest water percentage of land: " maxLandCounty " County , " maxLand " percent water"
print "Lowest water percentage of land: " minLandCounty " County , " minLand " percent water"
}
census.txt
Adams County 16428 4.73 1924.96
Asotin County 20551 5.34 635.34
Benton County 142475 57.03 1703.09
Chelan County 66616 72.25 2921.37
Clallam County 64525 930.89 1739.45
Clark County 345238 27.99 628.22
Columbia County 4064 4.71 868.81
Cowlitz County 92948 27.69 1138.64
Douglas County 32603 28.17 1820.53
Ferry County 7260 53.48 2203.98
Franklin County 49347 22.95 1242.40
Garfield County 2397 7.64 710.55
Grant County 74698 110.23 2681.06
Grays Harbor County 67194 307.55 1916.89
Island County 71558 308.95 208.43
Jefferson County 25953 369.29 1814.23
King County 1737034 180.48 2126.04
Kitsap County 231969 170.01 395.97
Kittitas County 33362 35.93 2297.19
Klickitat County 19161 31.80 1872.37
Lewis County 68600 28.63 2407.64
Lincoln County 10184 28.51 2311.21
Mason County 49405 89.97 961.06
Okanogan County 39564 47.09 5268.07
Pacific County 20984 290.52 932.97
Pend Oreille County 11732 25.05 1400.27
Pierce County 700820 127.58 1678.91
San Juan County 14077 446.15 174.92
Skagit County 102979 185.33 1735.14
Skamania County 9872 27.42 1656.44
Snohomish County 606024 107.35 2089.06
Spokane County 417939 17.09 1763.64
Stevens County 40066 62.34 2478.30
Thurston County 207355 46.62 727.02
Wahkiakum County 3824 22.45 264.24
Walla Walla County 55180 28.74 1270.51
Whatcom County 166814 384.02 2119.53
Whitman County 40740 18.23 2159.37
Yakima County 222581 15.38 4296.23
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.