Review With packagename ; Use packagename ; Procedure procedurename Is declaration of variables & constants Begin statements of program End procedurename.

Slides:



Advertisements
Similar presentations
Slide: 1 Copyright © AdaCore Arrays Presented Quentin Ochem university.adacore.com.
Advertisements

Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
22-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
String Escape Sequences
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Input & Output: Console
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Information and Programs. Foundations of Computing Information –Binary numbers –Integers and Floating Point –Booleans (True, False) –Characters –Variables.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Chapter 4 Variables and Constants. Goals and Objectives 1. Understand simple data types (int, boolean, double). 2. Declare and initialize variables using.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Primitive Variables.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Chapter 2 Variables.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Tokens in C Keywords Identifiers Constants
Documentation Need to have documentation in all programs
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Data Types, Identifiers, and Expressions
C++ Data Types Data Type
Data Types and Expressions
The Data Element.
The Data Element.
Variables and Constants
Programming Fundamental-1
Presentation transcript:

Review With packagename ; Use packagename ; Procedure procedurename Is declaration of variables & constants Begin statements of program End procedurename ;

Chapter 3 The Basics of Ada

Topics Standard Types Identifiers Literals Expressions Variables & Constants Errors in Programs

Data Types characterized by… Values that can be stored as the data type Operations that can be performed on them Attributes (properties) associated with each type ’Last ’First ’Digits ’Pos ’Val

Types of Data (Incomplete but a beginning)

Numeric Data Integer & Float

Data type: Integer No fractional part to the number Usually stored in two bytes (16 bits) Processed faster than float Stored as exact value in memory Limited to –32,768 to +32,767 (if stored as two bytes)

Storing Integer Data Using Binary Number System – 16 bits

Binary Number System vs. Decimal Number System Base 2 Uses symbols 0-1 Place value based on powers of 2 Base 10 Uses symbols 0-9 Place value based on powers of 10

Decimal Number System (Base 10) x x x x 10 0 = 4 x x x x 1 = = 4302 Place Value

Binary Number System (Base 2) x x x x 2 0 = 1 x x x x 1 = = Place Value

You try one… Change this binary (base 2) integer to a decimal (base 10) number: Sign of number

Answer: (will be positive) = 1 x x x x x 2 0 = 1 x x 1 = =

Package for Integers With ada.integer_text_io; Use ada.integer_text_io; Declaring a variable Count : integer;

Attributes of Integer Data Type Integer’first – gives smallest possible negative integer Integer’last – gives largest possible positive integer Way to find out how your computer stores integers (two bytes, four bytes, etc.) PUT(“the biggest integer is: ”); PUT(integer’last);

Data type: Float Always stores fractional part to the number Usually stored in four bytes (32 bits) Processed slower than integer Stored as approximate value in memory Stores the sign (1 st bit), exponent(8 bits), and then mantissa (23 bits)…from left to right

Data Type: Float Storing the number – 32 bits Signexponentmantissa = x 2 4 = = 1x2 3 +0x2 2 +1x2 1 +0x2 0 +1x2 -1 = ½ = 9.5

Package for Float With ada.float_text_io; Use ada.float_text_io; Declaring a variable Salary : float;

Attributes of Float Data Type Float’digits– gives number of significant digits Float’first – gives smallest possible positive number that can be stored Float’last – gives largest positive number that can be stored PUT(“the biggest float number is: ”); PUT(float’last);

Text Data Character & String

Data Type: Character Can store only one letter, digit, special symbol, or non- printable control character Value of character put in apostrophes – ’d’ Example: to assign the exclamation point to a variable called ch ch := ’!’ Stored in one byte (this is a ‘B’) Set of characters has order (enumerated) – see appendix F Can compare one character to another (, =)

Package for Character With text_io; Use text_io; Declaring a variable Ch : character;

Attributes of Character Data Type ’Pos – gives the ASCII code (position) of the character in the set Example: ’A’ has position 65 ’Val – gives the character that goes with a particular code Example: Put(Character’val(65)); would display the ‘A’

Data Type: String Used to store more than one character (a string of characters) Must declare how many characters are possible for the variable

Package for String same as character With text_io; Use text_io; Declaring a variable Name : string(1..8);

Indexing a String (only using part of it) Name(1..2) would only access the first two characters in the string variable Name

Reading text of varying length Make sure declaration of variable allows for as large a string as needed (Name : String(1..100) Declare an integer variable to hold the number of characters read in (N) Use the GET_LINE(Name,N) Then use indexing to get correct string you want PUT(“the name is ”); PUT(Name(1..N));

Logical Data Boolean (True or False)

Data Type: Boolean Can be a statement which can be shown true or false Example: num_of_people > 10 Can be a variable that is of type boolean Example: If Found then PUT(“I found it!”); End if;

Identifiers Way of naming things in the program Name of procedure Name of variable Reserved words (Begin, If, For…etc.) Must begin with letter of alphabet Remaining part of identifier must be letters, digits (0 – 9), or underline symbol Examples: num_of_2nd_place_winners Case does not matter

Valid or Invalid Identifiers ?? 7_up Number1 Number_1 My Name First-Name _MyName

Literals actual (constant)values used in a program …must match variable type 25 integer literal 3E4 integer literal (same as 30000) 23.0 float literal 4.1E-3 float literal (same as ) ’R’ character literal ”Joshua” string literal false boolean literal

Expressions…Examples Gross_pay – * Gross_Pay -k 13 mod 5 13 rem 5 abs k float(num_of_people) K>5 (boolean expression)

Expressions Precedence (order) of operators ** abs not * / mod rem + - (unary – sign of number) & + - (ordinary adding and subtraction) = /= >= in not in And or xor and then or else -5+4*6/2**3

Declaring Variables Num_of_items : integer; Address : string(1..30); Symbol : character; Temp, max_temp, min_temp : float; Found : boolean

Initializing variables Found : boolean := false; School : string(1..3) := “MSU”; Rate : float := 0.05; I_rate : float := Rate * 2

Declaring Constants cannot be changed in program Max_num : constant Integer := 100; Max_num : constant := 100; Int_rate : constant := 0.065; Title : constant string := “Welcome to Murray!”

Kinds of Errors Compile-time error –broke the rules of syntax (grammar) – detected during compilation Run-time error – illegal values occurred – detected during execution Logic-error – may have mixed up the sequence of statements – a true “bug”