CS201
Lab 2 - C Expressions
Objectives:
- Solve a simple problem using C.
- Learn how to write, compile and execute the code using Eclipse CDT.
Readings:
- Read Chapters 1 and 2 in the Hanly/Koffman text. Read Eclipse Tutorial in your course web page.
Deliverables: (DUE BY THE END OF THE 3RD LAB!)
- Submittal of your lab2.c and Makefile files.
TO DO (for today's lab)
- Design and Write a program to solve Programming Project #3
on page 91 of the Hanly/Koffman text by using Eclipse CDT and save this as lab2.c. Follow the software development method properly to solve the problem.
- Use Linux I/O redirection to enter your hours and minutes values. Do not
prompt for these values to be entered from keyboard, instead read them in from a data file
using
scanf
in your program code, and Input/Output redirection
operator provided by Linux (in the command line type (1) name of your
program, (2) "<"
sign and then (3) a name of your input data file). For more info on I/O
redirections see the Some Useful Links secion in your course webpage and Lecture3.pdf.
- For your input data file (name it
input), build a short file
including only two integers
in its first line.
Suppose you wanted to enter 12 hours and 30 minutes. You would
build a file that had the following numbers in line one.
12 30
Make sure to call this file "input" and save it to your the same directory where lab2.c resides.
- Hint: What types of values are you going to use to derive t,
and then T? Integer, double or float? Note that you need to convert
"30" minutes, to "0.5" of hour...
- A sample run of your program assuming lab2 for the name of your executable would look like the following:
$ lab2 < input
- "<" operator will re-direct standard input
for scanf command from your keyboard (default
setting), to the file input.
- A sample output (printed out on the screen) should look like the following:
Current temperature = 23.10
- Your program should produce output formatted exactly as shown above. Make sure to test your program with enough data.
- You do not need to submit a sample data file. We will provide
a set of test data files for to
test your program.
- Don't forget to document your code properly.
LAB 2 ENRICHMENT
- Try using fscanf in your C
program, to do the reading of input data. See Lecture3.pdf for details.
- Note: Make sure to close the input file after you done with reading
the data.
- A sample run of your program can now look like the following:
$ lab2
- Now, there is no I/O redirection necessary