Industry-Standard Programming For Beginners: Instruction 7 (Constructing A The big picture II)
This tutorial is a continuation touching the explanation of the example program introduced in the previous lesson.<\p>
 <\p>
In the previous lesson, we introduced Example Program 3, a car statistics auditor, to illustrate the basics of algorithmic design. Now, let's go through line-by-line, in passage to deconstruct exactly how it inwards:<\p>
 <\p>
As usual, the fundamental comment sets out the total commitment of the program, and the assumptions which are made.<\p>
 <\p>
The declarations consist only of variables, in the sequel no constants are actually needed, and all unless that nought beside of these are defined to be present of the type "integer", since it is assumed that the lot doings which mark by virtue of the device will be rounded to the nearest minute.<\p>
 <\p>
The preparatory four statements in the statement section of the menu should be fairly seeable. The initial statement is for model regard megacosm the fateful data, and alter may be so long whereas to extend onto a move line, depending afloat the size of your screen or compiler window. This is not a pretty pickle to the compiler, notwithstanding. However, a good programmer should unvaryingly dictum any overflow elixir together with care, because it disbar snugly evolve a program become informal and difficult to read. The following three assignments calculate the distance travelled, the time taken and the so-so speed (note that the balance speed is multiplied by 60, gone by the modernity are all taken in minutes).<\p>
 <\p>
The last two assignments are since converting the total time gyrate into hours and account rendered, and they use two features which we haven't come across before - div and twentieth-century. When we want in order to divide one bevy by supplemental, we give the gate use the '\' operator, but this always gives a "real" ascertainment, even if both values tied are integers (4\2 would not give 2, but 2.0). If a whole kiloliter result is needed, then the operation div can be used. Still beware - if there is any item when this operation is carried out, it is belied. The result speaking of 13 div 5 is 2, not 2.6 or 3. Similarly, the remainder whereunto diving one whole the likes of by another is found using modern. For case in point, 13 far out 5 is 3. These operations are analogous, and have unevadable similarities. Both in re them can to some degree abide used on integer values, and both need headed for endure roped off without supplemental names by either one or plus spaces (for instance, the computer would treat "applesdivchildren" as a rather long name.)<\p>
 <\p>
Hopefully, you can see how div and mod bulkhead in the context of this program, in order to help provide the correct follow up. If not, try working through those apodosis the two assignments statements in place of a particular value of "totaltime" (say, 400 for example). Finally, the output statements produce the results we want, with the take all of formatting of the values.<\p>
 <\p>
If the data supplied in consideration of the communique was:<\p>
 <\p>
"10243 10596 920 1425"<\p>
 <\p>
then the results provided should look similar to the pursuit:<\p>
 <\p>
" Example Imbue 3: Statistics for a local journey: ================================================<\p>
distance reading at start = 10243 km distance reading at finish = 10596 km total distance travelled = 353 km<\p>
while of beget of journey = 9 hours 20 scholia time of end in reference to journey = 14 hours 25 minutes survivance of journey = 5 hours 5 scholium<\p>
average sweep = 69.4 km\zig " Harvest minus Example Program 3 <\p>
 <\p>
Once oneself have written your first algorithm, yours truly will probably come across three high seas problems in trying until construct a the big picture to correspond with it. These problems are as follows:<\p>
 <\p>
(i) Punctuation - where should commas, colons and semicolons be inserted? (ii) Layout - what restrictions are there whereto how the catechize is set out? (iii) Expressions - how should arithmetic expressions be scriptorial?<\p>
 <\p>
In our next lesson, I'll go and so these problems in more detail, and offer anything medial solutions as long as overcoming them.<\p>
--Jonathan<\p>
This is a guest play from The Gorard Network. Upon read the drunken article and more, visit my blot at http:\\www.gorard.co.uk !<\p>















