Turbo Pascal Units (TPU)

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Spring Semester 2013 Lecture 5
P5, M1, D1.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
Chapter 9 Modules and Programming with Functions.
Chapter 13: Object-Oriented Programming
Pascal Programming Pascal Units, Abstract Data, Ordinals, Arrays.
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
1 Web Based Programming Section 6 James King 12 August 2003.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
Fall 2001(c)opyright Brent M. Dingle 2001 Arrays Brent M. Dingle Texas A&M University Chapter 9 – Sections 1 and 2 (and some from Mastering Turbo Pascal.
CSCI-383 Object-Oriented Programming & Design Lecture 13.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Adding a New Option to the Framework. Introduction This is intended as a step by step guide to adding a new action to the menu or toolbar. The order of.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part D (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
1 Chapter Four Creating and Using Classes. 2 Objectives Learn about class concepts How to create a class from which objects can be instantiated Learn.
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)
Top Down Design Brent M. Dingle Texas A&M University Chapter 4 – Section 1 (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
N. HARIKA Lecturer(csc). 3 General Structure Of A Java Program.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
Fall 2001(c)opyright Brent M. Dingle 2001 Simple Sorting Brent M. Dingle Texas A&M University Chapter 10 – Section 1 (and some from Mastering Turbo Pascal.
Functions Functions, locals, parameters, and separate compilation.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Scion Macros How to make macros for Scion The Fast and Easy Guide.
A Simple Program CPSC Pascal Brent M. Dingle Texas A&M University 2001, 2002.
Loops Brent M. Dingle Texas A&M University Chapter 7 – part C (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Loops Brent M. Dingle Texas A&M University Chapter 6 – Section 6.3 Multiway Branches (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
Fall 2001(c)opyright Brent M. Dingle 2001 Multidimensional Arrays Brent M. Dingle Texas A&M University Chapter 10 – Section 2, part B (and some from Mastering.
Fall 2001(c)opyright Brent M. Dingle 2001 Abstract Data Types (ADTs) Brent M. Dingle Texas A&M University Chapter 8 – Sections 2 and 3 (and some from Mastering.
Instructor & Todd Lammle
JavaScript/ App Lab Programming:
Chapter 6: User-Defined Functions I
Brent M. Dingle Texas A&M University Chapter 6, Sections 1 and 2
Complex data types Complex data types: a data type made of a complex of smaller pieces. Pascal has four very commonly used complex data types: strings,
Functions, locals, parameters, and separate compilation
Microsoft Visual Basic 2005: Reloaded Second Edition
Retrieving information from forms
Week 1 Gates Introduction to Information Technology cosc 010 Week 1 Gates
Lecturer: Mukhtar Mohamed Ali “Hakaale”
(c)opyright Brent M. Dingle 2001
Separate Compilation and Namespaces
Learning to Program in Python
Chapter 3 The DATA DIVISION.
Brent M. Dingle Texas A&M University Chapter 12 – section 1
Interfaces.
[insert Module title here]
Computer Science 1 Get out your notebook
Chapter 4 –Requirements for coding in Assembly Language
[insert Module title here]
Procedures Brent M. Dingle Texas A&M University
Teaching slides Chapter 6.
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
Defining Classes and Methods
Review of Previous Lesson
(c)opyright Brent M. Dingle 2001
Brent M. Dingle Texas A&M University Chapter 5 – Section 2-3
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Complex Array Structures
Code Organization Classes
Brent M. Dingle Texas A&M University Chapter 5 – Section 1
Presentation transcript:

Turbo Pascal Units (TPU) Brent M. Dingle Texas A&M University Chapter 8 – Section 1 (and some from Mastering Turbo Pascal 5.5, 3rd Edition by Tom Swan)

What is a Unit? A unit is a collection of procedures, functions and defined constants (and other stuff) that can be compiled apart from any program. The procedures, functions and constants that are defined in a unit can then be used by any program you write in the future, without having to be declared in the program. The file extension for Turbo Pascal Units is .TPU.

What makes a Unit? Units are written in a similar fashion to programs. They are divided into four parts (note the book i.d.s only 2 of them to begin with but all four are mentioned eventually) Unit Declaration/Heading Unit Interface Section Unit Implementation Section Unit Initialization

Unit Declaration This is like the declaration or heading line of the program, it gives the unit a name. For other programs to access the unit they will need to have a line of code which says: USES [unit name] where [unit name] is the name of the unit they wish to access. It is best to name units the same as their filename (without the .tpu extension). See comment on File names, page 278.

Unit Interface This is the public section of the unit. It describes all the features inside a unit that it can share with programs or other units. It contains labels, constants, types, variables along with function and procedure declarations. Think of this as describing how someone might ‘interface’ with the unit to use it.

Unit Implementation This is the private section of the unit. This part contains the actual statements which implement the procedures and functions declared in the interface section. Constants, types and variables may also be placed in this section but they will only be able to be used by this unit. Call these items private constants, private types, private variables. You may also declare private functions and private procedures, by placing them here and omitting them from the interface section.

Initialization This is an optional block of statements very similar to the main body of a Pascal program. The statements found here will run before any statements in the program that uses the unit. This allows the unit to initialize its own variables and perform other tasks before the host program even begins. Many units leave this section empty/blank.

Structure of a Unit File UNIT [name]; INTERFACE { USES declarations go here } { CONST, TYPE and VAR declarations go here } { Procedure and Function declarations go here } IMPLEMENTATION { private CONST, TYPE and VAR declarations go here } { Place Procedure and Function bodies here } BEGIN { optional } { Initialization statements go here } END.

Bizarre Fact Since the Initialization section is optional the BEGIN in the unit is also optional. However the END. is required. This is the only time you will have an END without a BEGIN.

Common Predefined Unit You probably have already been using the clrscr function. This function is part of the CRT unit. The CRT unit contains several different functions and procedures for accessing the monitor (once called the CRT device = Cathode Ray Tube device).

Compiling Units Your TA’s should show you how to compile a unit in lab. The unit BooleIn described on page 282 and 283 along with the corresponding program TestBooleIn might be a good place to start. If they are nice they will have already typed them up and placed them somewhere for download for you – so all you need do is compile and test them. Hopefully this won’t take more than 20 minutes.

Suggested Problems (not graded) page 290: 1, 4, 5, 6, 7 think about 2 and 3

End Units