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

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 4: Selections.
Lecture 2 Introduction to C Programming
1 Programming in Pascal Presented by:- Zonal ICT Section- Kurunegala Education Zone.
Program Development Procedures 1.Program definition clearly define what the problem is. clearly define Input and output data (types, precision, units used)
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
J. Michael Moore Arrays CSCE 110. J. Michael Moore Typical (although simplified) Problem Write a program that will track student grades in a class. The.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Input and Output (IO) CSCE 110 Drawn from James Tam's material.
Pascal By: Liane Tom. Outline o Background o Data types and Syntax o Procedures and Functions o Advantages o Disadvantages.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 7 User-Defined Methods.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
CONTROL STATEMENTS IF-ELSE, SWITCH- CASE Introduction to Computer Science I - COMP 1005, 1405 Instructor : Behnam Hajian
 2006 Pearson Education, Inc. All rights reserved Arrays.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
ARRAYS 1.Basic Ideas 2.The Array Type 3.Processing Arrays 4.Parallel Arrays 5.Two-dimensional Array 6.Arrays as Parameters.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Chapter 3 Selections Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
CHAPTER 5 FUNCTIONS I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Introduction to Pascal The Basics of Program writing.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Selection Statements Selection Switch Conditional.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Programming, an introduction to Pascal
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Data Types Declarations Expressions Data storage C++ Basics.
Pascal Programming Today Chapter 11 1 Chapter 11.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
PASCAL PROGRAMMING.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Array : 1-dimension อนันต์ ผลเพิ่ม Anan Phonphoem
Pascal Programming George Boole, a 19 th Century mathematician, is created with true, false logic. A Boolean expression in Pascal will be true or false.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are created using a declaration statement. For example: Dim.
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Bill Tucker Austin Community College COSC 1315
Basic concepts of C++ Presented by Prof. Satyajit De
Definition of the Programming Language CPRL
Egyptian Language School Computer Department
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Written by Al.So. Software solutions
The CONST definition CONST Pi = , City = ‘New York’;
Chapter 3 Control Statements Lecturer: Mrs Rohani Hassan
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
Chapter 10 Programming Fundamentals with JavaScript
7 Arrays.
Presentation transcript:

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 * 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

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 * 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

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 * 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

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 = ; PROCEDURE AREA; BEGIN A := PI * R * R; END; PROGRAM HEADING CONSTANT DECLARATION PROGRAM BODY VARIABLE DECLARATION PROCEDURE DECLARATION

begin write(‘Enter the Test score:’); readln(Testscore); write(‘Enter the Examination score:’); readln(Examscore); Finalscore := TestScore * 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

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

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.

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!

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 TestScore fail passfail Status

TestScore : array [1..4] of integer; 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 Studentheight Grade : array [1..4] of char; Ex 4 BCAD Grade LetterCount : array [‘A’..’Z’] of integer; Ex LetterCount …….

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 * Examscore * 0.7; 12 if Finalscore < 50 then 13 Status = ’PASS’ 14 else; 15 Status = ‘FAIL’; 16 writeln(Statu) 17 End.