Computer Project #2 Solution

$40.00 $34.00

Assignment Overview This assignment focuses on C shell programming in a Linux environment. You will design and implement a set of C shell scripts which are used to produce reports about census data. It is worth 30 points (3% of course grade) and must be completed no later than 11:59 PM on Thursday, 1/28. Assignment…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Assignment Overview

This assignment focuses on C shell programming in a Linux environment. You will design and implement a set of C shell scripts which are used to produce reports about census data.

It is worth 30 points (3% of course grade) and must be completed no later than 11:59 PM on Thursday, 1/28.

Assignment Deliverables

The deliverables for this assignment are the following files:

proj02.script1 — the C shell script which produces Report #1 proj02.script2 — the C shell script which produces Report #2 proj02.script3 — the C shell script which produces Report #3 proj02.script4 — the C shell script which produces Report #4

Be sure to use the specified file names and submit them for grading via the CSE Handin system before the project deadline.

Assignment Specifications

The following files are available on the CSE Linux system:

/user/cse325/Projects/project02.data

/user/cse325/Projects/project02.headers

The first file contains the list of cities and townships (census units) within each county in Michigan. For each census unit, the file contains the total population recorded during the 2010 United States Census. The first five lines of that file are shown below:

Acme township

| Grand Traverse |

4375

East Lansing city

| Clinton

|

1969

Bois Blanc township

| Mackinac

|

95

East Lansing city

| Ingham

|

46610

Newark township

| Gratiot

|

1093

Note that some cities appear more than once in the data file (for example, East Lansing). Multiple entries indicate that parts of the city are located in more than one county. For the purposes of this assignment, you may treat each entry in the data file as a unique record (you don’t need to combine multiple entries for a given city).

The second file contains column headers which are formatted for use with this data:

Census Unit | County | Population ————————————-+—————-+———–

You will design and implement four C shell scripts which are capable of producing the reports described below.

You may use UNIX utility programs (such as “echo”, “cat” and “grep”) inside your C shell scripts to generate the reports, but you may NOT use an editor program to edit any of the reports.

All four C shell scripts will write their output to standard output. You may use piping within your scripts to connect the output of one utility program to the input of another, but your scripts may not create any temporary files.

  1. The C shell script “proj02.script1” will produce a report about the census units within a specified county. The second command-line token is an identifier for the specified county (for example, “Ingham” or “Grand Traverse”).

The report will include an appropriate title, the column headers described above, and all of the census units in a specified county. The census units will be sorted by population (from lowest to highest); if more than one census unit has the same population, the report will list those places alphabetically.

  1. The C shell script “proj02.script2” will produce a series of individual reports about the census units in a list of specified counties. The second and each subsequent command-line token is an identifier for a specified county.

Each report will include an appropriate title, the column headers described above, and all of the census units in a specified county. The census units will be sorted by population (from lowest to highest); if more than one census unit has the same population, the report will list those places alphabetically. Individual reports will be separated by exactly two blank lines.

3. The C shell script “proj02.script3” will produce a report about the N census units with the largest population.

The report will include an appropriate title, the column headers described above, and the population for the top N census units (where N is a positive integer) from a subset of the places in Michigan, sorted by population (from highest to lowest). If more than one census unit has the same population, the report will list those places alphabetically.

Your C shell script will accept two arguments: a positive integer number that specifies the value of N, and a character string which specifies the subset of census units which should be included in the report. This character string will be “A” (meaning that all places should be included), “C” (meaning that only places which are cities should be included), or “T” (meaning that only places which are townships should be included).

4. The C shell script “proj02.script4” will produce a report about the N census units with the largest population.

The report will be identical to Report #3 described above. However, your C shell script which produces the report will include error checking.

If the user supplies an invalid number of arguments, your C shell script will display an appropriate error message.

If the user supplies an invalid value as the second token (something other than an integer value which is greater than zero), your C shell script will display an appropriate error message.

If the user supplies an invalid character string as the third token (something other than “C”, “T” or “A”), your C shell script will display an appropriate error message.

Assignment Notes

  1. The first line of each of your C shell scripts must be the line shown below (where the ‘#’ character is in the first column):

#!/bin/tcsh -f

  1. You may not copy the files containing the data or the column headers into your account. Instead, use absolute pathnames in your C shell scripts to access the files stored under the “/user/cse325/Projects” directory.

  1. The following are examples of valid commands which use the C shell scripts:

proj02.script1 Wayne

proj02.script2 “Grand Traverse” Gratiot Wexford

proj02.script3 25 A

proj02.script4 10 C

  1. In a “foreach” control construct in a shell script, the “:q” modifier can be used to retain the quoting for an argument list. Here is a simple example:

<129 arctic:~ > cat showargs

#!/bin/tcsh -f

foreach item ($argv[*]:q)

echo $item

end

<130 arctic:~ > showargs aaa bbb “ccc ddd” eee

aaa

bbb

  1. ddd

eee

Computer Project #2 Solution
$40.00 $34.00