|
このページはEtoJ逐語翻訳フィルタによって翻訳生成されました。 |
If you have a Pascalite, or the ソフトウェア emulation, then there's a separate tutorial for you, covering much of the ground as 現在のd here for the FPC/ TP (人が)群がる.
Before I say what I'm about to, I will say: This tutorial will develop a program which will work with FPC or Turbo Pascal. Now that's out of the way, I come to: Be sure to look at the previous tutorial before 試みる/企てるing this one. (In the previous tutorial, you could only read about something the Pascalite people could do.) In it we looked at using a computer to 記録,記録的な/記録する the activity of a hamster. The "For... To... Do..." 声明 was introduced. In this tutorial we are also going to 跡をつける some events, and will 会合,会う arrays for the first time. They are a special type of data, or a special sort of variable, if you prefer to think of them that way.
This might have left for "Level 2" of the tutorials, but it introduces a 根底となる programming 道具: arrays.
The program we will make could be used for a traffic 調査する. By "traffic 調査する", I mean the 演習 in which someone sits at a 道端 for an hour and counts how many motorbikes, how many 2-door sedans, how many 4-door sedans, and how many 非,不,無-of-the-above 乗り物s pass by. 明白に, such a program could be adapted to many other uses.
As developed here, the program will have a lot of 使用者 unfriendliness. There are lots and lots of things which you would do to it if it were really going to be used for traffic 調査するs... but for the 目的s of the tutorial, the に引き続いて is uncluttered.
The program will be used as follows: 使用者s will start it, at which time they will see "Enter 1, 2, 3, 4, or 99, and 圧力(をかける) enter." They will enter 0 if they see a motorbike, 2 or 4 for a 2 or 4 door sedan, 3 for an "other" 乗り物, and 99 to やめる the program. They will see running subtotals of the 乗り物s seen.
It always 支払う/賃金s, by the way, to 令状 out a description like the above before you start 令状ing a program.
We've already looked at simple variables. They 許す us to keep things so that we can 言及する to them. Now we're moving on to arrays. Like a simple variable, they are a place for keeping something. In 新規加入 to the 特徴 of a simple variable, they 許す us extra ways, clever ways, to 明示する which piece of (警察などへの)密告,告訴(状) we want. Type in the に引き続いて. Notice there is lots of 範囲 for using copy/ paste to 減少(する) typing and 増加する 正確.
Don't let the blank lines 混乱させる you... You can always put them in where ever you want to ーするために help make 論理(学)の 封鎖するs of the program show up. The indenting is there for the same 推論する/理由.
program Traffic;
uses crt;
var sTmp:string;
bSeen:array [1..4] of byte;//**
begin
bSeen[1]:=0;//Put 無 in each of the subtotals //**
bSeen[2]:=0;//**
bSeen[3]:=0;//**
bSeen[4]:=0;//**
clrscr;
repeat
writeln('Seen so far: Motorbikes:',bSeen[1],
' Two doors:',bSeen[2],
' Four doors:',bSeen[4],
' Other:',bSeen[3]);//**
writeln('Enter 1,2,3,4 or 99');
readln(sTmp);
if sTmp='1' then bSeen[1]:=bSeen[1]+1;//**
if sTmp='2' then bSeen[2]:=bSeen[2]+1;
if sTmp='3' then bSeen[3]:=bSeen[3]+1;
if sTmp='4' then bSeen[4]:=bSeen[4]+1;
until sTmp='99';
writeln;
writeln('Bye. Make a 公式文書,認める of your subtotals! THEN 圧力(をかける) the "Enter" 重要な.');
readln;
end.
That's all there is to it! I've 示すd lines you should 公式文書,認める 特に carefully with //**s. As I said, it could be done fancier, it could be done better... but what we have so far WORKS, and it shows you an array (bSeen) in 活動/戦闘. Now we'll talk about it a bit.
Our program uses the array bSeen. bSeen 供給するs four places to 蓄える/店 a byte. A particular one of them, say bSeen[2], is called "an element of the array". In the program in the tutorial we 港/避難所't taken advantage of the 力/強力にする of arrays... we could have done what we've done so far with four variables 指名するd bSeen0, bSeen1, bSeen2 and bSeen3. For a very modest example of the 力/強力にする of arrays, let's go 支援する to the start of the program, 支援する to the part that initializes each element of bSeen to 無. We had....
bSeen[0]:=0; bSeen[1]:=0; bSeen[2]:=0; bSeen[3]:=0;
Remember the important "For... To... Do..." 声明 we met in the previous tutorial? If we 単に 追加する "bTmp:byte" to the variables 宣言, we can 取って代わる the four lines above with:
for bTmp:=1 to 4 do bSeen[bTmp]:=0;
Look at that closely; make sure you see what it's doing, why it 達成するs the same thing that the previous answer 達成するd. It may not see very impressive. However, consider what an 改良 it would be if 150 bSeen elements had to be initialized! And there are more subtle things that you can do which can only be done through the 力/強力にする of arrays.
And so to bed! Unless you want to go 支援する to the (米)棚上げする/(英)提議する of contents for another one? :-)
|
|
Page has been 実験(する)d for 同意/服従 with INDUSTRY (not MS-only) 基準s, using the 解放する/自由な, 公然と accessible validator at validator.w3.org. Mostly passes.
....... P a g e . . . E n d s .....