[Courses] [C] Next C topic: Project Proposal
Conor Daly
conor.daly at oceanfree.net
Thu Jul 18 20:10:18 EST 2002
On Thu, Jul 18, 2002 at 12:27:32PM -0400 or so it is rumoured hereabouts,
Cynthia Grossen thought:
>
> Are there any useful programs we can write to do things on our systems at
> home? Maybe a program that would perform some onerous system task that
> usually requires a bunch of commands. I vaguely remember writing C prgs at
> school that would report memory usage and things of that ilk about my
> computer.
Might I suggest a program to calculate WeightWatchers(TM) points as a
suitable vehicle for learning about a number of the suggested topics? Not
so much an onerous system task (but vital nontheless to those of us who
have to watch!).
##########################################################################
The WeightWatchers algorithm is as follows:
1. 100 kCal = 1.5 points
2. 1 gram saturated fat = 0.25 points
3. If you don't know the saturated fat figure, use total fat * 0.5
4. Points are calculated to a resolution of 0.5 points.
I'd suggest something along the lines of:
A). Write a program to calculate WeightWatchers (TM) points. Your program
should:
1. Take data input in Q&A mode.
2. Account for saturated fat or total fat
3. Account for Cals quoted per 100gm and total to be consumed.
4. Calculate total points for a meal
5. Use structs to store nutrition / points data for each item.
6. Cope with incorrect data at any input stage.
B). Extend your program to take data on the commandline. Your program
should:
1. Accept data on the commandline.
2. If commandline data insufficient, ask for rest by Q&A.
2a.Alternatively, exit with an error (so it won't hang up a
background job).
3. Return a single number as output (so it can be used in a script).
C). Further extend your program to read WW algorithm configuration from a
file. Your program should:
1. Read configuration options from a file.
2. Use sensible default values if an option is not found in the
config file.
3. Ignore comment / blank lines in the config file
D). Finally, extend your program to read from and write to a datafile.
Your program should:
1. Read data from a file.
2. Use sensible default values where possible for missing data
3. Ignore comment / blank lines
4. Reproduce input data in output file along with results
5. Reproduce comment lines in output file
6. Optionally update input file with results
At all stages, your program should use functions for seperate tasks
(especially repeated tasks).
That's a reasonably simple program in its basic form and will extend
nicely to illustrate
A. Structs
B. Commandline args
C. File I/O (read only)
D. File I/O (read write)
######################################################################
Or am I jumping the gun?...
Conor
--
Conor Daly <conor.daly at oceanfree.net>
Domestic Sysadmin :-)
---------------------
Faenor.cod.ie
7:39pm up 56 days, 4:56, 0 users, load average: 0.08, 0.02, 0.01
Hobbiton.cod.ie
7:28pm up 29 days, 18:50, 1 user, load average: 0.02, 0.03, 0.00
More information about the Courses
mailing list