4bitsbytesifthen

4bitsbytesifthen - Introduction to Computers and...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computers and Programming Lecture 4 Prof. I. K. Lundqvist Reading: B pp. 20-46 ; FK pp. 157-165, 245-255 Sept 10 2003 Recap (1/3) Context Clause Indicates that package with Ada.Text_Io; Ada.Text_Io is used by the program Program Heading Identifies Unified as the procedure Unified is name of the program Constant declaration Associates the constant, Tax : constant Float := 17.00; Star : constant Character := ‘*’; Tax, with the Float value 17.00 Variable declaration Declares a variable X : Float; object named X for Y : Integer := 42; storage of Integer values
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Recap (2/3) Assignment statement Computes the product of Distance := Speed * Time; Speed and Time and assigns it to Distance Input Statements Enters data into the Ada.Text_Io.Get character variable Initial (Item =>Initial); Input Statements … into the integer Ada. Integer _Text_Io.Get variable Age (Item => Age); Input Statements … into the float variable Ada. Float _Text_Io.Get PayRate (Item => PayRate); Recap (3/3) Output Statements Displays the value of Ada.Text_Io.Put (Item =>Initial); the character variable Initial Output Statements Ada. Integer _Text_Io.Put (Item =>HowMany, Width=>3); … integer variable HowMany, using five columns on the display Output Statements Ada. Float _Text_Io.Put (Item => GrossPay, Fore => 4, Aft => 2, Exp => 0); … float variable GrossPay using four columns before the decimal point and two columns after the decimal point
Background image of page 2
Data types String type characters as a single unit of data Max_Str_Length : constant := 26; Alphabet, Response:String(1. .Max_Str_Length); String Operations Alphabet := “abcdefghijklmnopqrstuvwxyz” Response := Alphabet; Alphabet(1. .26) Alphabet & “.”); • Assignment Put(Item => “The alphabet is “ & • Used when representing a sequence of – How many characters? – String (1 . . Maxlen); –Examp le:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sub-strings alphabet(10) 'j' alphabet(17) 'q' alphabet(20. .23) "tuvw" alphabet(4. .9) "defghi" response(1. .4) := "FRED"; response "FREDefghijklmnopqrstuvwxyz" String I/O Get(Item => A_String); Get_Line(Item => A_String, Last => N); • Exact length needed – Get_Line • Variable length accepted • Returns string and length • Individual character: specify position • Slice: specify range of positions • Assign to compatible slice •Tex t_Io – Output: Put, Put_Line
Background image of page 4
Control Structures Selection statements statements if-then , when a single action might be done if-then-else , to decide between two possible actions if-then-elsif , to decide between multiple actions
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 18

4bitsbytesifthen - Introduction to Computers and...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online