Computer Science II TURBO PASCAL

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

Computer Science II TURBO PASCAL

CMSC 2833 Lecture Memory Organization and Addressing

DSCI 325: Handout 6 More on Manipulating Data in SAS Spring 2017

Section 9: Exponential and Logarithmic Functions

3. Can every Do-Loop loop be written as a For-Next loop? Why or why not? 4. Name two types of files that can be opened and used in a VB program.

Discrete Structures. Fall Homework3

CIS-331 Spring 2016 Exam 1 Name: Total of 109 Points Version 1

Reviewing all Topics this term

Homework Set 5 (Sections )

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

Polynomial Functions I

(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))

Getting Started With Pascal Programming

Computer Science III WEEK4 Dr.Elgin KILIÇ

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

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

Comparing and Modeling with Functions

STAT 7000: Experimental Statistics I

Comp 333: Concepts of Programming Languages Fall 2016

The vertex set is a finite nonempty set. The edge set may be empty, but otherwise its elements are two-element subsets of the vertex set.

GOZO COLLEGE. Boys Secondary Victoria - Gozo, Malta Ninu Cremona. Half Yearly Examination

4. Specifications and Additional Information

CIS-331 Final Exam Spring 2015 Total of 115 Points. Version 1

Math 96--Radicals #1-- Simplify; Combine--page 1

ACSL All-Star Practice, Woburn CI, (T AR) + S R = ART S + ST + AR

CIS-331 Final Exam Spring 2018 Total of 120 Points. Version 1

Advanced Algebra I Simplifying Expressions

Syllabus of Diploma Engineering. Computer Engineering. Semester: II. Subject Name: Computer Programming. Subject Code: 09CE1104

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

Section 7: Exponential Functions

Getting Started With Pascal Programming

Algebra I Notes Linear Equations and Inequalities in Two Variables Unit 04c

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

Assignment 3: Distance COP3330 Fall 2017

CSCE 531, Spring 2015 Final Exam Answer Key

MODULE 2: Branching and Looping

Hrs Hrs Hrs Hrs Hrs Marks Marks Marks Marks Marks

Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

Beginning Excel for Windows

Medium Term Plan Year 6: Autumn Term

Section 3.2 Measures of Central Tendency MDM4U Jensen

CIS-331 Fall 2013 Exam 1 Name: Total of 120 Points Version 1

METHODS EXERCISES GuessNumber and Sample run SumAll Sample Run

CPSC 121: Models of Computation Assignment #5

Programming, numerics and optimization

arrays Simple Types (Atomic) In this section of notes you will be introduced to a homogeneous composite type, onedimensional 1) Integer 2) Real

Excel Formulas and Functions

Repetition Algorithms

Section 2.2: Introducing Permutations and Factorial Notation

BRANCHING if-else statements

Pseudocode is an abbreviated version of the actual statement t t (or code ) in the program.

Operations and Properties

Lesson 10. Homework Problem Set Sample Solutions. then Print True else Print False End if. False False True False False False

APPM 2460: Week Three For, While and If s

Downloading other workbooks All our workbooks can be downloaded from:

CIS-331 Exam 2 Fall 2015 Total of 105 Points Version 1

Wisconsin Retirement Testing Preparation

Question7.How many proper subsets in all are there if a set contains (a) 7 elements (b) 4 elements

Chapter 1. Math review. 1.1 Some sets

PROBLEM SOLVING WITH LOOPS. Chapter 7

1.2 Round-off Errors and Computer Arithmetic

Homework 3 COSE212, Fall 2018

Chapter 7: Linear Functions and Inequalities

MML Contest #1 ROUND 1: VOLUME & SURFACES

Section 6: Quadratic Equations and Functions Part 2

The Excel worksheet contains 16,384 rows that extend down the worksheet, numbered 1 through

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

Homework 4 Even numbered problem solutions cs161 Summer 2009

Create your first workbook

MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards

Lesson 11.1 Dilations

CS 1803 Pair Homework 3 Calculator Pair Fun Due: Wednesday, September 15th, before 6 PM Out of 100 points

I SEMESTER EXAM : : XI :COMPUTER SCIENCE : MAX MARK a) What is the difference between Hardware and Software? Give one example for each.

Making Decisions In Pascal

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

CSC488S/CSC2107S - Compilers and Interpreters. CSC 488S/CSC 2107S Lecture Notes

ITEC2620 Introduction to Data Structures

Plan (next 4 weeks) 1. Fast forward. 2. Rewind. 3. Slow motion. Rapid introduction to what s in OCaml. Go over the pieces individually

Computer Programming: C++

Expressions & interactions Conditionals Solving a problem. binary representation (8 bits)

Linear Equations in Two Variables

Chapter 5 test Review Integrated 1

3.2-Measures of Center

CMPE Experiment 3 Selective Structures

CSc 372. Comparative Programming Languages. 15 : Haskell List Comprehension. Department of Computer Science University of Arizona

Unit 0: Extending Algebra 1 Concepts

H1 Series Data Logger / Thermometer

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

Know the Well-ordering principle: Any set of positive integers which has at least one element contains a smallest element.

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

Index Page 1 of 10. Index test size A6. Background. Page 2. Page 3

Study Guide for Exam 2

Excel Tips for Compensation Practitioners Month 1

Index Page 1 of 13. Index test size A6. Background. Page 2. Page 3

At the end of this lecture you should be able to have a basic overview of fundamental structures in C and be ready to go into details.

Excel. module. Lesson 1 Create a Worksheet Lesson 2 Create and Revise. Lesson 3 Edit and Format

UNIVERSITY OF SWAZILAND SUPPLEMENTARY EXAMINATION, JULY 2013

Problem Solving and Algorithms

Transcription:

Computer Science II TURBO PASCAL WEEK4 Program Flow Commands Dr.ELGİN KILIÇ

IF THEN ELSE expression: If <case> then Begin <Processes when CASE is TRUE> End else Begin < Processes when CASE is FALSE> End;

Example: For given 100 integers by keyboard control whether number is negative positive or zero. Label A1; Var a,t: integer; begin T:=0; A1: write( Enter a number please. ); readln(a); t:=t+1; if (a>0) then writeln( The given number is positive. ); else if (a<>0) then writeln( The given number is negative. ); If (t<100) then goto A1; readln; {Let us to see the output on screen} end.

Example: For any person weight and height values are given. And ideal weight is calculated as follows; For Women and For men ideal weight=height-108 ideal weight=height-110, Write a pascal program to show the output below; ideal weight> weight You should gain weight. ideal weight< weight You should loose weight. ideal weight = weight You are on ideal weight.

Label bas; Var SAY,w,h,ideal:byte; gender,answer:char; Begin SAY:=0; bas: SAY:=SAY+1; Writeln( Enter gender ); readln(gender); writeln( Weight= ); readln(w); writeln( Height= ); readln(h); if (gender= F ) or (gender= f ) then ideal:=h-110 else ideal:=h-108 if ideal>w then writeln ( You should gain, ideal-w) else if ideal<w then writeln ( loose, w-ideal ) else writeln( You are at ideal weight. ); {SAY:=SAY+1;} If (SAY<50) THEN GOTO BAS; Readln;

Example: In a laboratory there are 50 researchers. Each researcher does an experiment 5 times per day for 30 days. Write a Pascal Program to find; a) Daily Average of each researcher b) Monthly average of each researcher c) Maximum of daily averages of researchers and the day in which this maximum value is obtained.

Label 5,10,20; Var kisi,gun,ds,gun1: byte; ort,top1,enb: real; d,top: integer; Begin kisi:=0; 5: kisi:=kisi+1; gun:=0; top1:=0; 10: gun:=gun+1; ds:=0; top:=0; 20: ds:=ds+1; writeln( result of,ds, expr of,kisi, researcher in,gun, day = ); readln(d); top:=top+d;

if ds<5 then goto 20; ort:=top/5; writeln( Average=, ort); if gun=1 then begin enb:=ort; gun1:=gun; end else if enb<ort then begin enb:=ort; gun1:=gun; end; top1:=top1+ort; if gun<30 then goto 10; writeln( Answer of b =,enb,gun1); writeln( Answer of a =, top1/30); if kisi<50 then goto 5; end.

EXAMPLE: b n 1 x 2n 1 (2n 1)! Write a Pascal program to find the result of formula above for given only one x, b pair.

Label 5,10,20; Var x,b,n,i,k: integer; car,carp1: longint; t,top: real; Begin writeln( Enter x b values ); readln(x,b); n:=0; top:=0.0; 5: n:=n+1;

i:=0; carp:=1; 20: i:=i+1; carp:=carp*x; if (i<2*n-1) then goto 20; {power process} k:=0; carp1:=1; 10: k:=k+1; carp1:=carp1*k; if (k<2*n-1) then goto10; {factorial process} end. t:=carp/carp1; top:=top+t; if n<b then goto 5; writeln( sonuç=, top);

Homework: For given 100 a, b, c a b, M=a+b+3c a > b, M=5a+2b+4c Write a Pascal program to find triples M is calculated as follows; a) How many M values are divisible by 4 when a>b? b) What is the minimum M value when a<b and a, b, c triple giving this minimum value? c) First calculated M value when a=b. Z

CASE ----OF This structure is used to change the flow of program depending on many cases of one variable (input data). Type of input can be numeric or character based. Program process the part when the constant value is equal to given input. If no case is satisfied then ELSE part runs. It is not compulsory to use else part.

Case EXPRESSION OF const value1: Process / Begin Processes End; const value2: Process / Begin Processes End;... const value n: Process / Begin Processes End; [ELSE Process/ Processes] End;

Example: In a shop there 5 types of products are sold. This sale process stops when product type is given as a negative input. Write a Pascal Program to find HOW MANY OF EACH TYPE OF PRODUCT is sold when sales process stopped.

Label A1; Var t1,t2,t3,t4,t5,type:integer; Begin t1:=0;t2:=0;t3:=0;t4:=0;t5:=0; A1: Writeln( Enter product type as 1/2/3/4/5. ); Readln(type); If (type=1) then t1:=t1+1; If (type=2) then t2:=t2+1; If (type=3) then t3:=t3+1; If (type=4) then t4:=t4+1; If (type=5) then t5:=t5+1; end; If (type>0) then goto a1; Writeln( Total amounts= ); Writeln(t1,t2,t3,t4,t5); readln; end.

Label A1; Var t1,t2,t3,t4,t5,type:integer; Begin t1:=0;t2:=0;t3:=0;t4:=0;t5:=0; A1: Writeln( Enter product type as 1/2/3/4/5. ); Readln(type); Case type of 1: t1:=t1+1; 2: t2:=t2+1; 3: t3:=t3+1; 4: t4:=t4+1; 5: t5:=t5+1; end; If (type>0) then goto a1; Writeln( Total amounts= ); Writeln( type1=,t1,t2,t3,t4,t5); readln; end.

Example: In a shop there 5 types of products are sold. This sale process stops when product type is given as Z. Write a Pascal Program to find HOW MANY OF EACH TYPE OF PRODUCT is sold when sales process stopped.

Label A1; Var t1,t2,t3,t4,t5:integer; type:char; Begin t1:=0;t2:=0;t3:=0;t4:=0;t5:=0; A1: Writeln( Enter product type as A/B/C/D/E. ); Readln(type); If (type= A ) then t1:=t1+1; If (type= B ) then t2:=t2+1; If (type= C ) then t3:=t3+1; If (type= D ) then t4:=t4+1; If (type= E ) then t5:=t5+1; If (type<> Z ) then goto a1; Writeln( Total amounts= ); Writeln(t1,t2,t3,t4,t5); readln; end.

Label A1; Var t1,t2,t3,t4,t5 :integer; type:char; Begin t1:=0;t2:=0;t3:=0;t4:=0;t5:=0; A1: Writeln( Enter product type as A/B/C/D/E. ); Readln(type); Case type of A : t1:=t1+1; B : t2:=t2+1; C : t3:=t3+1; D : t4:=t4+1; E : t5:=t5+1; end; If (type<> Z ) then goto a1; Writeln( Total amounts= ); Writeln( pro1=,t1, pro2=,t2, prod3=,t3, p4=,t4, P5=,t5); readln; end.

Example: Write a Pascal Program to find LETTER notation of a student s grade according to intervals below. 86-100 AA 79-85 BA 71-78 BB 60-70 CC 46-59 DD 0-45 FD

Var g:integer; Begin Writeln( Enter student s grade. ); Readln(g); Case g of 0..45 :writeln( FD ); 46..59 : writeln( DD ); 60..70 : writeln( CC ); 71..78 : writeln( BB ); 79..85 : writeln( BA ); 86..100 : writeln( AA ); end; Readln; END.

Label A1; Var i,g:integer; Begin i:=0; A1: Writeln( Enter student s grade. ); Readln(g); i:=i+1; {ANA SAYAÇ} Case g of 0..45 :writeln( FD ); 46..59 : writeln( DD ); 60..70 : writeln( CC ); 71..78 : writeln( BB ); 79..85 : writeln( BA ); 86..100 : writeln( AA ); end; If (i<100) then goto a1; Readln; END. If there have been 100 students in the class, then solution will be like shown in left side.

Example: Write a Pascal Program to find LETTER notation of a student s grade according to intervals below in a class of 100 students and how many students are there in each INTERVAL. 86-100 AA 79-85 BA 71-78 BB 60-70 CC 46-59 DD 0-45 FD

Label A1; Var i,x,y,z,t,w,v,g:integer; Begin i:=0;x:=0;y:=0;z:=0;t:=0;w:=0;v:=0; A1: Writeln( Enter student s grade. ); Readln(g); i:=i+1; Case g of 0..45 :begin writeln( FD ); x:=x+1;end; 46..59 : begin writeln( DD ); y:=y+1;end; 60..70 : begin writeln( CC ); z:=z+1;end; 71..78 : begin writeln( BB ); t:=t+1;end; 79..85 : begin writeln( BA ); w:=w+1;end; 86..100 : begin writeln( AA ); v:=v+1;end; end; If (i<100) then goto a1;

Writeln( There are,x, students in FD ); Writeln( There are,y, students in DD ); Writeln( There are,z, students in CC ); Writeln( There are,w, students in BB ); Writeln( There are,t, students in BA ); Writeln( There are,v, students in AA ); readln; end.

Example: The amount of products that an employee produced in one is given day by day. Employee earns 25TL per each item of product at the first half of the month and 15TL per item at the last 15 days of the month. Write a Pascal Program to find the total amount of products and earning of this employee at the end of the month.

Label bas; Var ps,gun,topu,topps,ucret:integer; Begin Gun:=0;topu:=0; topps:=0; bas: Writeln( Enter number (amount) of products ); Readln(ps); Gun:=gun+1; Case gun of 1..15 :ucret:=ps*25; 16..30:ucret:=ps*15; end; topu:=topu+ucret; topps:=topps+ps; if gun<30 then goto bas; writeln (topu, topps); end.