1 Ordinal types An ordinal data type is an ordered set in which every element, except the first element, has an immediate predecessor, and every element,

Slides:



Advertisements
Similar presentations
1 Data Type Anan Phonphoem Data Type Ordinal TypeNon-ordinal Type StandardUser Define Enumerated Subrange Integer Char Boolean Real.
Advertisements

Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
1 Chapter 2 Basic Elements of Fortran Programming.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 2 Data Types, Declarations, and Displays
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
JavaScript, Third Edition
1 BIL106E Introduction to Scientific & Engineering Computing Organizational matters Fortran 90 ( subset F ): Basics Example programs in detail.
Basic Elements of C++ Chapter 2.
FOR DOWNTO Suppose you want to write a FOR-DO loop where the control variable is decreased with each repetition of the loop. Pascal provides the reserved.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Introduction to Programming (in C++) Data types and visibility Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC.
The Data Element. 2 Data type: A description of the set of values and the basic set of operations that can be applied to values of the type. Strong typing:
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
ME 142 Engineering Computation I Excel Functions.
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.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved.1 Chapter 4 Mathematical Functions, Characters, and Strings.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
Computer Science 101 Introduction to Programming.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Week 2 - Friday.  What did we talk about last time?  Using Scanner to get input  Basic math operations.
1 Week 2 n Organizational matters n Fortran 90 (subset F): Basics n Example programs in detail.
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Lecture 9 There are ain’t no way to find out why a snorer can’t hear himself snore Mark Twain, Western koan.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Visual Basic I Programming
CSCI 125 & 161 / ENGR 144 Lecture 8 Martin van Bommel.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part B (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Java Programming, Second Edition Chapter Two Using Data Within a Program.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
Midterm1 answers: Page 1 1 a6 b6 c0 2 ***. Midterm1 answers: Page 2 A)a. 53b. 44c. 13d. 75e. 77 B)a. 53b. 17c. 33 / 44d. 13e. 75 C)a. ‘5’b. ‘3’c. ‘ ‘d.
USING & CREATING FUNCTIONS. MODULAR PROGRAMMING  Why Modular Programming?  Improves Readability & Understandability  Improve Maintainability  Allows.
1 nd Semester Module2 C# Basic Concept Thanawin Rakthanmanon Computer Engineering Department Kasetsart University, Bangkok.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
CS 201 California State University, Los Angeles.  Various Mathematical Functions  Characters  Strings.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
Random Functions Selection Structure Comparison Operators Logical Operator
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.
Chapter 16 Introduction to Perl Perl (Practical Extraction and Report Language) Developed by Larry Wall as a Unix scripting language. Popular server-side.
Week 3 - Monday.  What did we talk about last time?  Using Scanner to get input  Basic math operations  Lab 2.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Chapter Topics The Basics of a C++ Program Data Types
CprE 185: Intro to Problem Solving (using C)
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Haskell Chapter 2.
CPSC Pascal Brent M. Dingle Texas A&M University Chapter 3
BIL 104E Introduction to Scientific and Engineering Computing
Basic Elements of C++.
Data Types, Identifiers, and Expressions
Fundamental of Java Programming Basics of Java Programming
Basic Elements of C++ Chapter 2.
Data Types, Identifiers, and Expressions
Chapter 2: Java Fundamentals
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
The Data Element.
An Introduction to Programming with C++ Fifth Edition
The Data Element.
Presentation transcript:

1 Ordinal types An ordinal data type is an ordered set in which every element, except the first element, has an immediate predecessor, and every element, except the last element, has an immediate successor. –all types of integers –characters –boolean –enumerated types (Enumerated types are user defined. We will not cover them in this course)

2 Ordinal types (con’t) Reals and strings are not ordinal types because they do not have a unique predecessor or successor. A FOR-DO loop’s control variable must be an ordinal type. –This is why reals cannot be control variables

3 ASCII Table ASCII (American Standard Code for Information Exchange) table contains 128 entries relating whole numbers to characters Turbo Pascal extends this table with graphical characters. The total number of characters in the table for Turbo Pascal is 256 (0 to 255 or to ). A character’s position in this table is called it’s ordinal position.

4 Distinction between integer and its character representation The number 6 and the character ‘6’ are not the same –The explicit representation of the character 6 in a program is ‘6’ and its ordinal position in the ASCII table is 54. –The explicit representation of the integer 6 in a program is 6 and its ordinal position in the integer sequence is also 6.

5 Ordinal Functions ord(ordinal_type) This function returns the ordinal position of the value in the parenthesis. –ord (‘A’) returns 65 –ord (123) returns 123 –ord (TRUE) returns 1 –ord (FALSE) returns 0

6 Ordinal functions (con’t) chr(byte) –give this function an integer between 0 and 255 and it returns the character whose ordinal value is that integer. –chr(64) returns –chr(52) returns ‘4’{note: this is a character} –chr(87) returns ‘W’ –chr(129) returns ‘ü’

7 Ordinal functions (con’t) succ() is the successor function. It returns the next value of the ordinal type. –succ(‘A’) returns ‘B’ –succ(3) returns 4 –succ(‘3’) returns ‘4’ –succ(FALSE) returns TRUE –succ(TRUE) does not have a value

8 Ordinal functions (con’t) pred() is the predecessor function. It returns the previous value of the ordinal type. –pred(‘B’) returns ‘A’ –pred(3) returns 2 –pred(‘3’) returns ‘2’ –pred(FALSE) does not have a value –pred(TRUE) returns FALSE

9 Converting numbers read as characters to integers Sometimes you may want to read numerical digits as characters and convert them to numerical values in your program. Number := ord(char) - ord(‘0’);

10 Turbo Pascal Topic: Debugging

11 Standard Functions: arithmetic Sqr(x): squares x sqrt(x): positive square root of x abs(x): absolute value of x exp(x): raises e to x power ln(x): log of x to base e cos(x): Cosine of x sin(x): Sine of x arctan(x): Arctangent of x

12 More standard functions Transfer functions (real to integer) –Round(x) rounds x to the closest integer –trunc (x) drops the part of x to the right of the decimal. Boolean functions –odd (x) returns TRUE if x is odd or FALSE if x is not –we will learn others later

13 Turbo Pascal non-standard functions Pi: the value of pi (note: no arguments) upcase(L): returns uppercase for a lowercase letter L. For any other character it returns the same character. Frac(x): returns part to the right of the decimal int(x): returns part to the left of the decimal random(N): returns random integer between 0 and N-1 random: returns random real between 0 & 1

14 Midterm topics Variables –types integers reals boolean character strings –rules for naming –garbage values

15 Midterm topics (con’t) Arithmetic operators –integers –reals –precedence formatting output - all types reading data –buffer –all types

16 Midterm topics (con’t) Units compiler loops –FOR TO –FOR DOWNTO –nested –ordinal types - all topics

17 Midterm topics (con’t) Programming –any topic covered in class homework chapters 1-5 functions