The main theme of this project is input and output in C. To be able to complete this project, you need to be able to do all of the following things as a C programmer:
In lecture, we took one day where each student chose a topic. Those topics are listed (or soon will be) on the web page at http://copland.udel.edu/~pconrad/cisc105/05F/classlists/topic.html. If you have not yet chosen a topic, or want to change your topic, please email your professor and cc your TA as soon as possible.
Your topic will guide you through this project, and ensure that your project is your own creation, individual and unique, a reflection of your own interests.
In lab02, you wrote up a proj1data.txt file, describing several "fields" of data that might be in a "table of values" for your topic. You also produced a short table of example values, and wrote a short C program that read in two of those fields, and echoed them back to the screen. If you've finished that, then congratulations! You are already half way finished with project 1. The rest of the project builds from that point.
If you finished lab02, you've already finished stages 1 and 2 of this project. Even if you do no further work other than resubmitting what you've already done, you can get 50% credit for project 1. There are five additional stages; for each stage that you complete, you work towards additional "partial credit". After completing six stages, you can stop, and "settle for a B", or complete one additional stage to go for an "A" grade. This structure will be used for project 2 and 3 as well.
Remember that each project is worth 10% of your final grade in the class, while each lab is worth 2% or less of your final course grade. So it is important to do well on the projects.
With that said, let's get started.
You completed this stage as part of lab02. See lab02.html for detailed instructions.
You completed this stage as part of lab02. See lab02.html for detailed instructions.
The idea of this stage is to take what you did for the first two fields from your table back in lab02, and finish the job for all the fields you came up with.
Step-by-step instructions
mkdir ~/cisc105/proj1
cd ~/cisc105/proj1Here are some details about each of these points:
int for integer data, double for numbers with decimal pointsdouble is almost always a better choice than float for real numbers (I can't think of any exceptions)float or double for dollar amounts, but for now it is ok. char array, also add a #define to indicate the length of the array instead of using a number
#define NAME_OF_RESORT_LENGTH 20char nameOfResort[NAME_OF_RESORT_LENGTH];#define, but there is one on the variable declaration.printf() statement that tells the user what to type in. :) and don't put a \n at the end. "Please enter price of lift ticket in dollars: ""Please enter year this album was released: "
scanf() (for int, float or double)fgets() (for character data) so you can have embedded spaces scanf() to put an & in front of your variable namescanf(), use %d for int variables, %f for float, and %lf for double. fgets(), be sure to use fflush(stdin); right before you read in the variable. %d, %f, %lf or %s as appropriate in your format string. "$%6.2lf", for example, can be used for double, or "$%6.2f" for float.
This gives you a dollar sign, 3 places before the decimal point, and 2 afterwards (3 + 2 = 5, but you have to count the decimal point as well, giving a total of 6, hence 6.2) The main work of this stage is to add something to your output that involves a simple calculation. Take one of your numeric fields, and in addition to printing it out in its original form, also print it out in some new form after doing a calculation on it.
For example: this might be converting the units of one of your fields (e.g. from miles to kilometers, or ounces to grams. You could do Fahrenheit to Celsius, but that's so "five minutes ago". Try to choose something more original.
Another possible calculation: converting a "year" into "how many years ago was that". For example, if you are doing "albums by Jessica Simpson", you could add a variable for the current year (e.g. 2005) and add a separate prompt at the beginning of the program to have the user enter the current year. For example:
What year is this (e.g. 2005) ?
The user would enter 2005, and then you could subtract from that value the year each album came out. That way you are converting from "year of release" to "how many years ago the album came out."
The calculation doesn't have to be fancy. I just want to see that you know how to do simple calculations as part of your program. If you need help coming up with an idea, ask your TA or professor for advice.
proj1s3.c file to proj1s4.c. #define such as #define CMS_PER_INCH 2.54 /* the number of centimeters in an inch */ printf("How many years ago this album came out: %d\n", currentYear - yearOfRelease);printf("Weight of digital camera in ounces : %5.1lf\n", gramsToOunces(cameraWeight));In this stage you want to add a simple comparison (i.e. an if/else) to one of your numeric fields.
As an example, you might ask the user to enter, as a separate variable, the year the user was born. You can then print output such as:
Year this album was released : 1972
Did this album come out before you were born: Yes
Year this album was released : 1990
Did this album come out before you were born: No
In this case, the code would take the following form:
printf("Did this album come out before your were born: ");
if (yearAlbumReleased < yearUserWasBorn)
{
printf("yes\n");
}
else
{
printf("no\n");
}
You can also define a constant and compare against that. For example, if your topic is hiking trails, you might decide that a hiking trail of 5 miles or less is a short trail, and a trail of more than 5 miles is a long trail. You could then use a #define to define a constant:
#define MAX_LENGTH_OF_SHORT_TRAIL 5
and use an if/else such as:
printf("Type of trail : ");
if (trailLength <= MAX_LENGTH_OF_SHORT_TRAIL)
{
printf("short\n");
}
else
{
printf("long\n");
}
To complete this stage, copy from proj1s4.c to proj1s5.c, and add C code to implement your decision. Add it into the end of the section of your program that produces the output, and test it.
Typically, the last stage of each project involves some step that is a bit more challenging, even though it is only worth 10% of the grade. The purpose of this stage is to provide some extra challenge to the students that will not be satisfied with anything less than an "A" on the project.
Should you skip this stage? It is a perfectly reasonable choice for many people. While I expect all students to try their best to complete up through stage 5, and will be a bit disappointed if you don't make it that far, I expect that many of you might choose to skip stage 6, and its ok if you do.
What are the consequences of skipping stage 6? If you skip this step, the maximum grade you can earn is a 90%, which an A-, but to earn that grade everything else must be perfect—so, more realistically, you are looking at earning a B. Note that a "B" is a perfectly good grade, and there is no dishonor in being satisfied with a B, and skipping this stage altogether. It is often a more challenging and time consuming stage, and you may need to devote that extra time to some other course.
What does this step involve?
In this step, you will add code at the end of your program to write out your table as an HTML file—that is, as a nicely formatted web page. This is a very typical thing that real-world computer programs do these days. Instructions for how to do it will be provided in lab03 (which will not be available until 9am 9/23). That will still give you a full week to complete this step, so if you plan on trying to complete it, you should try to finish up stages 1 through 5 before coming to lab on 9/23.
Further instructions for this stage will be posted no later than 9am on 9/23/2005 in this space.
To submit project 1, you need to do each of the following:
.c file (and for now, that file only) to WebCT for submission, but don't submit yet. lab02a.c. proj1s5.c. proj1s6.c.proj1.txt. In the script, do the following steps. cd ~/public_html/cisc105/proj1cat proj1data.txtcd ~/cisc105/proj1.c file that you uploaded (the one for the stage where you stopped)cc or gcc (doesn't matter which)./a.out or ./proj1s5 or ./proj1s6).exit to complete the script cd ~/public_html/cisc105/proj1cat proj1data.txtcd ~/cisc105/proj1.c file that you uploaded (the one for the stage where you stopped)cc or gcc (doesn't matter which)rm *.html to remove all the old .html files from your ~/cisc105/proj1 directory../a.out or ./proj1s6 or ./proj1s7). (Read all the instructions for this step before starting.) ls command to show the contents of your directory. Each time you create a new .html file, give it a new name (i.e. a name that isn't already in your directory) when you run the program (you'll pass in the new name as a command line argument). Then, after each run, type ls again to show that the file was created by running your program (i.e. it didn't exist before, but it does exist afterwards.) On the printed copy of your script file, use a highlighter (or circle in pen or pencil) to show the name of the file you pass on the command line, and then where that name appears in the ls listing after you run the program. mkdir -p ~/public_html/cisc105/proj1/stage6
cp *.html ~/public_html/cisc105/proj1/stage6
chmod -R a+rx ~/public_html/cisc105
Them, be sure your files are readable on the web at http://copland.udel.edu/~yourusernamehere/cisc105/proj1/stage6exit to complete the script proj1.txt file to WebCT and submit.proj1.txt using one of the following and give to your TA at the earliest possible date:qpr -q whlps proj1.txt (to print in Willard 009B)qpr -q smips proj1.txt (to print in the basement of Smith Hall)kpr proj1.txt (to print to your local printer if you are on a Windows machine, and using the ssh client downloaded from http://udeploy.udel.edu)