1.variables: we always use "var" to declare variables, there are lot
of common used variables in pascal programming:
character- a ASCII code character
String -a set of character
integer -a complete number
real -a non-complete number
sample 1:
program declare_variables;
var
S:string;
I,J:integer;
R,Q:Real;
C:char;
begin
{put value to variables: inputing and outputing? see next part}
I:=1; {put 1 to I}
R:=3.14 {put 3.14 to R}
S:='ABC'; {put string "ABC" to S}
C:='C'; {put character "C" to C}
{calculate integer and real}
I:=I+J; {I equal to I + J}
I:=I-J; {I equal to I - J}
I:=I * J {I equal to I x J}
I:=I div J {I equal to I / J ,remainer cutted}
R:=R / Q {method of divide in real,remainer remained}
I:=1 mod J {I equal to remainer of I / J}
end.
2. writeln: writeln is a function which can output somethings, variables
and string on the screen for a line:
sample 2:
program PRINTstring;
begin
writeln( ' helloevery body! ' );
end.
sample 3:
program PRINTvariable; {all variables are allowed to use this method}
var
bbq:string;
I :integer;
begin
bbq:=' welcome ';
I:=5;
writeln( 'you are',bbq);
writeln(' you are the ', I ,' member of my TPCL club');
writeln; {this line is used to print an empty line}
end.
3.write, write is a function like writeln ,but it not output for a line,
you can find out answer to compare with sample 3 by run that:
sample 4:
program WRITEfunction;
var
I:integer;
begin
I:=5;
write( ' YOU ARE WELLCOME,');
write(' you are the ', I, 'member of my club');
end.
4.readln: readln is a function that read user input:
sample 5:
program READLNfunction;
var
I:integer;
R:real;
S:string;
C:char;
begin
write('input your baby's D.O.B here:');
readln(I); write('input your baby's name here:');
readln(S); write('input your baby's weight here:');
readln(R); write('enter your baby's inital here:');
readln(C);
writeln;
writeln('you baby's information D.O.B.',I,' weight',R);
writeln(' and name ',S);
end.
home work: try to write a program new account setting of money storage in bank,process include: input name of user,input ammount of money input,input date of "input" and "output" money, input rate(%) of account , input output money will be taken out at "output" money time, answer(source) will give to you tomorrow..
Next >>