Presentation is loading. Please wait.

Presentation is loading. Please wait.

Program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter.

Similar presentations


Presentation on theme: "Program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter."— Presentation transcript:

1 program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter the Examination score:’); readln(Examscore); Finalscore := TestScore * 0.3 + Examscore * 0.7; if Finalscore >= 50 then Status := ‘Pass’ else Status := ‘FAIL’; writeln(Status) end. Reserved words – words having special meanings in Pascal. User-Defined Identifier – defined by users. Test Score Test _Score TestScore2 testscore Test Score TestScore% 2TestScore if OK NOT OK Standard Identifier – predefined by Pascal. CH 2 – INTRODUCTION TO PASCAL PROGRAMMING

2 program CheckPass ; var TestScore, ExamScore : integer ; FinalScore : real ; Status : string ; begin write ( ‘ Enter the Test score: ’ ) ; readln ( Testscore ) ; write ( ‘ Enter the Examination score: ’ ) ; readln ( Examscore ); Finalscore := TestScore * 0.3 + Examscore * 0.7 ; if Finalscore >= 50 then Status := ‘ Pass ’ else Status := ‘ FAIL ’; writeln ( ‘ The result is ’, Status ) end. := assigns values to variables : separate variables/data type identifier, separate items in a list +,-, *,/ arithmetic operators =,<>,,>=,<= relational operators () enclose arguments of procedures, functions. enclose arguments of procedures, functions ; separate statements, added at the end except then, else, end until ‘’ enclose characters or string

3 program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status: string; begin (* Get Score *) write(‘Enter the Test score:’); readln(Testscore); write(‘Enter the Examination score:’); readln(Examscore); (* Calculate the final Score *) Finalscore := TestScore * 0.3 + Examscore * 0.7; (* Check Status *) if Finalscore >= 50 then Status := ‘Pass’ else Status := ‘FAIL’; (*Display Status *) writeln(Status) end. Comments (* *) remarks – improve readability Ignored by computers during compilation or executed

4 BEGIN WRITELN(‘Enter Radius’); READLN(R); AREA; WRITELN(‘The circle area is ’, A:0:2); END. BASIC STRUCTURE OF A PASCAL PROGRAM PROGRAM AreaCircle; VAR R, A : real; CONST PI = 3.1416; PROCEDURE AREA; BEGIN A := PI * R * R; END; PROGRAM HEADING CONSTANT DECLARATION PROGRAM BODY VARIABLE DECLARATION PROCEDURE DECLARATION

5 begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter the Examination score:’); readln(Examscore); Finalscore := TestScore * 0.3 + Examscore * 0.7; if Finalscore >= 50 then Status := ‘Pass’ else Status := ‘FAIL’; writeln(Status) end. BASIC STRUCTURE OF A PASCAL PROGRAM program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; PROGRAM HEADING VARIABLE DECLARATION PROGRAM BODY

6 2.3 BASIC DATA TYPE IN PASCAL INTEGER REAL CHAR STRING BOOLEAN ARRAY -32728, -32727, …. -2, -1, 0, 1, 2, ………, 32726, 32727 123.45 0.00123 -12345.0 -0.00000123 ‘E’ ‘A’ ‘1’, ‘2’ ‘%’ ‘ □ ’ ‘PASS’ ‘FAIL’ ‘Enter Test Score’ ’45’ ‘Our Lady’’s College’ ‘’ TRUE FALSE 3221455423 ………. TestScore

7 PROGRAM STUDENTRECORD; VAR AGE: INTEGER; HEIGHT : REAL; CONDUCT : CHAR; NAME, CLASSNO, ADDRESS : STRING; TESTS : ARRAY[1..6] OF INTEGER; BEGIN AGE := 15; HEIGHT := 5.7; CONDUCT := ‘B’ ; NAME := ‘PETER CHAN’ ; CLASSNO := ‘4C’ ; ADDRESS := ’4/F, 23, NATHEN ROAD, MONGKOK’ ; TESTS[1] := 56; TESTS[2] :=78; TESTS[3] := 45; TESTS[4] := 67; END.

8 program CheckPass; var TestScore1, TestScore2, TestScore3,, TestScore4 : integer; Status1, Status2, Status3, Status4: string; begin readln(Testscore1); readln(Testscore2); readln(Testscore3); readln(Testscore4); if Testscore1 >= 50 then Status1 := ‘pass’ else Status1 := ‘fail’; if Testscore2 >= 50 then Status2 := ‘pass’ else Status2 := ‘fail’; if Testscore3 >= 50 then Status3 := ‘pass’ else Status3 := ‘fail’; if Testscore4 >= 50 then Status4 := ‘pass’ else Status4 := ‘fail’; end. WHY ARRAY? Supposed five students in the class. need to declare 5 variables to store their test scores! And 5 input statements to read their scores! And 5 IF statements to test their status!

9 program CheckPass; var TestScore: array[1..4] of integer; Status: array[1..4] of string; I : integer; begin for I := 1 to 4 do readln(Testscore[I]) for I := 1 to 4 do if Testscore[I]>= 50 then Status[I] := ‘pass’ else Status[I] := ‘fail’; end. 21455423 TestScore fail passfail Status

10 TestScore : array [1..4] of integer; 21455423 TestScore VARIABLE NAME : array [LOWER BOUND.. UPPER BOUND ] of ; DECLARE VARIABLE OF ARRAY DATA TYPE Ex 1 Status : array [1..4] of string;Ex 2 fail passfail Status Studentheight : array [1..4] of real; Ex 3 5.36.25.95.1 Studentheight Grade : array [1..4] of char; Ex 4 BCAD Grade LetterCount : array [‘A’..’Z’] of integer; Ex 5 20123 34 LetterCount …….

11 Identify errors below and state the type of errors Line No Type Of Errors : Syntax, Runtime, Logical Corrections 1 Program FinalScore; 2 Var 3 TestScore, ExamScore : real; 4 FinalScore: integer; 5 Status: char; 6 Begin 7 write (‘Enter the Test score:’) 8 Readln(Testscore); 9 write (Enter the Examination score:); 10 readln(Examscore); 11 Finalscore = TestScore * 0.3 + Examscore * 0.7; 12 if Finalscore < 50 then 13 Status = ’PASS’ 14 else; 15 Status = ‘FAIL’; 16 writeln(Statu) 17 End.


Download ppt "Program CheckPass; var TestScore, ExamScore : integer; FinalScore : real; Status : string; begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter."

Similar presentations


Ads by Google