Recent Question/Assignment

Assignment name: my car's mileage
Problem specification
A file is kept with details of my car's mileage. Whenever I fill up with petrol I enter the total km the car has travelled and the amount of petrol (in litres) I've just bought, beside each other on a single line. This file called mileage.txt is also uploaded.
The deliverables for this assignment are
1. a single C file. It should work, and It should be properly indented and commented.
2. A design report, including a short discussion of the problem, a flow diagram and results of unit tests. NB Do not exceed 2 pages
Notes
How to calculate the efficiency ei of your car at a particular fill (call it fill i) ?
The fuel efficiency can be calculated in terms of the distance travelled between fills di and the petrol used pi. It would be safe in general to assume that the tank is completely filled on each fill of petrol. If this is the case, then a fill of pi litres indicates that pi litres have been consumed by the car in its journey from di-1 to di.
How to get lots of numbers in from the mileage.txt file into the program, without having to type the numbers out one by one?
The answer is to pipe the mileage.txt file into the program, so the program 'thinks' it's taking all those numbers in from the keyboard.
1.
1. Make sure a copy of mileage.txt is in the same folder (or directory) as your .exe file. Right-click on the explorer bar and select Copy address as text.
2. Open a command window (run CMD.exe) and change current directory to the directory containing your .exe file: type cd and paste the path you copied in step 1. Hit Enter.
3. Type myprog mileage.txt and hit enter, where myprog.exe is the name of your executable (program) file.
4. Your myprog program will take the contents of mileage.txt onto its standard input
Assignment Help/Tips
The pattern for our program should go something like
while (not end of input):
Read a single (d, l) record
compute an efficiency, in terms of d, l and the previous d
write the efficiency value
end
But how to make sure the previous d value is available every time? One suggestion was to use an array for all d values, but we are fairly sure that reading all the records into an array is not viable. How can the program know in advance at compile time how big the array needs to be at run time? The answer seems to be that it can't (or can't easily). So no arrays. How, then?
Another niggle: the program needs to read and calculate until the end of input. How do do this? [ Clue: Remember how the scanf() function behaves if it isn't able to read all the values it expects. ]
Grading criteria
Working code
The code compiles and runs properly
Maximum mark
20
Error handling
Does the program check for basic error conditions, e.g. Bad input?
Maximum mark
5
Works as a filter
Works as a filter -- no need for long arrays
Maximum mark
10
Style -- comments, indentation
Style -- comments (head of file, above functions), proper indentation
Maximum mark
15
Design report -- short discussion of the problem
Maximum mark
10
Design report -- a flow diagram
Maximum mark
20
Design report -- results of unit tests
Maximum mark
20

Looking for answers ?