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

Similar documents
Unit 2: Accentuate the Negative Name:

Computer Science II TURBO PASCAL

A/L 2011_revision. PASCAL PROGRAMMING

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Computer Programming CS F111

Class 2: Variables and Memory. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

Fundamentals of Programming CS-110. Lecture 3

UNIT 3 OPERATORS. [Marks- 12]

Computer Science II TURBO PASCAL

x= suppose we want to calculate these large values 1) x= ) x= ) x=3 100 * ) x= ) 7) x=100!

Getting Started With Pascal Programming

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

The assignments. DAB721 Computer Architecture. Today. PPM and PGM. PPM and PGM. The deal. Parallel programming. Image manipulation

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

A First Program - Greeting.cpp

Operators in java Operator operands.

Flow Chart. The diagrammatic representation shows a solution to a given problem.

ISA 563 : Fundamentals of Systems Programming

Informatics Ingeniería en Electrónica y Automática Industrial

Operators in C. Staff Incharge: S.Sasirekha

CIS 110: Introduction to Computer Programming

Operators and Expressions:

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Chapter Two MIPS Arithmetic

Prepared by: Shraddha Modi

DEPARTMENT OF MATHS, MJ COLLEGE

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Beginning Programming (Pascal) Lecture 75. Figure 1. type-declarations. simple-type. pointer-type. array-type. file-type. set-type.

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Chapter 2: Using Data

Computer (Literacy) Skills. Variables, records, and pointers. Lubomír Bulej KDSS MFF UK

Quick Reference Guide

JAVA OPERATORS GENERAL

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

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

Information Science 1

Programming in C++ 5. Integral data types

Operators & Expressions

Relational and Logical Operators

Department of Computer Science

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

Introduction to C# Applications

Information Science 1

Making Decisions In Pascal

C Programming Multiple. Choice

C: How to Program. Week /Mar/05

This tutorial will teach you about operators. Operators are symbols that are used to represent an actions used in programming.

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Object Oriented Programming Using C++ Mathematics & Computing IET, Katunayake

Unit-2 (Operators) ANAND KR.SRIVASTAVA

1.8 Intro to Variables, Algebraic Expressions, and Equations

Computational Physics Operating systems

Chapter 2: Data and Expressions

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Data Types and Variables in C language

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

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

Getting Started With Pascal Programming

Arithmetic for Computers

ARITHMETIC EXPRESSION

CS Programming I: Primitives and Expressions

ADD Identifier-1 TO Identifier-2 Literal-1. ADD Identifier-1. GIVING Identifier-2 Literal-1

Today s Topics. Team Project Introduce this year s team project. S/SL S/SL, the Syntax/Semantic Language. CISC 458 Winter J.R.

Sir Syed University of Engineering and Technology. Computer Programming & Problem Solving ( CPPS )

1 Elementary number theory

Math & CompSci Contest - model Written Test in Computer Science

Quick Reference Guide

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Data Handing in Python

Arithmetic and Bitwise Operations on Binary Data

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Learning the Language - V

Lesson 1: Arithmetic Review

CT 229. Java Syntax 26/09/2006 CT229

C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Operators. Lecture 3 COP 3014 Spring January 16, 2018

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

Computer Programming : C++

Modular Arithmetic. Marizza Bailey. December 14, 2015

LECTURE 3 C++ Basics Part 2

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

Computers Programming Course 6. Iulian Năstac

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

MagicCalc 4.49 Product Manual

Operators. Java operators are classified into three categories:

Introduction to Programming

Introduction to Programming

Making Decisions In Pascal

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

Department of Computer Applications

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Macro Programming Reference Guide. Copyright 2005 Scott Martinez

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

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

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

Week 4 Lecture 1. Expressions and Functions

Prof. Navrati Saxena TA: Rochak Sachan

Transcription:

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. To access these USES block is used to run these on editor of pascal. Generally it is given in first line after name of program. UNITS can not run (process) by themselves. They must be called by a program.

Example for Uses BLOCK CLRSCR = Clear Screen = This is used to clear the screen it is a reserved command of PASCAL itself. Uses crt;.. Begin {main program block} Clrscr;.. end. 3

Label BloCK In any program each expression is separated by ; from other expressions. PROGRAM FLOW is from TOP to BOTTOM. If there is a need to change the flow of the program, then the place where we want the program to flow must be declared. To do this we need LABEL to address or declare this flow place. GOTO command is used to change flow. LABEL names are defined like variables. Variable definition rules are also valid for label defining. Label etiket1,etiket 2;

Type BloCK This block is used to define USER DEFINED TYPES. Any programmer can define new types by using default types of PASCAL. Type name of the type that user defined=type style; Example: type St20=string[20]; var a:st20;

OPERATORS 1)Aritmetic operators 2) Relational Operators 3) Logical Operators

Assignment operator Assign a value to a variable <name of variable>:=<value of variable>; A:=6; expression1:=expression2 OPERATOR expression3; A:=A+1; A:=A*B; If there are same variables in both sides of a equality ; then values of these variables are NOT EQUAL.

we can use logic operators in relational expressions: 0<=x<=34 X is an element in interval [0,34] (x>=0) AND (x<=34)

OPERATORS in DETAIL 1)Aritmetic operators + addition - subtraction * multiplicaiton / division 2) Relational Operators < less than > Greater than <= Less than or equal >= greater than or equal <> Not equal = equal 3) Logical Operators NOT değil OR veya AND ve Ex: (A<B) AND (C<=8) (A>(C-4)) OR (C<(NOT(B)))

mod operator (operand1) mod ( operand2) Gives an integer result of remainder after dividing OPERAND1 by OPERAND2. 3mod5=3 11mod4=3 22mod6=4 (- 13)mod5=2

div operator (operand1) div ( operand2) Gives an integer result of after dividing OPERAND1 by OPERAND2. It is used for exact division. 4div13=0 18div5=3 16div(-3)=-5

Priority order in Arithmetic Operations Parenthesis operator ( ) Arithmetic functions(e,ln ) Power DIVISION multiplication div OPERATOR of PASCAL mod OPERATOR of PASCAL ADDITION SUBTRACTION RELATIONAL expressions(<,>, ) LOGICAL expressions

INPUT OUTPUT EXPRESSIONS INPUT (READ) EXPRESSION: General usage: Read(variable1,variable2,,variablen); (READLN) EXPRESSION: (readln=readline) After getting input computer sends the cursor to the beginning of next line General usage: Readln(variable1,variable2,,variablen);

Difference between read and readln Program source code Var a, b:integer; c: real; Screen Result 12,35,-264 CURSOR WAITS HERE begin read (a,b,c); End. Var a, b:integer; c: real; 12,35,-264 CURSOR WAITS HERE in NEW LINE begin readln(a,b,c); end.

Char Type INPUT expressions char type variables allow users to enter ONE CHARACTER. If there are more than one character type variable SPACE shouldn t be given between these characters. Var a, b: char; begin read(a); read(b); End. ZX we press ENTER after Z X???? Computer takes Z as input not X. When we enter word ELGIN for b it can only process E.

STRING TYPE INPUT expressions Var a, b:string[20]; begin read(a,b); End. a and b CAN CONTAIN 20 CHARACTERS AT MOST. SO THEY TAKE MUCH SPACE FROM MEMORY. Var a, b:string[20]; begin A:= Ege University ; B:= mathematics Department ; Writeln(a); Writeln(b); End. We can assign initial (başlangıç) values to string type variables.

OUTPUT EXPRESSION 1 These are expressions that show output values on SCREEN of computer *write deyimi: General usage; Write(varibale1,variable2,,variablen); CURSOR waits on screen after showing the values in this command. It waits at right side of output expression. Var a, b: byte; top: integer; begin read(a,b); top:=a+b; write(top); end.

OUTPUT EXPRESSION 2 Instead of values of variables if anyone wants to give some information must be used. Write( Information about some data in program ); CURSOR waits on screen after showing the values in this command. It waits at right side of output expression. Program source code Var a, b: byte; Output after run process This is our first program. begin write( This is our first program. ); end.

1 Example OUTPUT EXPRESSION Program source code Output after run process Var a, b: byte; begin A:=5; B:=7; write( This is our first program. ); Write( A=,A); Write( B=,B); end. This is our first program.a=5 B=7 Cursor waits

2Example OUTPUT EXPRESSION Program source code Var a, b: byte; begin A:=5; B:=7; writeln( This is our first program. ); Writeln( A=,A); Writeln( B=,B); Writeln( A and B are=,a,b ); Writeln(a,b); end. Output after run process This is our first program. A=5 B=7 Cursor waits here. A and B are=,a,b 57

3Example OUTPUT EXPRESSION Program source code Var a,b: byte; sum: integer; begin write( Enter 1. number ); readln(a); write( Enter 2. number ); readln(b); sum:=(a+b); writeln( result=,sum); end. Output after run process Enter 1. number 25 Enter 2. number 73 result=98 Cursor waits here.

Example: Write a Pascal Program which gives the following output. First Number=5 Second Number=8 - - - - - - - - - MULT=firstnumber*secondnumber=5*8=40 Program run process stopped

Example: Write a Pascal Program which gives the following output. Var a,b,top: integer; Begin a:=5;b:=8; Write( First number=,a); Write( Second number=,b); Writeln( Mult=firstnumber*secondnumber=,a*b); Write( Program runprocess stopped. ); End.

Program p1; Uses crt; BEGIN write( Ege University ); Write( Faculty of Science ); Write( Department of Maths ); Write( Computer Sciences II course ); Readln; END.

Program p1; Uses crt; BEGIN writeln( Ege University ); Writeln( Faculty of Science ); Writeln( Department of Maths ); Writeln( Computer Sciences II course ); Readln; END.

Program p2; Uses crt; Var a,b:integer; BEGIN clrscr; a:=5; b:=7; Writeln( a+b is, a+b); Writeln(a, +,b, =, a+b); Writeln( a*b is, a*b); Writeln(a, *,b, =, a*b); Readln; END.

Program p3; Uses crt; Var a,b,sum,mult:integer; BEGIN clrscr; Writeln( Enter first number= ); readln(a); Writeln( Enter second number= ); readln(b); sum:=a+b; Writeln( Sum of, a, and,b, is, sum); mult:=a*b; Writeln( Multiplication of, a, and,b, is, mult); Readln; END.

Program p4; Uses crt; Var a,b:char; BEGIN clrscr; Writeln( Enter first name= ); readln(a); Writeln( Enter surname= ); readln(b); Writeln( The first charcter is =, a); Writeln( The second charcter is =, b); Readln; END.

Program p5; Uses crt; Var a,b:string[5]; BEGIN clrscr; Write( Enter first name= ); readln(a); Write( Enter surname= ); readln(b); Writeln( first name is =, a); Writeln( surname is =, b); Readln; END.

Program p5; Uses crt; Var a:string[10]; b:string[20]; BEGIN clrscr; Write( Enter first name= ); readln(a); Write( Enter surname= ); readln(b); Writeln( first name is =, a); Writeln( surname is =, b); Readln; END.