Tuesday 1/29 Week 3
Chapter 3
Student Notes
Objectives
Collect Project 1
Distribute Project 2
Discuss grading of projects
Basic program structure
Working with numbers
Variables
Return reading quizzes
1. Basic
Program Structure
·
Ex. Hello_Initials
·
This is the first program that we have used
·
Also note the interaction with the user using
·
·
Variables are
·
·
·
Ex. Hello_Name uses a String type (a
collection of Characters)
2. Reserved Words & Predefined Identifiers
·
Reserved words have a specific meaning in
·
·
·
WITH
PROCEDURE IS BEGIN END
·
Predefined Identifiers have special meanings, but these words may be
reused by the programmer for other things
·
·
·
Ada.Text_IO
Put New_Line Character Get String
·
In the book all
RESERVED WORDS
are in caps, this is a good habit, everything else is in Upper and Lower Case
3.
The context
clause
·
The WITH
packageName at
the top of your program
·
4. The basic structure of an
WITH package1;
WITH package2;
…
WITH packageN;
PROCEDURE pname IS
--------------------
-- header
comments, should contain file name, brief
-- description of
the program
-- Author name and date
--------------------
declarations
(variable, constants, etc.)
BEGIN –-procedure/function name
program statement;
…
program statement;
END pname;
·
Notice indent structure –
·
The comments are also not required by the compiler, but must be used in
this class.
5. Using Numbers
·
Ex. Inch_to_CM
·
In most cases,
·
·
Ada.Integer_Text_IO,
Ada.Float_Text_IO, and Ada.Text_IO
·
Ada.Float_Text_IO.Get(Item
=> Inches);
·
·
Centimeters
:= CMPerInch * Inches;
·
·
Ada.Float_Text_IO.Put(Item
=> Centimeters);
·
·
Notice that the value in printed in Scientific notation
·
·
·
Ex. Distance
·
Natural
is a type for
·
·
Ada.Text_IO
is used to
·
·
Ada.Text_IO.New_Line
6. Constants and Variables
·
CMPerInch:
CONSTANT Float := 3.54;
·
This is a constant declaration.
·
·
·
·
HowLong
: Natural;
·
This is a variable declaration.
7. Naming variables and constants
·
IdentifierName
: Type;
·
An identifier must begin with
a letter
·
·
An identifier must consist only
of letters, digits, and up to one underscore ( _ ).
·
Cannot use more than one underscore in an identifier.
·
·
Note that file names are not identifiers and therefore may use more than
one underscore.
·