A/L 2011_revision. PASCAL PROGRAMMING

Size: px
Start display at page:

Download "A/L 2011_revision. PASCAL PROGRAMMING"

Transcription

1 Pascal is a high level programming language developed by Niklaus Wirth in 1970 based on the ALGOL programming language. It was named in honor of the French mathematician and philosopher Blaise Pascal. Pascal programs saved as *.pas. Variables Constants Control Flow Procedures Functions Comments store values/data stay the same change directions sub routines sub routines returning a value notes Structure of a Pascal program PROGRAM ProgramName (FileList); uses crt; (*importing libraries) const (* Constant declarations *) type (* Type declarations *) (* Variable declarations *) (* Subprogram definitions *) (* Main Program statements *) program FirstProg; Writeln('Hello World!'); page 1 of 8

2 VARIABLES CONSTANTS Must with a letter Can include alphanumeric characters and underscore (_). May not contain # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < >?,. / Value assigned to a constant at the ning of the program. It can t be changed during the program running. Const Pi = ; Gravity = 9.8; GoldenRatio = 1.6; a : real = 12; page 2 of 8

3 VARIABLES AND DATA TYPES Var IdentifierList1 : DataType1; IdentifierList2 : DataType2; IdentifierList3 : DataType3; The basic data types integer From to real () 3.4x10-38 to 3.4x10 38 Char string Boolean A Niranjan TRUE and FALSE IndexNumber, Age: integer Temperature :real; FirstName: string; Married: Boolean ASSIGNMENT AND OPERATIONS iable_name := expression; length := ; totalarea := (37.57 * 5.93) + (38.2/2.1); page 3 of 8

4 OPERATORS + Addition - Subtraction * Multiplication / Division div Integer division mod Modulus (remainder division) PUNCTUATION AND INDENTATION Pascal ignores end-of-lines and spaces. punctuation (;) tells the compiler when a statement ends. program Compute; const a = 5; b = 385.3; alpha, beta : real; (* main *) alpha := a + b; beta := b / a (* main *) COMMENTS (* one line *) (* some comments go into several lines*) page 4 of 8

5 INPUT / OUTPUT read (Variable_List); readln (Variable_List); read (a); readln (b); read (a, b, c, d); readln (e, f); write (Argument_List); writeln (Argument_List); write (a); writeln (b,c,d); write ('Time:', time:2); program InputOutput; a, b : string; (* main *) read(a); readln(b); writeln(a) writeln(a) page 5 of 8

6 CONDITIONALS RELATIONAL OPERATORS: < > = <= >= <> less than greater than equal to less than or equal to greater than or equal to not equal to 5 < 7 2 > 1 4=3+1 2<=3 10>=5 A <> B IF THEN if BooleanExpression then Statement1; if A = 30 then Writeln('A is equal to 30'); IF THEN. ELSE if BooleanExpression then StatementIfTrue else StatementIfFalse; if A = 30 then Writeln('A is equal to 30') else Writeln('A is not equal to 30'); page 6 of 8

7 NESTED IF if Condition1 then Statement1 else if Condition2 then Statement2 if A=30 then Writeln('A is equal to 30'); else if A=50 then Writeln('A is equal to 50'); else Statement3; else Writeln('A is not 30 or 50'); CASE case selector of List1: Statement1; List2: Statement2;... Listn: Statementn; Choice := ReadKey; case Choice of 'a': Writeln('You like apples'); 'b': Writeln('You like bananas'); 'c': Writeln('You like carrots'); else Writeln('Your choice is not a, b or c'); otherwise Statement page 7 of 8

8 LOOPING FOR NEXT for index := Low to High do statements; sum := 0; for count := 1 to 100 do sum := sum + count; WHILE.. DO while BooleanExpression do statements; a := 5; while a < 6 do writeln (a); a := a + 1 REPEAT UNTIL repeat statement1; until BooleanExpression; a := 5; repeat a := a + 1; writeln (a); until a > 10 GOTO LABEL 10; statements; GOTO 10; page 8 of 8

9 BREAK and CONTINUE The Break command will exit a loop at any time. program breaktest; i: Integer; i := 0; repeat i := i + 1; break; Writeln(i); until i = 10; program breaktest; i: Integer; i := 0; repeat i := i + 1; continue; Writeln(i); until i = 10; Program 1 will not print anything because break it exits the loop before it gets there. In Program 2 continue command will jump back to the top of a loop ARRAYS X: ARRAY [1..5] of real; X[1]:=4.2; X[2]:=71.6; X[3]:=8.3; X[4]:=92.6; X[5]:=403.7; writeln (X[1]+X[2]+X[3]+X[4]+X[5]) page 9 of 8

10 PROCEDURES & FUNCTIONS Procedure has the same basic format as a program: procedure Name; const (* Constants *) Var (* Variables *) Begin (* Statements *) Parameters to the procedure passed in the heading procedure PrintParameters (a, b : integer; c, d : real); a := 10; b := 2; writeln (a, b, c, d) FUNCTIONS function functionname (parameter_list) : return_type; statements; BUILT IN FUNCTIONS function add1toparameter(a) : integer; add1toparameter:= a + 1 abs returns absolute value arctan returns arctan in radians cos returns cosine of a radian measure sin returns sin of a radian measure sqr returns square (power 2) sqrt returns root (power 1/2) chr character with given ASCII value round returns round to nearest integer page 10 of 8

11 MATH FUNTIONS ABS(-6) the absolute value of -6; gives 6 SQR(3) the square of 3; gives 9 SQRT(9) the square root of 9; gives 3.0 SIN(2) the sine of 2 radians measure COS(2) the cosine of 2 radians measure LN(9) the natural logarithm of 9; gives log e 9 ROUND(9.2) rounds a number; gives 9 Functions are used to do repetitive tasks to reduce repeating code. program AddEmUpAgain; function AddEmUp( a, b, c: integer ) : integer; AddEmUp := a + b + c; procedure PrintData( a, b, c: integer ); Writeln('The sum of a, b, and c is ', AddEmUp(a, b, c), '.'); PrintData(2, 3, 4); page 11 of 8

12 SAMPLE PROGRAMS Find the sum and average of five numbers program SumAverage; const NumberOfIntegers = 5; A, B, C, D, E : integer; Sum : integer; Average : real; (* Main *) A := 45; B := 7; C := 68; D := 2; E := 34; Sum := A + B + C + D + E; Average := Sum / NumberOfIntegers; writeln ('Number of integers = ', NumberOfIntegers); writeln ('Number1 = ', A); writeln ('Number2 = ', B); writeln ('Number3 = ', C); writeln ('Number4 = ', D); writeln ('Number5 = ', E); writeln ('Sum = ', Sum); writeln ('Average = ', Average) (* Main *) page 12 of 8

13 Input 5 numbers and print their sum and average program SumAverage; const NumberOfIntegers = 5; A, B, C, D, E : integer; Sum : integer; Average : real; (* Main *) write ('Enter the first number: '); readln (A); write ('Enter the second number: '); readln (B); write ('Enter the third number: '); readln (C); write ('Enter the fourth number: '); readln (D); write ('Enter the fifth number: '); readln (E); Sum := A + B + C + D + E; Average := Sum / 5; writeln ('Number of integers = ', NumberOfIntegers); writeln; writeln ('Number1:', A:8); writeln ('Number2:', B:8); writeln ('Number3:', C:8); writeln ('Number4:', D:8); writeln ('Number5:', E:8); writeln ('================'); writeln ('Sum:', Sum:12); writeln ('Average:', Average:10:1); page 13 of 8

14 SCOPE Where will the iables be visible? program ScopeDemo; A, B : integer; procedure ScopeInner; B:= 10; writeln (B); (* prints value 10 *) writeln (A); (* prints value 20 *) (* Main *) A := 20; writeln (A); (* prints value 20 *) ScopeInner; (*changes A value*) writeln (A); (* prints new value 10*) (* Main *) global iables A visible everywhere global iables can be changed inside procedures. page 14 of 8

15 RCURSION Recursion allows a function or procedure to call itself function Sum (num : integer) : integer; if num = 1 then Sum := 1 else Sum := Sum(num-1) + num;(* calls self again*) totalsum:=sum(10); writeln(totalsum); If we call Sum with 3 as parameter totalsum := Sum(3); 1 st call : Sum(3) becomes Sum(2) nd call : Sum(2) becomes Sum(1) + 2. At 1, the recursion stops and becomes 1 and returns Sum(2) becomes = 3. Sum(3) becomes = 6. a becomes 6. page 15 of 8

16 FORWARD REFERENCING procedures/functions can only use iables and subprograms already defined before them. (this is a weakness in Pascal coding) procedure Second (parameter list); procedure First (parameter list); procedure Third (parameter list); procedure First; Second (parameter list);(*second is declared before First *) procedure Second; Third (parameter list); (* ERROR Third is not visible to Second*) page 16 of 8

17 Find the first 100 numbers in the Fibonacci sequence program Fibonacci; Fibonacci1, Fibonacci2 : integer; temp : integer; count : integer; (* Main *) writeln ('First ten Fibonacci numbers are:'); count := 0; Fibonacci1 := 0; Fibonacci2 := 1; repeat write (Fibonacci2:7); temp := Fibonacci2; Fibonacci2 := Fibonacci1 + Fibonacci2; Fibonacci1 := Temp; count := count + 1 until count = 10; writeln; (*you can also use a FOR loop or a WHILE loop. *) (* Main *) ASSIGNMENT Modify above program to display all powers of 2 up to 200. What code would you change and why? page 17 of 8

18 FILE HANDLING Reading and Writing to Files read (file_iable, argument_list); write (file_iable, argument_list); rest (file_iable, 'filename' ) rewrite (file_iable, 'filename'); assign (file_iable, 'filename'); eoln (file_iable) eof (file_iable) Reads values from a file Write values to a file Opens a file for reading Opens a file for writing Assigns a filename to a iable Returns TRUE when end of line is reached Returns TRUE when end of file is reached program CopyOneByteFile; mychar : char; filein, fileout : text; assign (filein, 'c:\file1.txt'); reset (filein); assign (fileout, 'c:\file2.txt'); rewrite (fileout); read (filein, mychar); write (fileout, mychar); close(filein); close(fileout) page 18 of 8

19 BOOLEAN EXPRESSIONS not and or xor negation conjunction disjunction exclusive-or (~) (^) (v) NOT applied to only one value to invert it: NOT true = false NOT false = true AND gives TRUE only if both values are TRUE: TRUE and FALSE = FALSE TRUE and TRUE = TRUE OR yields TRUE if at least one value is TRUE: TRUE or TRUE = TRUE TRUE or FALSE = TRUE FALSE or TRUE = TRUE FALSE or FALSE = FALSE XOR yields TRUE if one expression is TRUE and the other is FALSE. TRUE xor TRUE = FALSE TRUE xor FALSE = TRUE FALSE xor TRUE = TRUE FALSE xor FALSE = FALSE page 19 of 8

20 Bubble sort moves the biggest numbers to the end of the array. Example of Sorting 5 Numbers program BubbleSort; a: array[1..5] of Integer; i, j, tmp: Integer; a[1] := 23; a[2] := 45; a[3] := 12; a[4] := 56; a[5] := 34; for i := 1 to 4 do for j := i + 1 to 5 do if a[i] > a[j] then tmp := a[i]; a[i] := a[j]; a[j] := tmp; for i := 1 to 5 do writeln(i,': ',a[i]); page 20 of 8

21 Programming Solution: the Towers of Hanoi Problem program TowersofHanoi; numdiscs : integer; procedure DoTowers (NumDiscs, OrigPeg, NewPeg, TempPeg : integer); (* Explanation of iables Number of discs -- number of discs on OrigPeg OrigPeg -- peg number of the tower NewPeg -- peg number to move the tower to TempPeg -- peg to use for temporary storage*) (* Take care of the base case -- one disc *) if NumDiscs = 1 then writeln (OrigPeg, ' ---> ', NewPeg) (* Take care of all other cases *) else (* First, move all discs except the bottom disc to TempPeg, using NewPeg as the temporary peg for this transfer *) Tower of Hanoi is a problem with three pegs and more than 3 disks on one peg. You have to move disks one by one from peg to peg to transfer all disks to one peg. Rules 1. Only one disk can be transferred at a time. 2. Smaller disk should always be on the top of the other. DoTowers (NumDiscs-1, OrigPeg, TempPeg, NewPeg); (* Now, move the bottom most disc from OrigPeg to NewPeg *) writeln (OrigPeg, ' ---> ', NewPeg); (* Finally, move the discs currently on TempPeg to NewPeg, use OrigPeg as the temporary peg for this transfer *) DoTowers (NumDiscs-1, TempPeg, NewPeg, OrigPeg) end (* Main *) write ('Please enter the number of discs in the tower ===> ') readln (numdiscs); writeln; DoTowers (numdiscs, 1, 3, 2) (* Main *) page 21 of 8

22 program Decisions; i: Integer; Writeln('Enter a number'); Readln(i); if i > 5 then Writeln('Greater than 5'); program Decisions; i: Integer; Writeln('Enter a number'); Readln(i); if i > 5 then Writeln('Greater than 5') else Writeln('Not greater than 5'); program Loops1; i: Integer; i := 0; while i <= 10 i := i + 1; Writeln('Hello'); program Loops2; i: Integer; i := 0; repeat i := i + 1; Writeln('Hello'); until i = 10; Download FREE Pascal Created by: Niranjan Meegammana, Shilpa Sayura Project. Supported by YES & OSIPTO, KANDY. page 22 of 8

Getting Started With Pascal Programming

Getting Started With Pascal Programming Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables and constants Input and output Pascal operators Common programming errors

More information

Quick Reference Guide

Quick Reference Guide SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Pascal language This reference guide

More information

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Macro Programming Reference Guide. Copyright 2005 Scott Martinez Macro Programming Reference Guide Copyright 2005 Scott Martinez Section 1. Section 2. Section 3. Section 4. Section 5. Section 6. Section 7. What is macro programming What are Variables What are Expressions

More information

Getting Started With Pascal Programming

Getting Started With Pascal Programming Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables and constants Input and output Common programming errors Computer Programs

More information

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems

History. used in early Mac development notable systems in Pascal Skype TeX embedded systems Overview The Pascal Programming Language (with material from tutorialspoint.com) Background & History Features Hello, world! General Syntax Variables/Data Types Operators Conditional Statements Functions

More information

Quick Reference Guide

Quick Reference Guide SOFTWARE AND HARDWARE SOLUTIONS FOR THE EMBEDDED WORLD mikroelektronika Development tools - Books - Compilers Quick Reference Quick Reference Guide with EXAMPLES for Basic language This reference guide

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

Functions. Systems Programming Concepts

Functions. Systems Programming Concepts Functions Systems Programming Concepts Functions Simple Function Example Function Prototype and Declaration Math Library Functions Function Definition Header Files Random Number Generator Call by Value

More information

520 Principles of Programming Languages. Arithmetic. Variable Declarations. 19: Pascal

520 Principles of Programming Languages. Arithmetic. Variable Declarations. 19: Pascal Structure of a Pascal Program 520 Principles of Programming Languages 19: Pascal Christian Collberg collberg@cs.arizona.edu Department of Computer Science University of Arizona PROGRAM Name (list of files);

More information

How to Design Programs Languages

How to Design Programs Languages How to Design Programs Languages Version 4.1 August 12, 2008 The languages documented in this manual are provided by DrScheme to be used with the How to Design Programs book. 1 Contents 1 Beginning Student

More information

Outline. Data and Operations. Data Types. Integral Types

Outline. Data and Operations. Data Types. Integral Types Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

More information

COMPUTER SCIENCES II Spring Term 2017 Asst.Prof.Elgin KILIÇ

COMPUTER SCIENCES II Spring Term 2017 Asst.Prof.Elgin KILIÇ COMPUTER SCIENCES II Spring Term 2017 Asst.Prof.Elgin KILIÇ TURBO PASCAL WEEK 2 DECLARATION BLOCKS in DETAIL Uses There default sub pascal programs called UNITS which are already embedded in pascal editor.

More information

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4 BIL 104E Introduction to Scientific and Engineering Computing Lecture 4 Introduction Divide and Conquer Construct a program from smaller pieces or components These smaller pieces are called modules Functions

More information

Making Decisions In Pascal

Making Decisions In Pascal Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action High Level View Of Decision Making For The Computer??? True

More information

REVIEW. The C++ Programming Language. CS 151 Review #2

REVIEW. The C++ Programming Language. CS 151 Review #2 REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,

More information

DelphiScript Keywords

DelphiScript Keywords DelphiScript Keywords Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 This reference covers the DelphiScript keywords used for the Scripting System in Altium Designer. The scripting

More information

Making Decisions In Pascal

Making Decisions In Pascal Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs choose between alternative courses of action High Level View Of Decision Making For The Computer Is income

More information

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2 1 BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER Chapter 2 2 3 Types of Problems that can be solved on computers : Computational problems involving some kind of mathematical processing Logical Problems

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson)

Dr M Kasim A Jalil. Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Lecture 9 Functions Dr M Kasim A Jalil Faculty of Mechanical Engineering UTM (source: Deitel Associates & Pearson) Objectives In this chapter, you will learn: To understand how to construct programs modularly

More information

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

More information

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way

Control Structures. Outline. In Text: Chapter 8. Control structures Selection. Iteration. Gotos Guarded statements. One-way Two-way Multi-way Control Structures In Text: Chapter 8 1 Control structures Selection One-way Two-way Multi-way Iteration Counter-controlled Logically-controlled Gotos Guarded statements Outline Chapter 8: Control Structures

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

{ -- FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '84 } { -- PASCAL PROGRAM SOLUTIONS }

{ -- FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '84 } { -- PASCAL PROGRAM SOLUTIONS } { -- FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '84 } { -- PASCAL PROGRAM SOLUTIONS } {1.1} program One1T84; { -- This program produces a table of Fahrenheit for Celcius. } C: Integer; Writeln ('CELCIUS

More information

VBScript: Math Functions

VBScript: Math Functions C h a p t e r 3 VBScript: Math Functions In this chapter, you will learn how to use the following VBScript functions to World Class standards: 1. Writing Math Equations in VBScripts 2. Beginning a New

More information

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

More information

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Functions. Functions are everywhere in C. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR 1 Functions Functions are everywhere in C Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR Introduction Function A self-contained program segment that carries

More information

Basic types and definitions. Chapter 3 of Thompson

Basic types and definitions. Chapter 3 of Thompson Basic types and definitions Chapter 3 of Thompson Booleans [named after logician George Boole] Boolean values True and False are the result of tests are two numbers equal is one smaller than the other

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

Chapter 7 - Notes User-Defined Functions II

Chapter 7 - Notes User-Defined Functions II Chapter 7 - Notes User-Defined Functions II I. VOID Functions ( The use of a void function is done as a stand alone statement.) A. Void Functions without Parameters 1. Syntax: void functionname ( void

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Chapter 3 - Functions

Chapter 3 - Functions Chapter 3 - Functions 1 Outline 3.1 Introduction 3.2 Program Components in C++ 3.3 Math Library Functions 3.4 Functions 3.5 Function Definitions 3.6 Function Prototypes 3.7 Header Files 3.8 Random Number

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

Programmers should write code that is self-documenting and split into small sections.

Programmers should write code that is self-documenting and split into small sections. Writing Programs What are good program writing techniques? Programmers should write code that is self-documenting and split into small sections. Specifically, the programmers should: use meaningful identifier

More information

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool

More information

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals

Fall Semester (081) Dr. El-Sayed El-Alfy Computer Science Department King Fahd University of Petroleum and Minerals INTERNET PROTOCOLS AND CLIENT-SERVER PROGRAMMING Client SWE344 request Internet response Fall Semester 2008-2009 (081) Server Module 2.1: C# Programming Essentials (Part 1) Dr. El-Sayed El-Alfy Computer

More information

In Delphi script, when values are assigned to variables, the colon-equal operator is used; :=

In Delphi script, when values are assigned to variables, the colon-equal operator is used; := Statements and Operators Old Content - visit altium.com/documentation Modified by on 13-Sep-2017 Parent page: DelphiScript DelphiScript Statements A statement in DelphiScript is considered as simple when

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Downloaded from Chapter 2. Functions

Downloaded from   Chapter 2. Functions Chapter 2 Functions After studying this lesson, students will be able to: Understand and apply the concept of module programming Write functions Identify and invoke appropriate predefined functions Create

More information

What did we talk about last time? Examples switch statements

What did we talk about last time? Examples switch statements Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ FUNCTIONS. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ FUNCTIONS Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Functions: Program modules in C Function Definitions Function

More information

Subprograms A Procedure with No Parameters A Procedure with One Parameter Variable Parameters in Procedures

Subprograms A Procedure with No Parameters A Procedure with One Parameter Variable Parameters in Procedures 275 Chapter 16 Subprograms 16.1 Functions 16.2 A Procedure with No Parameters 16.3 A Procedure with One Parameter 16.4 Variable Parameters in Procedures 16.5 Predefined Procedures and Functions 16.6 Recursive

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

CSCE 110 PROGRAMMING FUNDAMENTALS

CSCE 110 PROGRAMMING FUNDAMENTALS CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 2. Overview of C++ Prof. Amr Goneid, AUC 1 Overview of C++ Prof. Amr Goneid, AUC 2 Overview of C++ Historical C++ Basics Some Library

More information

1 Programming. 1.1 Analyzing a problem

1 Programming. 1.1 Analyzing a problem 1 Programming The chapter concerns the following; ² How to analyze a problem and develop an algorithm ² Control structures and their use ² ² Finding alternate solutions to a problem ² Programming in Pascal

More information

Introduction to C Final Review Chapters 1-6 & 13

Introduction to C Final Review Chapters 1-6 & 13 Introduction to C Final Review Chapters 1-6 & 13 Variables (Lecture Notes 2) Identifiers You must always define an identifier for a variable Declare and define variables before they are called in an expression

More information

Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs to execute alternatives

Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs to execute alternatives Making Decisions In Pascal In this section of notes you will learn how to have your Pascal programs to execute alternatives Decision-Making In Pascal Decisions are questions that are either true or false

More information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

Computer Science II TURBO PASCAL

Computer Science II TURBO PASCAL Computer Science II TURBO PASCAL WEEK6 LOOP structures Dr.ELGİN KILIÇ Loop Type Description while-do loop Repeats a statement or group of statements while a given condition is true. It tests the condition

More information

CSE123. Program Design and Modular Programming Functions 1-1

CSE123. Program Design and Modular Programming Functions 1-1 CSE123 Program Design and Modular Programming Functions 1-1 5.1 Introduction A function in C is a small sub-program performs a particular task, supports the concept of modular programming design techniques.

More information

Functions and Recursion

Functions and Recursion Functions and Recursion CSE 130: Introduction to Programming in C Stony Brook University Software Reuse Laziness is a virtue among programmers Often, a given task must be performed multiple times Instead

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

Creating a C++ Program

Creating a C++ Program 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. 1 Creating a C++ Program created using an

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

Getting Started With Pascal Programming

Getting Started With Pascal Programming Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables and constants Input and output Pascal operators Common programming errors

More information

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review StudyHub+ 1 StudyHub: AP Java Semester One Final Review StudyHub+ 2 Terminology: Primitive Data Type: Most basic data types in the Java language. The eight primitive data types are: Char: A single character

More information

Basics of ST. Each must end with a semi-colon (";") Basic statement. Q:=IN; Q:=sin(angle); Q := (IN1 + (IN2 / IN 3)) * IN4;

Basics of ST. Each must end with a semi-colon (;) Basic statement. Q:=IN; Q:=sin(angle); Q := (IN1 + (IN2 / IN 3)) * IN4; Excerpt of tutorial developed at University of Auckland by Gulnara Zhabelova Based on Dr. Valeriy Vyatkin s book IEC 61499 Function Blocks for Embedded and Distributed Control Systems Design, Second Edition

More information

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction

Functions. Prof. Indranil Sen Gupta. Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur. Introduction Functions Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute t of Technology Kharagpur Programming and Data Structure 1 Function Introduction A self-contained program segment that

More information

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

More information

Chapter 2: Overview of C. Problem Solving & Program Design in C

Chapter 2: Overview of C. Problem Solving & Program Design in C Chapter 2: Overview of C Problem Solving & Program Design in C Addison Wesley is an imprint of Why Learn C? Compact, fast, and powerful High-level Language Standard for program development (wide acceptance)

More information

Chapter-8 DATA TYPES. Introduction. Variable:

Chapter-8 DATA TYPES. Introduction. Variable: Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include

More information

Expressions. Eric McCreath

Expressions. Eric McCreath Expressions Eric McCreath 2 Expressions on integers There is the standard set of interger operators in c. We have: y = 4 + 7; // add y = 7-3; // subtract y = 3 * x; // multiply y = x / 3; // integer divide

More information

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 4. Procedural Abstraction and Functions That Return a Value. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 4 Procedural Abstraction and Functions That Return a Value 1 Overview 4.1 Top-Down Design 4.2 Predefined Functions 4.3 Programmer-Defined Functions 4.4 Procedural Abstraction 4.5 Local Variables

More information

CSc 520. Principles of Programming Languages 11: Haskell Basics

CSc 520. Principles of Programming Languages 11: Haskell Basics CSc 520 Principles of Programming Languages 11: Haskell Basics Christian Collberg Department of Computer Science University of Arizona collberg@cs.arizona.edu Copyright c 2005 Christian Collberg April

More information

Chapter 5 Selection Statements. Mr. Dave Clausen La Cañada High School

Chapter 5 Selection Statements. Mr. Dave Clausen La Cañada High School Chapter 5 Selection Statements Mr. Dave Clausen La Cañada High School Objectives Construct and evaluate Boolean expressions Understand how to use selection statements to make decisions Design and test

More information

Ch. 7: Control Structures

Ch. 7: Control Structures Ch. 7: Control Structures I. Introduction A. Flow of control can be at multiple levels: within expressions, among statements (discussed here), and among units. B. Computation in imperative languages uses

More information

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Functions. Lecture 6 COP 3014 Spring February 11, 2018 Functions Lecture 6 COP 3014 Spring 2018 February 11, 2018 Functions A function is a reusable portion of a program, sometimes called a procedure or subroutine. Like a mini-program (or subprogram) in its

More information

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements Evolution: - FORTRAN I control statements were based directly on IBM 704 hardware - Much research and argument

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

COMP322 - Introduction to C++ Lecture 02 - Basics of C++ COMP322 - Introduction to C++ Lecture 02 - Basics of C++ School of Computer Science 16 January 2012 C++ basics - Arithmetic operators Where possible, C++ will automatically convert among the basic types.

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Pascal Validation Suite Report

Pascal Validation Suite Report Pascal Validation Suite Report Pascal processor identification The ACK-Pascal compiler produces code for an EM machine as defined in [1]. It is up to the implementor of the EM machine whether errors like

More information

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char Review Primitive Data Types & Variables int, long float, double boolean char String Mathematical operators: + - * / % Comparison: < > = == 1 1.3 Conditionals and Loops Introduction to Programming in

More information

Introduction to the C++ Programming Language

Introduction to the C++ Programming Language LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming

More information

FORM 4 PASCAL PROGRAMMING 6.1 WHAT IS AN ARRAY? Unit 6: Arrays and Strings

FORM 4 PASCAL PROGRAMMING 6.1 WHAT IS AN ARRAY? Unit 6: Arrays and Strings Unit 6 Arrays and Strings FORM 4 PASCAL PROGRAMMING Unit 6 Arrays and Strings http//www.i-garden.org March, 01 6.1 WHAT IS AN ARRAY? is a structured data type in which we store a collection of data items

More information

Annex A (Informative) Collected syntax The nonterminal symbols pointer-type, program, signed-number, simple-type, special-symbol, and structured-type

Annex A (Informative) Collected syntax The nonterminal symbols pointer-type, program, signed-number, simple-type, special-symbol, and structured-type Pascal ISO 7185:1990 This online copy of the unextended Pascal standard is provided only as an aid to standardization. In the case of dierences between this online version and the printed version, the

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 1, 2015 1 M Environment console M.1 Purpose This environment supports programming

More information

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

N.B. These pastpapers may rely on the knowledge gained from the previous chapters.

N.B. These pastpapers may rely on the knowledge gained from the previous chapters. N.B. These pastpapers may rely on the knowledge gained from the previous chapters. 1 SEC 94-PAPER 1 Q7 a. Briefly explain the importance of user documentation (user manual) and program documentation: User

More information

MagicCalc 4.49 Product Manual

MagicCalc 4.49 Product Manual 1 MagicCalc 4.49 Product Manual Publication Date: 08 February 2014 Copyright HOUCINE ROMDHANE Please check www.magiccalc.net periodically for product manual updates. 1 INTERFACE DESCRIPTION:... 3 2 AVAILABLE

More information

CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona

CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona 1/40 CSc 372 Comparative Programming Languages 4 : Haskell Basics Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2013 Christian Collberg 2/40 The Hugs Interpreter The

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade; Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The

More information

Chapter 2.5 Writing maintainable programs

Chapter 2.5 Writing maintainable programs Chapter 2.5 Writing maintainable programs Good program writing techniques Maintenance is the updating of a program after it has been released. Maintenance will be helped when the programmer uses good programming

More information

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank 1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

CSc 372 Comparative Programming Languages. 4 : Haskell Basics

CSc 372 Comparative Programming Languages. 4 : Haskell Basics CSc 372 Comparative Programming Languages 4 : Haskell Basics Christian Collberg Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2011 Christian Collberg August 23, 2011

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

C++ Overview. Chapter 1. Chapter 2

C++ Overview. Chapter 1. Chapter 2 C++ Overview Chapter 1 Note: All commands you type (including the Myro commands listed elsewhere) are essentially C++ commands. Later, in this section we will list those commands that are a part of the

More information

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4 Ziad Matni Dept. of Computer Science, UCSB Administrative CHANGED T.A. OFFICE/OPEN LAB HOURS! Thursday, 10 AM 12 PM

More information

Chapter 4 - Notes Control Structures I (Selection)

Chapter 4 - Notes Control Structures I (Selection) Chapter 4 - Notes Control Structures I (Selection) I. Control Structures A. Three Ways to Process a Program 1. In Sequence: Starts at the beginning and follows the statements in order 2. Selectively (by

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] Content in [] is optional. Example:- PROGRAM FIRST_PROGRAM IMPLICIT NONE PRINT*,

More information

ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

More information