CMSC 201
Programming Project Three
Maryland Counties
Out: Tuesday 3/27/01
Due: Before Midnight, Sunday 4/8/01
The design document for this project,
design3.txt ,
is due: Before Midnight, Sunday 4/1/01
|
The Objective
The objective of this assignment is to give you practice with project and
function design. It will also give you an opportunity to work with structures,
an array of structures, sorting, searching, pointers, passing by reference,
and some formatted printing.
The Background
I have been provided with some data about Maryland's counties and Baltimore
City. The data include the counties' area, population in 1990 and 1980,
personal income, number of votes cast for president in 1992 and the percentage
of those votes that were Democratic, Republican or votes for Perot, who ran as
an independent candidate that year.
I have the information in a data file called p3counties.dat, but it
does not contain all of the information that I would like to see.
The file contains the following fields for each county:
county name
area (in square miles)
population in 1990
population in 1980
personal income (in thousands of $)
votes cast for President in 1992
percentage of Democratic votes for President in 1992
percentage of Republican votes for President in 1992
percentage of votes for Perot for President in 1992
You can view the p3counties.dat file to examine
its contents and see its format.
You should copy this file into your account by using the following command:
cp /afs/umbc.edu/users/s/b/sbogar1/pub/cs201/P3Data/p3counties.dat .
The Task
Design and code a project that will allow you to read in the information from
the p3counties.dat file using UNIX redirection, manipulate it to be in the
desired form, and produce a chart that looks like the one shown below:
Population Pop Votes % % %
County Area 1990 1980 growth Income 1992 dem. rep. perot
-------------------------------------------------------------------------------
Allegany 425 74946 80548 -5602 1108188 30595 37.6 45.3 16.6
Anne_Arundel 416 427239 370775 56464 9776730 185634 37.0 43.9 19.0
Baltimore 599 692134 655615 36519 16286479 323220 44.4 39.2 16.0
Baltimore_City 81 736014 786741 -50727 12695941 245091 75.8 16.6 7.1
Calvert 215 51372 34638 16734 1136375 23249 37.1 43.1 19.4
Caroline 320 27035 23143 3892 383996 8459 33.4 45.6 20.4
Carroll 449 123372 96356 27016 2733498 54930 28.1 51.7 20.0
Cecil 348 71347 60430 10917 1344514 27319 37.5 39.5 22.4
Charles 461 101154 72751 28403 1970029 38454 37.7 45.0 16.9
Dorchester 558 30236 30623 -387 515583 10957 35.9 45.0 18.3
Frederick 663 150208 114792 35416 3020111 64691 33.8 48.4 17.6
Garrett 648 28138 26490 1648 371642 10580 27.0 54.0 18.8
Harford 440 182132 145930 36202 3842573 80687 33.7 45.1 21.1
Howard 252 187328 118572 68756 5217970 99798 44.9 38.7 16.2
Kent 279 17842 16695 1147 344391 7628 40.5 40.6 18.5
Montgomery 495 757027 579053 177974 22941256 362613 55.1 33.0 11.6
Prince_George's 486 729268 665071 64197 14321200 256859 65.7 24.5 9.1
Queen_Anne's 372 33953 25508 8445 730808 14514 32.2 47.1 20.4
Somerset 327 23440 19188 4252 280171 7936 40.4 43.5 15.5
St._Mary's 361 75974 59895 16079 1277134 25085 35.6 45.8 18.1
Talbot 269 30549 25604 4945 774426 13708 33.9 49.4 16.3
Washington 458 121393 113086 8307 1977145 46208 35.7 47.6 16.3
Wicomico 377 74339 64540 9799 1238240 30272 37.9 44.8 17.0
Worcester 473 35028 30889 4139 665516 16559 36.5 43.7 19.7
and give a summary of the total population of Maryland in 1980 and 1990 and
show the total population growth for Maryland over that 10 year period.
Then sort the data in descending order by growth and produce another chart
with the information in that order.
The Specifications
- You must use the following structure definition and typedef:
typedef struct county
{
char name[MAX];
int area;
int pop90;
int pop80;
int popGrowth;
int income;
int votes;
float percentDem;
float percentRep;
float percentPerot;
}COUNTY;
where MAX has been defined to be 16
- You will store the information that you get from the file into an
array of COUNTYs, where each element of the array will hold the
information for one county. The array size should be 24.
- The population growth must be computed from the population in 1980 and
the population in 1990. If the population has grown then the growth
should be positive, but if there has been a decrease in the population,
the growth should be negative.
- You must produce a table using formatted printing (discussed in
Chapter 9) to make your table look similar to mine, shown both above
in the description and below in the sample output. You must have the
same aligned columns of information as shown. The percentages of votes
must be aligned by their decimal points as shown. Your spacing of the
columns may be different. Make your table fit in an 80-character wide
screen.
- You must use a function called FindMDTotals() to compute the total
population of Maryland in 1980, the total population of Maryland in
1990 and the total population growth for Maryland between 1980 and 1990.
This function must use call by reference to manipulate the values of
variables that are declared in main(). You must use the following
prototype for this function:
void FindMDTotals(COUNTY counties[], int *mdPop90Ptr, int *mdPop80Ptr,
int *mdGrowthPtr);
You may not change this prototype in any way.
- You must use either Insertion Sort or Selection Sort.
Selection sort is available in the lecture notes. You may not use
Bubble Sort or Quick Sort.
Sample Run
ecs225d-sgi-01[102] a.out < p3counties.dat
Your greeting would go here ...
The counties in alphabetical order are:
Population Pop Votes % % %
County Area 1990 1980 growth Income 1992 dem. rep. perot
-------------------------------------------------------------------------------
Allegany 425 74946 80548 -5602 1108188 30595 37.6 45.3 16.6
Anne_Arundel 416 427239 370775 56464 9776730 185634 37.0 43.9 19.0
Baltimore 599 692134 655615 36519 16286479 323220 44.4 39.2 16.0
Baltimore_City 81 736014 786741 -50727 12695941 245091 75.8 16.6 7.1
Calvert 215 51372 34638 16734 1136375 23249 37.1 43.1 19.4
Caroline 320 27035 23143 3892 383996 8459 33.4 45.6 20.4
Carroll 449 123372 96356 27016 2733498 54930 28.1 51.7 20.0
Cecil 348 71347 60430 10917 1344514 27319 37.5 39.5 22.4
Charles 461 101154 72751 28403 1970029 38454 37.7 45.0 16.9
Dorchester 558 30236 30623 -387 515583 10957 35.9 45.0 18.3
Frederick 663 150208 114792 35416 3020111 64691 33.8 48.4 17.6
Garrett 648 28138 26490 1648 371642 10580 27.0 54.0 18.8
Harford 440 182132 145930 36202 3842573 80687 33.7 45.1 21.1
Howard 252 187328 118572 68756 5217970 99798 44.9 38.7 16.2
Kent 279 17842 16695 1147 344391 7628 40.5 40.6 18.5
Montgomery 495 757027 579053 177974 22941256 362613 55.1 33.0 11.6
Prince_George's 486 729268 665071 64197 14321200 256859 65.7 24.5 9.1
Queen_Anne's 372 33953 25508 8445 730808 14514 32.2 47.1 20.4
Somerset 327 23440 19188 4252 280171 7936 40.4 43.5 15.5
St._Mary's 361 75974 59895 16079 1277134 25085 35.6 45.8 18.1
Talbot 269 30549 25604 4945 774426 13708 33.9 49.4 16.3
Washington 458 121393 113086 8307 1977145 46208 35.7 47.6 16.3
Wicomico 377 74339 64540 9799 1238240 30272 37.9 44.8 17.0
Worcester 473 35028 30889 4139 665516 16559 36.5 43.7 19.7
Maryland's population in 1980 was 4216933
Maryland's population in 1990 was 4781468
Maryland's population grew by 564535 people in that 10 year period
The counties sorted in descending order by growth are:
Population Pop Votes % % %
County Area 1990 1980 growth Income 1992 dem. rep. perot
-------------------------------------------------------------------------------
Montgomery 495 757027 579053 177974 22941256 362613 55.1 33.0 11.6
Howard 252 187328 118572 68756 5217970 99798 44.9 38.7 16.2
Prince_George's 486 729268 665071 64197 14321200 256859 65.7 24.5 9.1
Anne_Arundel 416 427239 370775 56464 9776730 185634 37.0 43.9 19.0
Baltimore 599 692134 655615 36519 16286479 323220 44.4 39.2 16.0
Harford 440 182132 145930 36202 3842573 80687 33.7 45.1 21.1
Frederick 663 150208 114792 35416 3020111 64691 33.8 48.4 17.6
Charles 461 101154 72751 28403 1970029 38454 37.7 45.0 16.9
Carroll 449 123372 96356 27016 2733498 54930 28.1 51.7 20.0
Calvert 215 51372 34638 16734 1136375 23249 37.1 43.1 19.4
St._Mary's 361 75974 59895 16079 1277134 25085 35.6 45.8 18.1
Cecil 348 71347 60430 10917 1344514 27319 37.5 39.5 22.4
Wicomico 377 74339 64540 9799 1238240 30272 37.9 44.8 17.0
Queen_Anne's 372 33953 25508 8445 730808 14514 32.2 47.1 20.4
Washington 458 121393 113086 8307 1977145 46208 35.7 47.6 16.3
Talbot 269 30549 25604 4945 774426 13708 33.9 49.4 16.3
Somerset 327 23440 19188 4252 280171 7936 40.4 43.5 15.5
Worcester 473 35028 30889 4139 665516 16559 36.5 43.7 19.7
Caroline 320 27035 23143 3892 383996 8459 33.4 45.6 20.4
Garrett 648 28138 26490 1648 371642 10580 27.0 54.0 18.8
Kent 279 17842 16695 1147 344391 7628 40.5 40.6 18.5
Dorchester 558 30236 30623 -387 515583 10957 35.9 45.0 18.3
Allegany 425 74946 80548 -5602 1108188 30595 37.6 45.3 16.6
Baltimore_City 81 736014 786741 -50727 12695941 245091 75.8 16.6 7.1
ecs225d-sgi-01[103]
Submitting the Program
You are to use seperate compilation for this project, so you will be
submitting a minimum of three files.
Your C source code file that
contains main() MUST be called proj3.c. I would expect
that you would also have files called counties.c and counties.h, but you
may choose to have additional .c and .h files.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj3 proj3.c counties.c counties.h (and possibly
other files, seperated by spaces)
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show all files that
you submitted in a format similar to the Unix 'ls' command.
submitls cs201 Proj3