INFORMATION TECHNOLOGY CSEC CXC 10/25/20151. PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.

Slides:



Advertisements
Similar presentations
Andrew C. Samuels, Information Technology Specialist Trainer c/o Ministry of Education Mona High School, Kingston, Jamaica 1 Problem Solving Section 2:
Advertisements

Computer Programming w/ Eng. Applications
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
1 Programming in Pascal Presented by:- Zonal ICT Section- Kurunegala Education Zone.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Objectives You should be able to describe: Data Types
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
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.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Lecture 13 Midterm overview When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it: this is.
Input, Output, and Processing
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
Chapter 2: Using Data.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Introduction to Pascal The Basics of Program writing.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 6, Lecture 1 (Monday)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Programming, an introduction to Pascal
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Pascal Programming Today Chapter 11 1 Chapter 11.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
CPS120: Introduction to Computer Science Variables and Constants.
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,
1 Variables and Arithmetic Operators in JavaScript.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
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.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
Chapter 2 Introduction to C++ Programming
Data Types Variables are used in programs to store items of data e.g a name, a high score, an exam mark. The data stored in a variable is entered from.
BASIC ELEMENTS OF A COMPUTER PROGRAM
The CONST definition CONST Pi = , City = ‘New York’;
Computing Fundamentals
CMP 131 Introduction to Computer Programming
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Primitive Types and Expressions
C++ Programming Basics
COMPUTING.
Building Java Programs
Presentation transcript:

INFORMATION TECHNOLOGY CSEC CXC 10/25/20151

PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides a teaching language that highlights concepts common to all computer languages standardizes the language in such a way that it makes programs easy to write Strict rules make it difficult for the programmer to write bad code! 10/25/20152

Allows programmers to use complex data types (structured) easier to build dynamic and recursive data structures such as lists, trees and graphs Blaise Pascal, June 19, 1623 – August 19, /25/20153

defines a variable (data item) in such a way as a range of values which the variable is capable of storing, and it also defines a set of operations that are permissible to be performed on variables of that type Data type Range of values which the variable is capable of storing Integer Whole numbers from to Byte The integers from 0 to 255 Real Floating point numbers from 1E-38 to 1E+38 Boolean Can only have the value TRUE or FALSE Char Any character in the ASCII character set Shortint The integers from -128 to 127 Word The integers from 0 to Longint The integers from to /25/20154 Please note that four of these types of data (char, shortint, word, and longint) are not a part of the standard Pascal definition but are included as extensions to the TURBO Pascal compiler.

These statements are used to announce the Variables and Constants that are to be used in the program as well as the appropriate Data Type format they will take. 10/25/20155 var Identifier1, Identifier2: Data Type Identifier3 : Data Type; const Name = 'Tao Yue'; FirstLetter = 'a'; Year = 1997; pi = ; UsingNCSAMosaic = TRUE; var age, year, grade : integer; circumference : real; LetterGrade : char [1]; DidYouFail : Boolean; const Identifier1 = value; Identifier2 = value; Identifier3 = value;

Write a program in Pascal to display the phrase Hello, World! PROGRAM HelloWorld (output); BEGIN Writeln ('Hello, World!'); END. Parts of a Pascal Program: 1. Program Title (Header) – this tells the name of the program and may state the actions the program carries out. The title should not contain spaces or start with a number or have in a special character sign 10/25/ Body – this refers to the statements to be executed by the Compiler.

An Identifier is a name given to an item of data in a program. The Identifier name once used can only represent that one item of data when called or used in a program. The Identifier name should not begin with a number, special character or contains special characters. 10/25/20157 Name Age#Room Team 1 Full

Constants represents a value of data that remains fixed is not designed or expected to change. E.g. the number of days in a week could be set to 7 as there can be only 7 days in 1 week. The number of ounces in a pound of flour will always be 16 ounces represents 1 pound. 10/25/20158

Assignment Statements in programming are used to give a value to a variable/constant. The Assignment Statement can also change the value of a variable or constant. How to use this statement: variable_name := expression; E.g. carry a single value some_real := ; or an arithmetic sequence some_real := * / 367.1; 10/25/20159

10 div and mod only work on integers. / works on both reals and integers but will always yield a real answer. The other operations work on both reals and integers. When mixing integers and reals, the result will always be a real since data loss would result otherwise. This is why Pascal uses two different operations for division and integer division. 7 / 2 = 3.5 (real), but 7 div 2 = 3 (and 7 mod 2 = 1 since that's the remainder).

10/25/ Pascal compiler will not know if its to Multiply or Subtract. Use parentheses. Above is Pascal code not indented or properly, which makes for hard reading. Instead, indents are used on the right.

10/25/ Useful for on screen output See example on Average of 5 numbers using constants and displaying results. Use of read and readln read treats input as a stream of characters, with lines separated by a special end-of-line character. readln, on the other hand, will skip to the next line after reading a value, by automatically moving past the next end-of-line character:

10/25/ Use of the Write Statements Used to communicate results to the outside world. Used to print words on the terminal screen. Write (‘This is our first example of output.’); This is our first example of output.

PROGRAM First; {Demonstrates the use of Write Statements} BEGIN Write (‘This is our first example of output.’); END. 10/25/ OUTPUT ON SCREEN This is our first example of output. PROGRAM First; BEGIN write (‘This is our first example of output’.) BAD CODING

10/25/ With using the write statement in Pascal Programming, the write statement when used, leaves the cursor where it is after printing is complete. write (‘My name’); write (‘is Andrew’) My nameis Andrew PROGRAM OneLine (output); BEGIN write (‘My name’); write (‘is Andrew’); Readln; END. write (‘My name’); write (‘ is Andrew’); SPACE USED

10/25/ USE OF WRITELN STATEMENT With the use of the writeln statement for output, the compiler returns the cursor to the next line on screen. PROGRAM TwoLines (output); BEGIN writeln (‘My name’); writeln (‘is Andrew’); END. My name is Andrew

10/25/ PROGRAM Song (output); BEGIN write (‘This is the land’); writeln (‘ of my birth!’); write (‘This is the land’); writeln (‘ of my birth!’); writeln (‘this is Jamaica, my Jamaica,’); writeln (‘this is the land of my birth.’); Readln END. This is the land of my birth! this is Jamaica, my Jamaica, this is the land of my birth. Write a program in Pascal that displays the first stanza of the song “This is the land of my birth” by Eric Donaldson. Each line of output, should start on a new line.

PROGRAM Storing (output); {Demonstrates use of variables} VAR Length, Width, Area: integer; BEGIN Length := 152; Width := 32; Area := Length * Width; writeln(‘Length = ‘, Length, ‘ Width = ‘, Width, ‘ Area = ‘, Area); Readln; END. 10/25/ Length = 152 Width = 32 Area = 4864 Program that takes the value for Width as 32’ and Length 152’ of a Rectangle and calculate the Area.

PROGRAM Storing (output); {Demonstrates use of variables with assigned values}; VAR Length, Width, Area: integer; BEGIN Length:= 15; Width:= 20; Area:= Length * Width; writeln(‘Length = ‘, Length, ‘Width = ‘, Width, ‘Area = ‘ ‘Area); Length:= 20; Area:= Length * Width; writeln(‘Length = ‘, Length, ‘Width = ‘, Width, ‘Area = ‘ ‘Area); END. 10/25/ Output Length = 15 Width 20 Area = 250 Length = 20 Width 20 Area = 400

PROGRAM Salary (output); {Adds two salaries}; VAR Salary1, Salary2, Total: real; BEGIN Salary1:= ; Salary2:= ; Total:= Salary1 + Salary2; writeln (‘Salary Week 1 =$’, Salary1, ‘Salary Week 2 =$‘, Salary2, ‘and Total Salary =$’, Total); END. 10/25/ Salary Week 1 =$500.29, Salary Week 2 = $500.01, and Total Salary = $ Program that takes the value of two salary amounts $ and $ and provide the sum of both stored in a variable Total.

Write a program code in Pascal to take a time of.3 seconds and velocity of 24 and calculate the distance by use of the formula Time travelled times Velocity and output this distance on a new line. 10/25/ PROGRAM Distance (output); VAR Time, Velocity, Distance: real; BEGIN Time:=.3; Velocity:= 24; Distance:= Time * Velocity; writeln (‘Distance travelled is =‘, Distance); END. Distance Travelled = 7.2

PROGRAM Area (input, output); VARLength, Width: integer; Cost, Price: real; BEGIN writeln (‘Type in Length, Width and Price’); readln (Length, Width, Price); Cost:= (Length * Width) * Price; writeln (‘The cost is:=$ ‘, Cost); END. 10/25/ Write a program in Pascal to accept the Length and Width of a piece of lumber along with the price and provide the cost where Cost = Length x Width x Price. An output should be provided.

PROGRAM AreaVolume (input, output); CONST Pi = ; H = 6; VAR Volume, R: real; BEGIN writeln (‘Type in the radius.’); readln (R); Volume:= Pi * (R * R) * H; writeln (‘Volume = ‘, Volume); END. 10/25/ Write a program in Pascal that calculates the volume of a shape provided with the Pi as and Height being 6. The program should accept Radius and calculate the volume where Volume =