Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
comp20005 Engineering Computation
Assignment 1
Learning Outcomes
In this project you will demonstrate your understanding of loops, if statements, functions, and arrays,
by writing a program that first reads a file of text data, and then performs a range of processing tasks on
the data. The sample solution that will be provided to you after the assignment has been completed will
also make use of structures (covered in Chapter 8), and you may do likewise if you wish. But there is no
requirement for you to make use of struct types, and they will not have been covered in lectures before
the due date.
Sequential Data
Scientific and engineering datasets are often stored in text files using comma separated values (.csv
format) or tab separated values (.tsv format), usually with a header line describing the contents of the
columns. The simplest framework for processing such data is to first read the complete set of input rows
into arrays, one array per column of data, and then pass those arrays (and a buddy variable) into functions
that perform various the required data transformations and analysis.
Your task in this project is to use that processing approach to determine shipping arrangements for the
transport of a mineral resource such as iron ore. Imagine a massive open-cut mine in outback Australia
in which huge machines dig raw iron ore out of the ground, and load it into railway wagons for transfer
overseas for processing.1 Each scoop extracted from the mine has a slightly different concentration of
iron ore in it, because natural variation means that the ore is mixed with differing amounts of rock and
dirt. Each scoop is transferred into a railway wagon at the mine, and then long trains with hundreds of
wagons are taken by rail from the mine to the port, for shipping to overseas smelters. To measure the
ore concentration in each wagon, samples are taken of the load at the time the wagon leaves the mine,
and are analyzed for purity. Those samples are processed while the train is in transit, and the percentage
concentration in each wagon is known by the time each train of wagons reaches the port a few days later.
The wagons are also weighed as they depart the mine, so that the amount of ore they contain is known.
To describe a train of wagons, a tsv file contains one line for each wagon in the train. The examples
that follow, supposes that the data file wagons0.tsv contains these values in tab-separated format:
tonnes percent
100.4 50.3
94.2 48.2
89.7 61.3
105.2 42.9
108.8 65.2
95.2 55.1
101.6 47.2
104.5 51.2
108.6 59.4
There will always be a single header line in all input files, and then rows containing pairs of values
separated by “tab” characters (’\t’ in C). Once the first line has been bypassed (write a function that
reads and discards characters until it has read and discarded a newline character, ’\n’), each data line
can be read as a pair of double variables using scanf("%lf%lf",...). The two values in each row
1The iron ore will eventually come back to Australia as cars and tv sets and steel beams, but that’s another story.
1
represent a weight in tonnes, and the corresponding percentage ore concentration. This example file
and another longer one wagons1.tsv can be copied from http://people.eng.unimelb.edu.au/
ammoffat/teaching/20005/ass1/. The train shown in wagons0.tsv contains nine wagons/loads,
and has a total weight of 908.2 tonnes of ore.
When a train of wagons arrives at the port they are combined to make consignments, where each
consignment contains an integral number of wagons of ore. As the consignment is being formed, the
overall weight and concentration are monitored. For example, if the first four wagons in wagons0.tsv
were combined into a consignment, it would weigh 100.4 + 94.2 + 89.7 + 105.2 = 389.5 tonnes and
have an overall concentration of:
(100.4 × 50.3%) + (94.2 × 48.2%) + (89.7 × 61.3%) + (105.2 × 42.9%)
(100.4 + 94.2 + 89.7 + 105.2) ≈ 50.3% .
If each consignment must be a minimum of 375 tonnes at a minimum concentration of 50.0%, this fourwagon
consignment can be accepted, and transferred to one of the waiting ships. But if the requirement
was for 375 tonnes at 52.5%, this consignment would be rejected, and sold (at a loss) in a secondary
market. Finally, if the minimum contracted size of the consignments was actually 400 tonnes, a fifth
wagon would be need to be added, and the concentration would need to be recalculated before it could
be known if the consignment could be accepted or rejected.
The clear goal is to avoid forming consignments that greatly exceed the minimum weight, or that
greatly exceed the required concentration (because the company will not get paid for the excess minerals
they contain); but at the same time also avoid forming consignments that fall below the required
concentration (because the consignment will be rejected).
For all of the task in this assignment, consignments must be 375 tonnes or more, and to be accepted
must have an ore concentration of 52.5% or more2
(Be sure to #define these quantities!) We will
also assume throughput this assignment that the “train processing mode” is sequential. That is, as each
train arrives at the port, it rolls slowly through a single unloading station. As it does, each wagon is
unloaded to one of two possible conveyor belts that move the unloaded ore, perhaps “tilt wagon left”
to add that wagon’s load to the current consignment, or “tilt wagon right” to send it to the secondary
market. Hence, your program will model the situation in which only one consignment is being built at a
time, and with the wagons being unloaded in the order that they appear in the train. In a real port there
will have multiple unloading stations and multiple consignments being built concurrently, making the
program required much more complex, and beyond our expertise in this subject.
Stage 1 – Control of Reading and Printing (marks up to 5/10)
The first version of your program should read the entire input dataset into parallel arrays (or, if you are
adventurous, an array of struct), counting the data rows as they are read. The heading line should be
discarded and is not required for any of the subsequent processing steps. Once the entire dataset has been
read, your program should print the first and last of the wagons’ tonnages and concentrations (counting
the wagons starting at “1”), the total of the wagon weights, and the overall ore concentration across the
train. The output for this stage for file wagons0.tsv must be:
mac: ./myass1 < wagons0.tsv
S1, wagon 1, tonnes= 100.4, %= 50.3
S1, wagon 9, tonnes= 108.6, %= 59.4
S1, whole train, tonnes= 908.2, %= 53.4
Note that the input is to be read from stdin in the usual manner, via “<” input redirection at the shell
level; and that you must not make use of the file manipulation functions described in Chapter 11. No
prompts are to be written. You may (and should) assume that each train contains at most 999 wagons3
.
2
In reality, consignment sizes will be in the thousands of tonnes, and will be matched against ship capacities.
3The actual trains used in Western Australia are around 250 wagons long, but hey, we should plan for growth – computer
memory is cheap. Some iron ore trains are also driverless, making them the world’s biggest “robots”. Unsurprisingly, when
something goes wrong with an iron ore train, it goes really really wrong, see https://tinyurl.com/y8v35spn.
2
Note that to obtain full marks you need to exactly reproduce the required output lines. Full examples
can be found on the FAQ page linked from the LMS. You can assume that the input provided to your
program will always be sensible and correct, and you do not need to perform any data validation.
You may do your programming in your grok playpen, in which case you will probably wish to also
create some test files there too, and will need to click on the “Terminal” button to run your program.
Or, given the scale of the required program, may find it more convenient to move to the jEdit/gcc
environment. Information about this option is available on the LMS.
Stage 2 – Simple Sequential Processing (marks up to 8/10)
In the simplest mode of operation, each train’s wagons are combined in strict arrival order to reach the
minimum weight, and then the concentration of that consignment calculated. If the concentration exceeds
the required minimum, it can be loaded. On the other hand if the average concentration over the wagons
in the consignment is less the the target purity, the consignment is rejected, and transferred to a dumping
area. In both cases the next consignment is then commenced.