Language Fundamentals:
Program structure, assignment, with and use, primitive types,
literals, operators, if and loop statements, text and numeric output
Language Fundamentals (Continued):
Program structure, assignment, with and use, primitive types,
literals, operators, if and loop statements, text and numeric output
Reading (continued from last week): these sections discuss the
material we are covering this week.
Chapter 1: all
Chapter 1: sections 1-4
Chapter 5: all
Chapter 6: all sections except 3 and 6 (which we will cover later)
Chapter 7: sections 1-3
Key Topics for this week and next:
Strings:
Strings are fixed length and their length cannot be changed
Strings are not references
Strings are arrays of characters, and they can have slices
Procedures can change their parameters - java cannot do this
I/O of strings and characters
Use get to input a character
Use get to input a fixed length string of exact length (skips
newlines)
Use get_line to input a string of unknown length but shorter than
some maximum length (if the string was not completely filled,
then the next get_line starts on the next line)
More on input
Use end_of_line to determine if input is at the end fo a line
Use skip_line to move to the next line of input, ignoring
anything remaining on a line
In interactive programs, EOF returns true when control D or
control Z is entered
get causes an end error if it reads control D or control Z in an
interactive programs or if it attempts to do a read at end of file
in a program that reads from a file
Use redirection to cause standard input (output) to read from (write
to) a file
Exceptions
Any begin/end block can have an exception clause
When an exception occurs, control transfers to the exception
clause and then (normally) to the end of the enclosing begin/end block
Begin/end block can be added anywhere in a program
New exceptions can be declared just like variables
Exceptions can be raised as needed
Ada has 3 built-in exceptions: constraint_error, data_error,
program_error.
Other exceptions are defined in packages (eg end_error) and/or
by the user (eg too_large)
Command line arguments and i/o with named files: Routines to access command line arguments are in Ada.Command_Line.
Here is a
simple example (cline.adb) which uses command line
arguments and named files and here is a
more complex example (text.adb) which does the same.
Group project: Unique words program: Use the Word ADT to write a
program that prints the most frequent word in the input, along with its frequency.
Assume the definition of
a Word given in the Word ADT package.
Abstract Data Objects:
When using a package to define an Abstract Data Object
the package implementation contains declarations of variables
that the client accesses and manipulates using the operations in the
specification. The client accesses the object by instantiating and
useing the package.
Thus the client can only access more than one such object
(eg more than one stack) by instantiating the package several times.
Inputs a list of employees that are salaried or wage and calculates their pay and
prints two lists: employees sorted by id, and ascending salaries only
p3.adb contains the main program
all_emp.ads/b contains the employee package
a generic list package is also included
Tagged record types can be extended with new fields
Parameters of type Type'Class allows parameters of subclass type
Polymorphism is only possible when using pointers
ITEC 320
CPSC 272: Week 17
Comprehensive Final Exam: 11:00 a.m. on Tuesday, December 14, 2004