Assignment 1: Warmup
Out on:
January 28, 2008
Due by:
February 4, 2008, 3:00 pm (before lecture)
Collaboration:
None
Grading:
Packaging 10%, Style 10%, Functionality 80%
Overview
The first assignment is mostly a warmup exercise,
giving you a chance to play with Unix, the C compiler,
and even a little C programming on your own.
You will also get acquainted with a number of tools
such as tar and gzip.
Convince us that you're in the right course!
Problem 1: Exploring Unix
This problem asks you to figure out what a (somewhat complicated)
Unix command does, so you'll need access to a Unix system.
One of the first commands to type after you're logged in is
man man which will explain how to find and read
documentation.
Here's the command you need to figure out:
ls -la / | grep ^d | wc -l
It's important to understand that this command consists of
three separate commands connected by what's
called a "pipe" in Unix (the vertical bar).
The ls command produces some kind of output
which is then fed into the grep command; that
command does it's job and again produces output which is
then fed into the wc command; that command
produces output, and this time you get to see it since it
is not redirected into another pipe.
In your README file, give a brief account
of what each of the three commands does, as well as a summary
of what the overall effect of the compound command is.
Hints
-
Look up
ls,grep, andwcusing themancommand. - Play with the commands in isolation to understand how each influences what happens.
- Don't try to understand every little detail, try to figure out what the particular options given above do and how they work together.
Problem 2: Compiling Stuff
This one is quite simple:
First grab the example program
freq.c
and compile it
(with the correct warning options, see below).
Then run the program on it's own source code
using ./freq <freq.c and store
the output in a file called freq.out
(don't forget to submit that file).
Finally, read over the source code yourself
and try to figure out what the program does;
focus on the overall purpose of the program
and
include a short description of your
findings in your README file.
Problem 3: Diamond Programming
Finally, here's an actual programming problem:
Write a program diamond.c that prints
out a "diamond of stars" like this one (of size 7):
* *** ***** ******* ***** *** *
Ideally there's only one place in the program where the size of the pattern is defined, so it should only take a few keystrokes to produce a smaller or larger diamond instead.
Hints
- You should define the size of the diamond as a named constant.
-
Be sure to defend all warnings you can't get
rid of in your
READMEfile.
Deliverables
Please turn in a
gzip
compressed
tarball
of your assignment;
the filename should be
cs120-assign-1-login.tar.gz
with login replaced by your Unix login name
on ugradx.cs.jhu.edu
(so I would use cs120-assign-1-phf.tar.gz).
The tarball should contain no derived files whatsoever
(i.e. no executable files),
but allow building all derived files.
Include a README file that briefly explains what your
programs do and contains any other notes you want us to check out
before grading.
Grading
For reference, here is a short explanation of the grading criteria.
Packaging refers to the proper organization of the
stuff you hand in, following the guidelines for Deliverables above.
Style refers to C programming style, including
things like consistent indentation, appropriate identifiers,
useful comments, suitable documentation, etc.
Simple, clean, readable code is what you should be aiming for.
Performance refers to how fast your program can
produce the required results compared to other submissions.
Design refers to proper modularization and the
proper choice of algorithms and data structures.
Functionality refers to your programs being
able to do what they should according to the specification
given above; if the specification is ambiguous and you had
to make a certain choice, defend that choice in your
README file.
If your programs cannot be built you will get no points whatsoever.
If your programs cannot be built without warnings using
gcc -ansi -pedantic -Wall -Wextra -std=c99 -O
we will take off 10% (except if you document a very good reason).
If your programs fail miserably even once,
i.e. terminate with an exception of any kind or dump core,
we will take off 10%.
Finally, make sure to include your name and email address in
every file you turn in!