Lab04, CISC105 Summer 2005
Directions
- Write a program for each of the following problems. If you wish, you
may start each program using a previous program as a base and then
modifying it, BUT you will learn more if you code each one from
scratch. Be sure to save every separate program. All programs must be
properly commented and indented (see
Assignment Standards on the class
website).
- Some programs below are associated with a question. Answer the
question using comments in your code.
- During your scripting of the programs, you will compile and run each
one. If a program does not compile, don't try to run it (because a.out
will not have been created).
- Name each program lab04.n.c, where n is the number in the list
below. For example, the name of the file for the first will be lab04.1.c
Programs
- (10) Write a void function that takes two parameters---a total width and a
number of stars/asterisks---and prints the number of stars on one
line, right-justified within the total width. Call the function from
a main program that demonstrates the function's abilities.
Example output:
Right-justify 5 asterisks in 10 spaces
*****
Right-justify 1 asterisk in 20 spaces
*
- (10) Write a function that takes two parameters---the original value
and a scaling factor---and returns the scaled value. Call the
function from a main program that demonstrates the function's
capabilities.
Example Runs:
Enter a number: 3.5
Enter a scaling factor: 30
Scaled value: 105
Enter a number: -1
Enter a scaling factor: 20
Scaled value: -20
- (30) Modify angle.c
to be more general and to use some of the concepts we've learned since
we originally wrote the program.
- Let the user specify the start and end values for degrees, as well
as the increment for the next degree.
- Add a function that
converts degrees into radians. Use the function in your program.
- Use a loop to generate the output, from the user-specified start to end degrees
in the user-specified increment.
In next week's lab, we'll put the above programs together to create a
bigger program.
Creating a Web Page
- A special directory is the one called
~/public_html
. Any and all files that you put into
this directory become available on your web page. (If your user id
is foobar, your web page is http://udel.edu/~foobar).
To see if you have this directory, change your working directory
to your home directory and then see if the directory
"public_html" is listed. If you don't have the
directory already, create the public_html
directory.
- Go into the
public_html
directory and create a
cisc105 directory. The public_html/cisc105
directory
will store your CISC105 web page. In a later step in this lab, you
will create a personal web page (if you don't already have one) and a
web page specifically for this course.
The files for your personal web page go into the directory
"~/public_html", and will be accessed via the URL http://udel.edu/~userid
(where userid is your UDelNet ID).
The "CISC105 web page" goes into the directory
"~/public_html/cisc105" and will be accessed with the
URL http://udel.edu/~userid/cisc105.
You can use this same technique to create as many web pages as you
like under your main web page, just by creating new subdirectories
to store the content.
Goal 1: Creating a personal web page (10)
- If you already have a personal web page on strauss (one that
comes up when you type http://udel.edu/~userid, where userid is
your UDelNet ID), then skip to the next goal (creating your
CISC105 web page). Otherwise, cd into your ~/public_html
directory.
- Use emacs to create a file in that special directory.
The file must be named
"index.html". The contents of that file should be
something like the following:
<html>
<head>
<title>Joe Sample's Web page</title>
</head>
<body>
<h1>Joe Sample's Web page</h1>
I had to do this <b>web page</b> for my <a
href="http://udel.edu/~pconrad/cisc105">CISC105 class</a>.
Right now it is pretty lame, but I hope to make it better later.
</body>
</html>
|
Here's what that looks like once it is formatted by a web browser:
Joe Sample's web page
I had to do this web page for my CISC105
class. Right now it is pretty lame, but I hope to make it better
later. |
- After you save the file, you need to type in the following command:
chmod a+rx ~/public_html/*
This command makes all files and directories in your public_html
directory accessible to all users on strauss, as well as all users on
the World Wide Web. You need to repeat this command each time you add
new files under public_html that you want users of the Web to be able
to access.
More details:The asterisk in the above command is a
"wildcard" that matches every file name in the public_html
directory. You can also use chmod
on individual files and
directories as shown in class. You need to repeat this command each
time you add new files under public_html that you want users of the
Web to be able to access.
- To see that it works, type into a web
browser:
http://copland.udel.edu/~userid
If it
doesn't come up, make sure you set all your file permissions
correctly. The most common problem is not doing the "chmod
a+rx ~/public_html/*" command. If you did that, and it still
doesn't work, check with your TA or with a classmate for help.
Goal 2: Creating a CISC105 web page (10)
- cd into ~/public_html/cisc105. Now, create an index.html file in
this directory containing html code similar to the personal page.
-
Now, add an image to your web page. Find an image on the Web (or
from wherever you want) and copy it into your public_html/cisc105
directory. Then, put the image in your CISC105 Web page, using the
HTML tag
<img src="imagename.jpg">
, where
"imagename.jpg" is the (case-sensitive) name of your file.
- After you have created the index.html file and/or
copied your image file into your public_html/cisc105 subdirectory,
you may need to repeat the
chmod a+r [filename]
command to get the web page to come up when you use the URL http://udel.edu/~jsample/cisc105.
Goal 3: Why are you here? (30)
Several of you have mentioned that you're not sure why you have to
take the course for your major. I, of course, believe that the course
is just plain fun, so you shouldn't need a reason.
Computers and programming specifically have advanced all sciences.
For example, researchers in other fields use computer programs to
write simulations before performing expensive experiments in
real-life. Computer programs are also used to process data quickly.
Computer programming is a very useful skill!
Your assignment: Find at least two Web pages that discuss
the connection between your major and computer science. (If you don't
have a major, pick a potential major or find some sites about computer
science that interest you.) Add these links to your cisc105 web page.
Summarize what you learned from each link in a little blurb.
Searching the Web: There are lots of Web sites that you can use
to search the Web. I like Google, but
there are lots of other available resources. Effectively searching
for relevant information on the Web is another valuable tool. Because
there is so much information out on the Web, you need to be able to
quickly determine if a Web page is relevant and worth further viewing.
Be careful, though. Try to use only reliable Internet sources.
The goal of this assignment is not to learn HTML, but if you would
like to learn a little more about HTML to format your page nicer,
there are many resources available:
You can find many, many more if you do a Google search.
Submission
You should have a total of 3 programs named lab04.1.c to
lab04.3.c. Make a single script file (see lab00 for the instructions)
where you cat, compile, and run each one in its final form (if it
didn't compile, don't run it in the script - mark the place in the
printed script file with a marker so it stands out).
Note: Cat, compile, and run each program in order! Do not
cat all programs, then compile, etc.
Execute your program multiple times to show that you tested the
program well.
Submission
Email the tar file to Gang by midnight on Wednesday (see lab00 for
directions). Give the paper version to Gang at the beginning of your
next lab. Clearly write at the top of your paper submission where
Gang can find your web page.
Grading
Grading is as noted above for each program, and creating the web pages
is worth 50 points for a total of 100 points. (Using UNIX, e.g.,
changing file permissions, is included in the 50 points.)
The "Creating a Web Page" part of this lab was
adapted from Phill Conrad's lab.