Download as pdf or txt
Download as pdf or txt
You are on page 1of 54

C++ Programming: An Object-Oriented

Approach, 1e ISE 1st Edition Behrouz


A. Forouzan - eBook PDF
Go to download the full and correct content document:
https://ebooksecure.com/download/c-programming-an-object-oriented-approach-1e-is
e-ebook-pdf/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

(eBook PDF) Microsoft Visual C#: An Introduction to


Object-Oriented Programming 7th Edition

http://ebooksecure.com/product/ebook-pdf-microsoft-visual-c-an-
introduction-to-object-oriented-programming-7th-edition/

Foundations of Computer Science 4th Edition Behrouz


Forouzan - eBook PDF

https://ebooksecure.com/download/foundations-of-computer-science-
ebook-pdf/

Design patterns: elements of reusable object-oriented


software 1st edition - eBook PDF

https://ebooksecure.com/download/design-patterns-elements-of-
reusable-object-oriented-software-ebook-pdf/

Data Communications and Networking with TCP/IP Protocol


Suite 6th Edition Behrouz A. Forouzan - eBook PDF

https://ebooksecure.com/download/data-communications-and-
networking-with-tcp-ip-protocol-suite-ebook-pdf/
Programming in C 1st Edition - eBook PDF

https://ebooksecure.com/download/programming-in-c-ebook-pdf/

Readings from Programming with C++ 1st Edition Kyla


Mcmullen - eBook PDF

https://ebooksecure.com/download/readings-from-programming-with-
c-ebook-pdf-2/

Readings from Programming with C++ 1st Edition Kyla


Mcmullen - eBook PDF

https://ebooksecure.com/download/readings-from-programming-with-
c-ebook-pdf/

Object Relations Theory and Practice: An Introduction


(eBook PDF)

http://ebooksecure.com/product/object-relations-theory-and-
practice-an-introduction-ebook-pdf/

Principles of Microeconomics: A Streamlined Approach,


4e ISE 4th/ISE Edition Robert H. Frank - eBook PDF

https://ebooksecure.com/download/principles-of-microeconomics-a-
streamlined-approach-4e-ise-ebook-pdf/
C++ Programming:
An Object-Oriented Approach

Behrouz A. Forouzan
Richard F. Gilberg
C++ PROGRAMMING: AN OBJECT-ORIENTED APPROACH

Published by McGraw-Hill Education, 2 Penn Plaza, New York, NY 10121. Copyright © 2020 by McGraw-Hill Education. All rights
reserved. Printed in the United States of America. No part of this publication may be reproduced or distributed in any form or by any
means, or stored in a database or retrieval system, without the prior written consent of McGraw-Hill Education, including, but not
limited to, in any network or other electronic storage or transmission, or broadcast for distance learning.

Some ancillaries, including electronic and print components, may not be available to customers outside the United States.

This book is printed on acid-free paper.

1 2 3 4 5 6 7 8 9 LWI 21 20 19

ISBN 978-0-07-352338-5 (bound edition)


MHID 0-07-352338-0 (bound edition)
ISBN 978-1-259-57145-9 (loose-leaf edition)
MHID 1-259-57145-9 (loose-leaf edition)

Executive Portfolio Manager: Suzy Bainbridge


Product Developer: Heather Ervolino
Marketing Manager: Shannon O’Donnell
Content Project Managers: Jane Mohr and Sandra Schnee
Buyer: Laura Fuller
Designer: Egzon Shaqiri
Content Licensing Specialist: Shawntel Schmitt
Cover Image: ©McGraw-Hill Education
Compositor: MPS Limited

All credits appearing on page or at the end of the book are considered to be an extension of the copyright page.

Library of Congress Cataloging-in-Publication Data

Forouzan, Behrouz A., author. | Gilberg, Richard F., author.


C++ programming : an object-oriented approach / Behrouz A. Forouzan, Richard F. Gilberg.
First edition. | New York, NY : McGraw-Hill Education, [2020] |
Includes index.
 LCCN 2018030975| ISBN 9780073523385 (bound edition : acid-free paper) |
ISBN 0073523380 (bound edition : acid-free paper) | ISBN 9781259571459 (loose-leaf edition) |
ISBN 1259571459 (loose-leaf edition)
LCSH: Object-oriented programming (Computer science) | C++ (Computer program language)
LCC QA76.64 .F684 2019 | DDC 005.1/17—dc23
LC record available at https://lccn.loc.gov/2018030975

The Internet addresses listed in the text were accurate at the time of publication. The inclusion of a website does not indicate an endorse-
ment by the authors or McGraw-Hill Education, and McGraw-Hill Education does not guarantee the accuracy of the information presented
at these sites.

mheducation.com/highered
To my wife, Faezeh
Behrouz A. Forouzan

To my wife, Evelyn
Richard F. Gilberg
This page intentionally left blank
Brief Table of Contents

Preface xv
Chapter 1 Introduction to Computers and Programming Languages 1
Chapter 2 Basics of C++ Programming 19
Chapter 3 Expressions and Statements 59
Chapter 4 Selection112
Chapter 5 Repetition158
Chapter 6 Functions208
Chapter 7 User-Defined Types: Classes 273
Chapter 8 Arrays338
Chapter 9 References, Pointers, and Memory Management  380
Chapter 10 Strings443
Chapter 11 Relationships among Classes 496
Chapter 12 Polymorphism and Other Issues  553
Chapter 13 Operator Overloading 597
Chapter 14 Exception Handling 657
Chapter 15 Generic Programming: Templates 693
Chapter 16 Input/Output Streams 716
Chapter 17 Recursion776
Chapter 18 Introduction to Data Structures 813
Chapter 19 Standard Template Library (STL) 852
Chapter 20 Design Patterns Available online

v
Appendixes A-R  Available online

Appendix A Unicode
Appendix B Positional Numbering System

Appendix C C++ Expressions and Operators

Appendix D Bitwise Operations

Appendix E Bit Fields

Appendix F Preprocessing

Appendix G Namespaces

Appendix H Ratios

Appendix I Time

Appendix J Lambda Expressions

Appendix K Regular Expressions

Appendix L Smart Pointers

Appendix M Random Number Generation

Appendix N References

Appendix O Move versus Copy

Appendix P A Brief Review of C++ 11

Appendix Q Unified Modeling Language (UML)

Appendix R Bitset

CheckPoints  Available online

True/False Questions  Available online

Review Questions  Available online

Glossary  Available online

Index 915
Contents

Preface xv
What Is the C++ Language? xv
Why This Book? xv
Appendicesxvi
Instructor Resources xvii
Acknowledgmentsxvii

1
Introduction to Computers and Programming Languages 1

1.1 Computer System 1


1.2 Computer Languages 5
1.3 Language Paradigms 7
1.4 Program Design 10
1.5 Program Development 13
1.6 Testing15
Key Terms 16
Summary17
Problems17

2
Basics of C++ Programming 19

2.1 C++ Programs 19


2.2 Variable, Value, and Constant 26
2.3 Components of a C++ Program 32
2.4 Data Types 36
Key Terms 52
Summary52
Problems52
Programming Projects 57

vii
viii Contents

3
Expressions and Statements 59

3.1 Expressions59
3.2 Type Conversion  71
3.3 Order of Evaluation 76
3.4 Overflow and Underflow 81
3.5 Formatting Data 85
3.6 Statements93
3.7 Program Design  98
Key Terms 105
Summary105
Problems106
Programs110

4
Selection 112

4.1 Simple Selection 112


4.2 Complex Decisions 126
4.3 Decisions on Specific Values 134
4.4 Conditional Expressions 142
4.5 Program Design  144
Key Terms 152
Summary153
Problems153
Programs156

5
Repetition 158

5.1 Introduction158
5.2 The while Statement 161
5.3 The for Statement 175
5.4 The do-while Statement  180
5.5 More About Loops 184
5.6 Other Related Statements  188
5.7 Program Design  191
Key Terms 203
Summary203
Problems204
Programs206
Contents ix

6
Functions 208

6.1 Introduction208
6.2 Library Functions  213
6.3 User-Defined Functions 224
6.4 Data Exchange 233
6.5 More About Parameters 244
6.6 Scope and Lifetime  248
6.7 Program Design  256
Key Terms 265
Summary265
Problems266
Programs269

7
User-Defined Types: Classes 273

7.1 Introduction273
7.2 Classes275
7.3 Constructors and Destructors 283
7.4 Instance Members 294
7.5 Static Members 302
7.6 Object-Oriented Programming 311
7.7 Designing Classes 320
Key Terms 332
Summary332
Problems333
Programs335

8
Arrays 338

8.1 One-Dimensional Arrays 338


8.2 More on Arrays 349
8.3 Multidimensional Arrays 363
8.4 Program Design  369
Key Terms 376
Summary376
Problems376
Programs378
x Contents

9
References, Pointers, and Memory Management  380

9.1 References380
9.2 Pointers391
9.3 Arrays and Pointers 405
9.4 Memory Management 414
9.5 Program Design 425
Key Terms 437
Summary437
Problems437
Programs442

10
Strings 443

10.1 C Strings 443


10.2 The C++ String Class 460
10.3 Program Design 484
Key Terms 492
Summary492
Problems493
Programs494

11
Relationships among Classes 496

11.1 Inheritance496
11.2 Association519
11.3 Dependency528
11.4 Program Design 532
Key Terms 546
Summary546
Problems547
Programs550

12
Polymorphism and Other Issues  553

12.1 Polymorphism553
12.2 Other Issues 567
Contents xi

Key Terms 594


Summary594
Problems594
Programs596

13
Operator Overloading 597

13.1 Three Roles of an Object 597


13.2 Overloading Principles 602
13.3 Overloading as a Member 605
13.4 Overloading as a Nonmember  621
13.5 Type Conversion 625
13.6 Designing Classes 626
Key Terms 652
Summary653
Problems653
Programs654

14
Exception Handling 657

14.1 Introduction657
14.2 Exceptions in Classes 675
14.3 Standard Exception Classes 682
Key Terms 688
Summary688
Problems689
Programs692

15
Generic Programming: Templates 693

15.1 Function Template 693


15.2 Class Template 703
Key Terms 713
Summary713
Problems714
Programs715
xii Contents

16
Input/Output Streams 716

16.1 Introduction716
16.2 Console Streams 720
16.3 File Streams 729
16.4 String Streams 751
16.5 Formatting Data 755
16.6 Program Design 766
Key Terms 773
Summary773
Problems774
Programs774

17
Recursion 776

17.1 Introduction776
17.2 Recursive Sort and Search 792
17.3 Program Design 803
Key Terms 808
Summary808
Problems809
Programs811

18
Introduction to Data Structures 813

18.1 Introduction813
18.2 Singly Linked List 815
18.3 Stacks and Queues 825
18.4 Binary Search Trees 841
Key Terms 849
Summary850
Problems850
Programs851
Contents xiii

19
Standard Template Library (STL) 852

19.1 Introduction  852


19.2 Iterators853
19.3 Sequence Containers 856
19.4 Container Adapters 877
19.5 Associative Containers 884
19.6 Using Functions  894
19.7 Algorithms899
Key Terms 910
Summary910
Problems911
Programs911

20
Design Patterns Online

20.1 Introduction
20.2 Creational Patterns
20.3 Structural Patterns
20.4 Behavioral Patterns
Key Terms
Summary
Problems
Programs

Online Appendices
Appendix A Unicode
Appendix B Positional Numbering System
Appendix C C++ Expressions and Operators
Appendix D Bitwise Operations
Appendix E Bit Fields
Appendix F Preprocessing
xiv Contents

Appendix G Namespaces
Appendix H Ratios
Appendix I Time
Appendix J Lambda Expressions
Appendix K Regular Expressions
Appendix L Smart Pointers
Appendix M Random Number Generation
Appendix N References
Appendix O Move versus Copy
Appendix P A Brief Review of C++ 11
Appendix Q Unified Modeling Language (UML)
Appendix R Bitset

CheckPoints Available online

True/False Questions Available online

Review Questions Available online

Glossary Available online

Index 915
Preface

This book complements a course designed to teach object-oriented programming using the syntax
of the C++ language. It will also prepare students for advanced concepts such as data structure
and design patterns. Students who have completed this course will be ready to take on any other
object-oriented language course, a data-structure course, or a course about design patterns.

What Is the C++ Language?


C++ is a progressive programming language derived from its predecessors, the C language
and the B language. The C++ language expands the idea of a struct to a class in which dif-
ferent objects can be created from one single definition of a class with different values for
each data element.
Furthermore, the C++ language explores the idea of object-oriented languages that
simulate real life. In real life, we define a type and then we have objects of that type. In the
C++ language, we define a class and then we create objects from that class. C++ also in-
cludes the idea of inheritance. In inheritance, we can create a class and then extend the defi-
nition to create other classes, just as in real life where the idea of an animal can be extended
to create the idea of a horse, a cow, a dog, and so on.
Perhaps the most interesting addition to C++ is the idea of polymorphism. Polymor-
phism gives us the ability to write several versions of an action with the same name to be
used by different objects. This practice is found in real life when we use the verb open. We
can say that we open a business, open a can, open a door, and so on. Although the word open
is used in all cases, it elicits different actions on different objects.
The most recent additions to C++ include the Standard Template Library (STL), a
collection of predefined complex objects and actions that can be applied to those objects, as
well as design patterns to make problem solving more efficient and coherent.

Why This Book?


The book has five distinctive goals as discussed below.

Teach Computer Programming


The book can be used as the first course in computer programming using the C++ language
as the vehicle. Chapters 1 to 6 are designed for this purpose. They discuss computer systems
and languages. They also discuss the basics of the C++ syntax and program controls, such
as decisions and repetitions. Chapters 1 to 6 are essential to learning programming using the
C++ language.

Teach the Syntax of the C++ Language


Chapters 7 to 12 are essential in the study of object-oriented programming. Although Chap-
ters 8 and 9 are not directly related to the object-oriented features of C++, we believe that
these two chapters can be taught after students understand the basics of object-oriented pro-
gramming, which are discussed in Chapter 7.
xv
xvi Preface

Present New Features of C++


Chapters 13 to 17 discuss other topics normally taught in a first or second course in program-
ming. They can be taught in any order.

Discuss Data Structure and Introduce the STL Library


Chapters 18 and 19 are an introduction to data structures. They prepare students for a course
in data structures.

Introduce Design Patterns


Chapter 20 (which can be found online) gives simple and alternative solutions to some
typical problems in object-oriented programming that would be more difficult to solve if
patterns were not used. Chapter 20 gives students an insight to object-oriented programming
through a set of standard solutions to specific problems. Although design patterns are nor-
mally taught in computer graphics courses, we have applied them to nongraphic problems
for students who have no graphical programming experience.

Course Outline
The twenty chapters of the book are outlined in the following figure.

Chapter 1

Chapter 6

Chapter 7 Chapter 8
Chapter 10 Chapter 9
Chapter 11
Chapter 12

Chapter 13
Legend:
Chapter 17 Basic C++ language
Object-oriented concepts
Chapter 18 Can be taught in anywhere after chapter 7
Chapter 19 Can be taught if time allows (second course)
Data structures (optional)
Chapter 20 Design patterns (optional)

Appendices
Appendices can be found online and are divided into six categories.

References
Appendices A to E are designed to be used as references for students. Students may need to
consult these appendices when studying chapters in the book.

Language Knowledge
Appendices F and G give students information about how C++ prepares a source code for
compilation and how it handles names in different sections.
Preface xvii

Advanced Topics
Appendixes H to O discuss some advanced topics that were added to C++. They can be
taught in the class, or students can use them as a source of additional information.

Brief Review of C++ 11


Appendix P gives a brief review of C++ 11 topics that were not discussed in the appendices
that discussed advanced topics.

Brief Review of UML


We have used UML diagrams in the text. Appendix Q provides general insight into UML as
a tool for designing object-oriented projects.

Bitset
The concept of bitset becomes more popular when C++ is used in network programming.
We have included this topic in Appendix R.

Instructor Resources
Accompanying this text are several additional resources which can be found online at www
.mhhe.com/forouzan1e. These include CheckPoint questions that help instructors gauge stu-
dent understanding after reading each section of a chapter. True/false and review questions
are also available to further test student’s knowledge. Complete solutions to the CheckPoint
features, true/false questions, review questions, and problems are provided as well. Lastly,
Lecture PPTs, text image files, and sample programs are provided as well.

Acknowledgments
We would like to express our gratitude to the reviewers of this text. Their insight and sug-
gestions over the last few years greatly influenced this first edition. In alphabetical order, the
reviewers are as follows:

Vicki H. Allan, Utah State University


Kanad Biswas, Institute of Technology, Delhi
Gary Dickerson, Union College
Max I. Formitchev, Maximus Energy
Cynthia C. Fry, Baylor University
Barbara Guillott, Q&A Analyst, CGI, Lafayette, LA
Jon Hanrath, Illinois Institute of Technology
David Keathly, University of North Texas
Robert Kramer, Youngstown State University
Kami Makki, Lamar University
Christopher J. Mallery, Principal Software Engineering Lead for Microsoft
Michael L. Mick, Purdue University, Calumet
Amar Raheja, California State Polytechnic University, Pomona
Brendan Sheehan, University of Nevada–Reno

At McGraw-Hill, we would like to thank the following editorial and production staff:
Thomas Scaife, Senior Portfolio Manager; Suzy Bainbridge, Executive Portfolio Manager;
Heather Ervolino, Product Developer; Shannon O’Donnell, Marketing Manager; Patrick
Diller, Business Project Manager; and Jane Mohr, Content Project Manager.
This page intentionally left blank
1 Introduction to Computers
and Programming Languages
In this chapter, we describe the components of a computer system and discuss the general
ideas behind computer languages. The overview provided in this chapter will help prepare
you for future chapters. You can skip the chapter in the first reading and return to it when
you have a better understanding of programming.

Objectives
After you have read and studied this chapter, you should be able to:

• Discuss the two major components of a computer: hardware and software.


• Describe the six parts of hardware: CPU, primary memory, secondary storage, input system,
output system, and communication system.
• Describe the two major categories of software: system software and application software.
• Describe the evolution of computer languages from machine languages, to assembly
languages, and to high-level languages.
• Discuss four different paradigms of computer languages: procedural, object-oriented,
functional, and logic.
• Describe the two steps of program design: understand the problem and develop a solution.
• Describe the multistep procedure that transforms a program written in the C++ language to
an executable program.

1.1 COMPUTER SYSTEM


A computer system is made of two major components: hardware and software. The com-
puter hardware is the physical equipment. The software is the collection of programs
(instructions) that allow the hardware to do its job.

1.1.1 Computer Hardware


The hardware of a computer system consists of six parts: a central processing unit (CPU),
main memory, secondary storage, the input system, the output system, and the communica-
tion system. These components are connected together by what is called a bus. Figure 1.1
shows these six components and their connection.

Central Processing Unit (CPU)


The central processing unit (CPU) consists of the arithmetic-logical unit (ALU), the con-
trol unit, and a set of registers to hold data temporarily while being processed. The control
unit is the traffic cop of the system; it coordinates all the operations of the system. The ALU

1
2 Chapter 1  Introduction to Computers and Programming Languages

CPU

Bus

Main Secondary Input Output Communication


memory storage system system system

Figure 1.1 Basic hardware components

ALU Registers
Control unit

Central processing unit (CPU)

Figure 1.2 Central processing unit


(photo) ©leungchopan/Getty Images

executes instructions such as arithmetic calculations and comparisons among data. Figure 1.2
shows the general idea behind a central processing unit.

Primary Memory
Primary memory is where programs and data are stored temporarily during processing.
The contents of primary memory are lost when we turn off the computer. Figure 1.3 shows
primary memory in more detail. Each storage location in memory has an address, much like
a street address, that is used to reference the memory’s contents. The addresses in Figure
1.3(a) are shown on the left as numbers ranging from zero to (n – 1), where n is the size of
memory. In Figure 1.3(b) the address is shown symbolically as x.

0
1 Address Contents
Operating
system
x 256

(b) Address and contents


Program

256
15.34
Hello Data

n−1
(a) General layout
Figure 1.3 Primary memory
(photo) ©Simon Belcher/Alamy
1.1  Computer System 3

Figure 1.4 Some secondary storage devices


©Shutterstock/PaulPaladin; ©David Arky/Getty Images; ©McGraw-Hill Education

Figure 1.5 Some input systems


©JG Photography/Alamy; ©Keith Eng 2007

Generally, each address refers to a fixed amount of memory. In personal computers,


the amount of storage accessed is usually one, two, or four bytes. In large computers, it can
be many bytes. When more than one byte is accessed at a time, word rather than byte is usu-
ally used for the memory size.
In general, primary memory is used for three purposes: to store the operating system,
to store the program, and to store data. The type of data stored is dependent on the applica-
tion. In Figure 1.3, we demonstrate three different types of data: an integer (256), a real
number (15.34), and a string (Hello).

Secondary Storage
Programs and data are stored permanently in secondary storage. When we turn off the
computer, our programs and data remain in the secondary storage ready for the next time
we need them. Examples of secondary storage include hard disks, CDs and DVDs, and flash
drives (Figure 1.4).

Input System
The input system is usually a keyboard where programs and data are entered into the com-
puter. Examples of other input devices include a mouse, a pen or stylus, a touch screen, or
an audio input unit (Figure 1.5).

Output System
The output system is usually a monitor or a printer where the output is displayed or printed.
If the output is displayed on the monitor, we say we have a soft copy. If it is printed on the
printer, we say we have a hard copy (Figure 1.6).

Communication System
We can create a network of computers by connecting several computers. Communication
devices are installed on a computer system for this purpose. Figure 1.7 shows some of these
devices.
4 Chapter 1  Introduction to Computers and Programming Languages

Figure 1.6 Some output systems


©Roy Wylam/Alamy; ©Stephen VanHorn/Alamy

Figure 1.7 Some communication devices


©Ingram Publishing; ©somnuek saelim/123RF

1.1.2 Computer Software


Computer software is divided into two broad categories: system software and application
software. This is true regardless of the hardware system architecture. System software man-
ages the computer resources. Application software, on the other hand, is directly responsible
for helping users solve their problems.

System Software
System software consists of programs that manage the hardware resources of a computer
and perform required information processing. These programs are divided into three groups:
the operating system, system support, and system development.
Operating System The operating system provides services such as a user interface, file and
database access, and interfaces to communication systems. The primary purpose of this soft-
ware is to operate the system in an efficient manner while allowing users access to the
system.

System Support System support provides system utilities and other operating services. Ex-
amples of system utilities are sort programs and disk format programs. Operating services
consist of programs that provide performance statistics for the operational staff and security
monitors to protect the system and data.

System Development System development software includes the language translators that
convert programs into machine language for execution, debugging tools to assure that the
programs are error-free, and computer-assisted software engineering (CASE) systems that
are beyond the scope of this book.
1.2  Computer Languages 5

Application Software
Application software is broken into two categories: general-purpose software and
application-specific software.
General-Purpose Software General-purpose software is purchased from a software devel-
oper and can be used for more than one application. Examples of general-purpose software
include word processors, database management systems, and computer-aided design sys-
tems. These programs are called general purpose because they can solve a variety of user
computing problems.

Application-Specific Software Application-specific software can be used only for its in-
tended purpose. A general ledger system used by accountants and a material requirements
planning system used by engineers are examples of application-specific software. They can
be used only for the task they were designed for; they cannot be used for other generalized
tasks.

1.2 COMPUTER LANGUAGES


To write a program for a computer, we must use a computer language. Over the years,
computer languages have evolved from machine to symbolic to high-level languages and
beyond. A time line for computer languages is seen in Figure 1.8.

1.2.1 Machine Languages


In the earliest days of computers, the only programming languages available were machine
languages. While each computer still has its own machine language, which is made of
streams of 0s and 1s, we no longer program in machine language.

The only language understood by a computer is its machine language.

1.2.2 Symbolic Languages


It became obvious that not many programs would be written if programmers continued to
work in machine language. In the early 1950s, Grace Hopper, a mathematician and a mem-
ber of the United States Navy, developed the concept of a special computer program for
converting programs into machine language (see Figure 1.9).
Her work led to the use of programming languages, which simply mirrored the ma-
chine languages using symbols, or mnemonics, to represent the various machine language
instructions. Because they used symbols, these languages were known as symbolic lan-
guages. A special program called an assembler is used to translate symbolic code into ma-
chine language. Because symbolic languages have to be assembled into machine language,
they soon became known as assembly languages. This name is still used today for symbolic
languages that closely represent the machine language of their computer.

High-level languages
Symbolic languages
Machine languages
Time
1940 1950 1960 1970 1980 1990 2000 2010

Figure 1.8 Computer language evolution


6 Chapter 1  Introduction to Computers and Programming Languages

Figure 1.9 Grace Hopper


©Cynthia Johnson/Getty Images

Symbolic language uses mnemonic symbols to


represent machine language instructions.

1.2.3 High-Level Languages


Although symbolic languages greatly improved programming efficiency, they still required
programmers to concentrate on the hardware they were using. Working with symbolic lan-
guages was also very tedious because each machine instruction had to be individually coded.
The desire to improve programmer efficiency and to change the focus from the computer to
the problem being solved led to the development of high-level languages.
High-level languages are portable to many different computers, which allows the pro-
grammer to concentrate on the application problem at hand rather than the intricacies of the
computer. High-level languages are designed to relieve the programmer from the details of
the assembly language. However, high-level languages share one thing with symbolic lan-
guages: They must be converted to machine language. This process is called compilation.
The first widely used high-level language, FORTRAN (Formula Translation), was
created by John Backus and an IBM team in 1957. Following soon after FORTRAN was
COBOL (Common Business-Oriented Language). Admiral Grace Hopper was again a key
figure, this time in the development of the COBOL business language.
1.3  Language Paradigms 7

Over the years, several other languages—most notably BASIC, Pascal, Ada, C, C++,
and Java—were developed. Today, one of the popular high-level languages for system soft-
ware and new application code is C++, which we discuss in this book.

1.3 LANGUAGE PARADIGMS


Computer languages can be categorized according to the approach they use in solving a prob-
lem. A paradigm is a model or a framework for describing how a program handles data. Al-
though there are several taxonomies for dividing current languages into a set of paradigms, we
discuss only four: procedural, object-oriented, functional, and logic, as shown in Figure 1.10.
The figure also shows which language belongs to which paradigm according to our taxonomy.
Note that the C++ language can be used both as a procedural and an object-oriented
paradigm, as we will see in future chapters.

1.3.1 Procedural Paradigm


In a procedural (also called imperative) paradigm, a program is a set of commands. The
execution of each command changes the state of the memory related to that problem. For
example, assume we want to find the sum of any two values. We reserve three memory
locations and call them a, b, and sum. The combination of these three memory locations
comprises a state in this case. Figure 1.11 shows how a procedural paradigm uses four com-
mands to change the state of memory four times. Note that the memory locations in gray
show the original state, wherein the locations are reserved for the program.
To get the value of the first number, a, into memory, we use an input command (input
a). After execution of this command, the computer waits for us to enter a number on the
keyboard. We entered 6. When we press the enter key on the keyboard, the number 6 is
stored in the first memory location and the state of memory is changed. After the second
command, again the state of the memory is changed and now both 6 and 8 are stored in
memory. The third command changes the memory state by adding the values of a and b
and storing the result in sum. Although the last command (output sum) does not look like it
is changing the memory state, it is considered a change because the value of sum is output.
The way we have written the code in Figure 1.11 is very inefficient for two reasons.
First, it contains some commands that can be repeated in the same program or other pro-
grams. Second, if the set of data to be handled is large, we need to handle them one by one.
To remove these two inefficiencies, the procedural paradigm allows packaging commands
and data items.

Computer language
paradigms

Object-
Procedural Functional Logic
oriented

FORTRAN Smalltalk LISP Prolog


COBOL C++ Scheme
BASIC Visual Basic
Ada C#
Pascal Java
C
C++

Figure 1.10 Language paradigms


8 Chapter 1  Introduction to Computers and Programming Languages

a
b
sum
a 6 6
input a b
sum
input b
a 6
sum = a + b 8
b 8
output sum sum
a 6
Program b 8
sum 14
a 6
b 8 14
14
sum 14
States

Figure 1.11 An example of a procedural paradigm

a. If we are writing code for different programs, we can package the code and create
what is called a procedure (or function). A procedure can be written once and then
copied in different programs. The standard procedures can be stored in the language
library and be used instead of rewritten.
b. If we are handling a large set of data items (for example, hundred or thousands of
numbers), we need to store them in a package (called different names such as array
or record) and input them all together, process them all together, and output them
all at the same time. The operation at the background is still done one data item at a
time, but the program can see the data items as packages.
The following shows how a procedural paradigm uses three lines of code to sort a list of
numbers of any size. Of course, we must have already written the procedures and already
packaged data items into a list.

input (list);
sort (list);
output (list);

1.3.2 Object-Oriented Paradigm


In the procedural paradigm, the often-used procedures can be created and saved. We then
apply a subset of these procedures to the corresponding data packages to solve our particular
problem. One thing that is obvious in this paradigm is that there is no explicit relationship
between the set of procedures and the set of data packages. When we want to solve a prob-
lem, we need to choose our data package and then go and find the appropriate procedure(s)
to be applied to it.
The object-oriented paradigm goes further and defines that the set of procedures that
can be applied to a particular type of data package needs to be packaged with the data. The
whole is referred to as an object. In other words, an object is a package containing all pos-
sible operations that can be applied to a particular type of data structure.
This is the same concept we find in some physical objects in our daily life. For exam-
ple, let us think about a dish-washing machine as an object. The minimum operations we ex-
pect from a dishwasher are washing, rinsing, and drying. All of these operations are included
1.3  Language Paradigms 9

Objects

13 17 8 10 list1
sort ( )
reverse ( )
11 17 38 14 list2
search (...)

print (...)
Shared 12 10 91 20 listn
Procedures

Figure 1.12 An example of an object-oriented paradigm

in any typical dish-washing machine. However, each time we load the machine with a dif-
ferent set of dishes (same as a different set of data). We need to be careful, however, not to
load the machine with a load it is not designed for (not to wash clothes, for example, in the
dish-washing machine).
In the real world, all the hardware necessary for an operation is included in an object;
in the object-oriented programming world, each object holds only data, but the code that
defines the procedures is shared. Figure 1.12 shows the relationship between the procedures
and data in the object-oriented paradigm.

1.3.3 Functional Paradigm


In the functional paradigm, a program is a mathematical function. In this context, a func-
tion is a black box that maps a list of inputs to a list of outputs. For example, adding num-
bers can be considered as a function in which the input is a list of numbers to be added and
the output is a list with only one item, the sum. In other words, the functional paradigm is
concerned with the result of a mathematical function. In this paradigm, we are not using
commands and we are not following the memory state. The idea is that we have some primi-
tive functions, such as add, subtract, multiply, divide. We also have some primitive func-
tions that create a list or extract the first element or the rest of the elements from a list. We
can write a program or a new function by combining these primitive functions. Figure 1.13
shows how we add two numbers using the functional paradigm. The code is symbolic, but
each language in this paradigm has its own definition for a function. Note also that in our
code, we distinguish between a number and a list. We have a number as 8, but a list with one

list (6, 8)

first () rest ()

sum (first (6, 8), first (rest (6, 8))) (8)


6 first ()
Code 8
sum ()
14

Visualization

Figure 1.13 An example of a functional paradigm


10 Chapter 1  Introduction to Computers and Programming Languages

Parent (Fay, Tara)


Parent (Tara, Willie) 1. Parent (Willie, Tara)? No
Parent (Tara, Benji) 2. Parent (Fay, Benji)? No
Facts 3. Parent (Tara, Benji)? Yes
4. Grandparent (Tara,Willi)? No
Grandparent (X, Y) 5. Grandparent (Fay, Benji)? Yes
Parent (X, Z) AND Parent (Z, Y) 6. Grandparent (Fay, Willi)? Yes
Queries
Rule

Figure 1.14 An example of a logic paradigm

element is (8). The function first gets a number, but the function rest gets a list. To get
the second number in the list, we first use the function rest to get the list (8) and then use
the function first to get 8.

1.3.4 Logic Paradigm


The logic paradigm uses a set of facts and a set of rules to answer queries. It is based on
formal logic as defined by Greek mathematicians. We first give the program the facts and
rules before asking queries. Figure 1.14 shows a simplified and symbolic version of a logic
paradigm. A fact such as Parent (Fay, Tara) is read as “Fay is the parent of Tara.”

1.3.5 Paradigms in C++ Language


Our discussion of four paradigms might lead you to wonder where the C++ language stands.
C++ is an extension to the C language and is based on the procedural paradigm. However,
the existence of classes and objects allows the language to be used as an object-oriented lan-
guage. In this book we use C++ mostly as a procedural paradigm in early chapters (except
for input/output that are done using objects). However, we use the language as an object-
oriented paradigm after the introductory chapters.

1.4 PROGRAM DESIGN


Program design is a two-step process that requires understanding the problem and then de-
veloping a solution. When we are given the assignment to develop a program, we are given
a program requirements statement and the design of any program interfaces. In other words,
we are told what the program needs to do. Our job is to determine how to take the inputs we
are given and convert them to the outputs that have been specified. To understand how this
process works, let’s look at a simple problem.

Find the largest number in a list of numbers.

How do we go about doing this?

1.4.1 Understand the Problem


The first step in program design is to understand the problem. We begin by reading the
requirements statement carefully. When we fully understand it, we review our understand-
ing with the user. Often this involves asking questions to confirm our understanding. For
example, after reading our simple requirements statement, we should ask several clarifying
questions.
1.4  Program Design 11

What type of numbers are we dealing with (with fractions or without fractions)?
Are the numbers arranged in any special sequence, such as lowest to highest?
How many numbers can we expect?

If we don’t clarify the problem—that is, if we make assumptions about the input or
the output—we may supply the wrong answer. To answer our questions, we need to process
integers arranged in any sequence. There is no limit as to the number of integers.
As this example shows, even the simplest problem statements may require clarifica-
tion. Imagine how many questions must be asked for a program that contains hundreds or
thousands of detailed statements.

1.4.2 Develop the Solution


Once we fully understand the problem and have clarified any questions we may have, we
develop a solution in the form of an algorithm. An algorithm is a set of logical steps neces-
sary to solve a problem. Algorithms have two important characteristics: first, they are inde-
pendent of the computer system. This means that they can be used to implement a manual
system in an office as well as a program in a computer. Second, an algorithm accepts data as
input and processes the data into an output.
To write the algorithm for our problem, we use an intuitive approach, calling not only
on the problem statement but also our knowledge and experience. We start with a small set
of five numbers: Once we have developed a solution for five numbers, we extend it to any
number of integers.

13  7  19  29  23

We begin with a simple assumption: The algorithm processes the numbers one at a
time. We name the algorithm FindLargest. Every algorithm has a name to identify it.
FindLargest looks at each number in turn without knowing the values of the others. As it
processes each number, it compares it to the largest number known to that point and deter-
mines if the new number is larger. It then looks at the next number to see if it is larger, and
then the next number and the next number until all of the numbers have been processed.
Figure 1.15 shows the steps in determining the largest among five integers.
The algorithm requires that we keep track of two values, the current number and the
largest number found. We determine the largest number using the following steps.
∙∙ Step 1: We input the first number, 13. Since largest has no value, we set it to the
value of the first number.
∙∙ Step 2: We input the second number, 7. Since 7 is less than 13, the value of largest
does not need to be changed.
∙∙ Step 3: We input the third number 19. When we compare 19 to the value of largest, 13,
we see that 19 is larger. We therefore set largest to 19.
∙∙ Step 4: We input the fourth number, 29. When we compare 29 to the value of largest,
19, we see that 29 is larger. We set largest to 29.
∙∙ Step 5: We input the fifth number, 23. Because it is smaller than 29, largest does not
need to be changed. Because there is no more input, we are done and we have deter-
mined that the largest value is 29.
∙∙ Step 6: We output the value of largest, which is 29.
Another random document with
no related content on Scribd:
Nature, likewise, art, and the sympathy of things in the universe,
as if they were the parts of one animal, contain premanifestations of
certain things with reference to each other. And bodies are so
prepared, that there is a presignification of some by others, which is
clearly indicated by the works performed in predicting what is future.
For those who invoke the divinities for this purpose, have about
them stones and herbs, bind certain sacred bonds, which they also
dissolve, open places that are shut, and change the deliberate
intentions of the recipients, so as from being depraved to render
them worthy, though they were before depraved. Nor are the
artificers of efficacious images to be despised. For they observe the
motion of the celestial bodies, and can tell from the concurrence of
what star with a certain star or stars, predictions will be true or false;
and also whether the things that are performed will be inanities, or
significant and efficacious, though no divinity or dæmon is drawn
down by these images.
But there are some who suppose that there is a certain obedient
genus of dæmons, which is naturally fraudulent, omniform, and
various, and which assumes the appearance of Gods and dæmons,
and the souls of the deceased; and that through these every thing
which appears to be either good or evil is effected; for they are not
able to contribute any thing to true goods, such as those of the soul,
nor to have any knowledge of them, but they abuse, deride, and
frequently impede those who are striving to be virtuous. They are
likewise full of pride, and rejoice in vapours and sacrifices.
Jugglers likewise fraudulently attack us in many ways, through the
ardour of the expectations which they raise.
It very much indeed perplexes me to understand how superior
beings, when invoked, are commanded by those that invoke them, as
if they were their inferiors; and they think it requisite that he who
worships them should be just, but when they are called upon to act
unjustly, they do not refuse so to act. Though the Gods, likewise, do
not hear him who invokes them, if he is impure from venereal
connexions, yet, at the same time, they do not refuse to lead any one
to illegal venery.
[I am likewise dubious with respect to sacrifices, what utility or
power they possess in the universe, and with the Gods, and on what
account they are performed, appropriately indeed, to the powers who
are honoured by them, but usefully to those by whom the gifts are
offered.[20]]
Why also do the interpreters of prophecies and oracles think it
requisite that they should abstain from animals, lest the Gods should
be polluted by the vapours arising from them; and yet the Gods are
especially allured by the vapours of animals?
Why is it requisite that the inspector [who presides over sacred
rites] ought not to touch a dead body, though most sacred operations
are performed through dead bodies? And why, which is much more
absurd than this, are threats employed and false terrors, by any
casual person, not to a dæmon, or some departed soul, but to the
sovereign Sun himself, or to the Moon, or some one of the celestial
Gods, in order to compel these divinities to speak the truth? For does
not he who says that he will burst the heavens, or unfold the secrets
of Isis, or point out the arcanum in the adytum, or stop Baris, or
scatter the members of Osiris to Typhon, [or that he will do
something else of the like kind[21]], does not he who says this, by thus
threatening what he neither knows nor is able to effect, prove himself
to be stupid in the extreme? And what abjectness does it not produce
in those who, like very silly children, are possessed with such vain
fear, and are terrified at such fictions? And yet Chæremon, who was
a sacred scribe, writes these things, as disseminated by the
Egyptians. It is also said, that these, and things of the like kind, are of
a most compulsive nature.
What also is the meaning of those mystic narrations which say that
a certain divinity is unfolded into light from mire, that he is seated
above the lotus, that he sails in a ship, and that he changes his forms
every hour, according to the signs of the zodiac? For thus, they say,
he presents himself to the view, and thus ignorantly adapt the
peculiar passion of their own imagination to the God himself. But if
these things are asserted symbolically, being symbols of the powers
of this divinity, I request an interpretation of these symbols. For it is
evident, that if these are similar to passions of the Sun, when he is
eclipsed, they would be seen by all men who intently survey the God.
What also is the design of names that are without signification?
and why, of such, are those that are barbaric preferred to our own?
For if he who hears them looks to their signification, it is sufficient
that the conception remains the same, whatever the words may be
that are used. For he who is invoked is not of the Egyptian race; nor,
if he was an Egyptian, does he use the Egyptian, or, in short, any
human language. For either all these are the artificial contrivances of
enchanters, and veils originating from our passions, which rumour
ascribes to a divine nature; or we ignorantly frame conceptions of
divinity, contrary to its real mode of subsistence.
I likewise wish you to unfold to me, what the Egyptians conceive
the first cause to be; whether intellect, or above intellect? whether
alone, or subsisting with some other or others? whether incorporeal,
or corporeal; and whether it is the same with the Demiurgus, or prior
to the Demiurgus? Likewise, whether all things are from one
principle, or from many principles? whether the Egyptians have a
knowledge of matter, or of primary corporeal qualities; and whether
they admit matter to be unbegotten, or to be generated? For
Chæremon, indeed, and others, do not think there is any thing else
prior to the visible worlds; but in the beginning of their writings on
this subject, admit the existence of the Gods of the Egyptians, but of
no others, except what are called the planets, the Gods that give
completion to the zodiac, and such as rise together with these; and
likewise, the sections into decans, and the horoscopes. They also
admit the existence of what are called the powerful leaders, whose
names are to be found in the calendars, together with their
ministrant offices, their risings and settings, and their significations
of future events. For Chæremon saw that what those who say that the
sun is the Demiurgus, and likewise what is asserted concerning
Osiris and Isis, and all the sacred fables, may be resolved into the
stars and the phases, occultations and risings of these, or into the
increments or decrements of the moon, or into the course of the sun,
or the nocturnal and diurnal hemisphere, or into the river [Nile].
And, in short, the Egyptians resolve all things into physical, and
nothing into incorporeal and living essences. Most of them likewise
suspend that which is in our power from the motion of the stars; and
bind all things, though I know not how, with the indissoluble bonds
of necessity, which they call fate. They also connect fate with the
Gods; whom, nevertheless, they worship in temples and statues, and
other things, as the only dissolvers of fate.
Concerning the peculiar dæmon, it must be inquired how he is
imparted by the lord of the geniture, and according to what kind of
efflux, or life, or power, he descends from him to us? And also,
whether he exists, or does not exist? And whether the invention of
the lord of the geniture is impossible, or possible? For if it is possible
he is happy, who having learned the scheme of his nativity, and
knowing his proper dæmon, becomes liberated from fate.
The canons, also, of genethlialogy [or prediction from the natal
day] are innumerable and incomprehensible. And the knowledge of
this mathematical science cannot be obtained; for there is much
dissonance concerning it, and Chæremon and many others have
written against it. But the discovery of the lord, or lords, of the
geniture, if there are more than one in a nativity, is nearly granted by
astrologers themselves to be unattainable, and yet they say that on
this the knowledge of the proper dæmon depends.
Farther still, I wish to know whether the peculiar dæmon rules
over some one of the parts in us? For it appears to certain persons,
that dæmons preside over the parts of our body, so that one is the
guardian of health, another of the form of the body, and another of
the corporeal habits, and that there is one dæmon who presides in
common over all these. And again, that one dæmon presides over the
body, another over the soul, and another over the intellect; and that
some of them are good, but others bad.
I am also dubious whether this dæmon is not a certain part of the
soul, [such, for instance, as the intellectual part;] and if so, he will be
happy who has a wise intellect.
I see likewise, that there is a twofold worship of the peculiar
dæmon; the one being the worship as of two, but the other as of
three. By all men, however, the dæmon is called upon by a common
invocation.
I farther ask, whether there is a certain other latent way to felicity,
separate from the Gods? And I am dubious whether it is requisite to
look to human opinions in divine divination and theurgy? And
whether the soul does not devise great things from casual
circumstances? Moreover, there are certain other methods, which
are conversant with the prediction of future events. And, perhaps,
those who possess divine divination, foresee indeed what will
happen, yet are not on this account happy; for they foresee future
events, but do not know how to use this knowledge properly. I wish,
therefore, that you would point out to me the path to felicity, and
show me in what the essence of it consists. For with us [Greeks]
there is much verbal contention about it, because we form a
conjecture of good from human reasonings. But by those who have
devised the means of associating with beings more excellent than
man, if the investigation of this subject is omitted, wisdom will be
professed by them in vain; as they will only disturb a divine intellect
about the discovery of a fugitive slave, or the purchase of land, or, if
it should so happen, about marriage, or merchandize. And if they do
not omit this subject, but assert what is most true about other things,
yet say nothing that is stable and worthy of belief about felicity, in
consequence of employing themselves about things that are difficult,
but useless to mankind; in this case, they will not be conversant
either with Gods or good dæmons, but with that dæmon who is
called fraudulent; or, if this is not admitted, the whole will be the
invention of men, and the fiction of a mortal nature.
Iamblichus[22] on the Mysteries, &c.
THE

ANSWER OF THE PRECEPTOR ABAMMON

TO THE

EPISTLE OF PORPHYRY TO ANEBO,

AND A

SOLUTION OF THE DOUBTS CONTAINED IN


IT.
SECTION I.

CHAP. I.

Hermes, the God who presides over language, was formerly very
properly considered as common to all priests; and the power who
presides over the true science concerning the Gods is one and the
same in the whole of things. Hence our ancestors dedicated the
inventions of their wisdom to this deity, inscribing all their own
writings with the name of Hermes. If, therefore, we participate of a
portion of this God, adapted and commensurate to our powers, you
do well to propose your theological doubts to the priests, as friends,
and to make these doubts known to them. I also very properly
conceiving that the epistle sent to my disciple Anebo was written to
me, shall give you a true answer to your inquiries. For it would not be
becoming, that Pythagoras and Plato, Democritus and Eudoxus, and
many other of the ancient Greeks, should have obtained appropriate
instruction from the sacred scribes of their time, but that you who
are our contemporary, and think conformably to those ancients,
should be frustrated of your wish by those who are now living, and
who are called common preceptors. I, therefore, thus betake myself
to the present discussion; and do you, if you please, conceive that the
same person to whom you sent the letter returns you an answer. Or,
if it should seem fit to you, admit it to be me who discourses with you
in writing, or some other prophet of the Egyptians, for this is of no
consequence. Or, which I think is still better, dismiss the
consideration whether the speaker is an inferior or a superior
character, but direct your attention to what is said, so as readily to
excite your mind to survey whether what is asserted is true or false.
In the first place, therefore, we shall divide the genera of the
proposed problems, in order that we may know the quantity and
quality of them. And, in the next place, we shall show from what
theologies the doubts are assumed, and according to what sciences
they are investigated. For some things that are badly confused,
require a certain distinction; others are conversant with the cause
through which they subsist, and are apprehended; others, which we
propose according to a certain contrariety, draw our decision on both
sides; and some things require from us the whole development of
mystic doctrines. Such, therefore, being the nature of the subjects of
discussion, they are assumed from many places, and from different
sciences. For some things introduce animadversions from what the
wise men of the Chaldeans have delivered; others produce objections
from what the prophets of the Egyptians teach; and there are some
that, adhering to the theory of philosophers, make inquiries
conformably to them. There are now likewise some, that from other
opinions, which do not deserve to be mentioned, elicite a certain
dubitation; and others originate from the common conceptions of
mankind. These things, therefore, are of themselves variously
disposed, and are multiformly connected with each other. Hence,
through all these causes, a certain discussion is requisite for the
management of them in a becoming manner.
CHAP. II.

We shall, therefore, deliver to you the peculiar dogmas of the


Assyrians; and also clearly develop to you our own opinions;
collecting some things from the infinite writings of the ancients, but
others from those particulars which were comprehended by the
ancients in one treatise, and pertain to the whole knowledge of divine
natures. If also you should propose any philosophic inquiry, we shall
discuss it for you, according to the ancient pillars of Hermes, which
Plato and Pythagoras knew before, and from thence constituted their
philosophy. But such things as exhibit foreign inquiries, or which are
contradictory and contentious, we shall assist mildly and aptly, or we
shall demonstrate their absurdity. Such, likewise, as proceed
conformably[23] to common conceptions, we shall endeavour to
discuss in a way perfectly known and clear. And things, indeed,
which require the experience of divine operations to an accurate
knowledge of them, we shall explain, as far as this is possible to be
effected by words alone; but such as are full of intellectual theory, we
shall develop with a view to the purification of the soul. But
indications of this theory worthy of notice may be mentioned, by
which it is possible for you, and those who resemble you, to be
conducted by intellect to the essence of [real] beings. And with
respect to such things as become known by a reasoning process, we
shall leave no one of these without a perfect demonstration. But in all
things we shall give to each that which is appropriate. And such
questions, indeed, as are theological, we shall answer theologically;
such as are theurgic, theurgically; but such as are philosophical, we
shall, in conjunction with you, philosophically explore. Of these, also,
such as extend to first causes, we shall unfold into light, by following
them conformably to first principles. But such as pertain to morals,
or to ends, we shall fitly discuss, according to the ethical mode. And,
in a similar manner, we shall examine other things methodically and
appropriately. Let us, therefore, now betake ourselves to your
inquiries.
CHAP. III.

In the first place, therefore, you say, “it must be granted that there
are Gods.” Thus to speak, however, is not right on this subject. For
an innate knowledge of the Gods is coexistent with our very essence;
and this knowledge is superior to all judgment and deliberate choice,
and subsists prior to reason and demonstration. It is also counited
from the beginning with its proper cause, and is consubsistent with
the essential tendency of the soul to the good. If, indeed, it be
requisite to speak the truth, the contact with divinity is not
knowledge. For knowledge is in a certain respect separated [from its
object] by otherness.[24] But prior to the knowledge, which as one
thing knows another, is the uniform connexion with divinity, and
which is suspended from the Gods, is spontaneous and inseparable
from them. Hence, it is not proper to grant this, as if it might not be
granted, nor to admit it as ambiguous (for it is always unically
established in energy); nor are we worthy thus to explore it, as if we
had sufficient authority to approve or reject it. For we are
comprehended in it, or rather we are filled by it, and we possess that
very thing which we are, [or by which our essence is characterized] in
knowing the Gods.
I shall likewise say the same thing to you, concerning the more
excellent genera that follow the Gods, I mean dæmons, heroes, and
undefiled souls.[25] For it is necessary to understand respecting these,
that there is always in them one definite reason of essence, and to
remove from them the indefiniteness and instability of the human
condition. It is likewise requisite to separate from them that
inclination to one side of an argument rather than another, arising
from the equilibrium of a reasoning process. For a thing of this kind
is foreign from the principles of reason and life, and rather tends to
secondary natures, and to such things as pertain to the power and
contrariety of generation. But it is necessary that the more excellent
genera should be apprehended uniformly.
The connascent perception, therefore, of the perpetual attendance
of the Gods, will be assimilated to them. Hence, as they have an
existence which is always invariably the same, thus also the human
soul is conjoined to them by knowledge, according to a sameness of
subsistence; by no means pursuing through conjecture, or opinion,
or a syllogistic process, all which originate in time, an essence which
is above all these, but through the pure and blameless intellections
which the soul received from eternity from the Gods, becoming
united to them. You, however, seem to think, that there is the same
knowledge of divine natures as of any thing else, and that one thing,
rather than another, may be granted from opposites, in the same
manner as it is usual to do in dialectic discussions. There is, however,
no similitude whatever between the two kinds of knowledge. For the
knowledge of divine natures is different from that of other things,
and is separated from all opposition. It likewise neither subsists in
being now granted, or in becoming to be, but was from eternity,
uniformly consubsistent with the soul. And thus much I say to you
concerning the first principle in us, from which it is necessary those
should begin who speak or hear any thing about the natures that are
superior to us.
CHAP. IV.

With respect to your inquiry, “what the peculiarities are in each of


the more excellent genera, by which they are separated from each
other?” if you understand by peculiarities the specific differences
under the same genus, which are distinguished by opposite qualities,
as the rational and irrational under animal; we by no means admit
peculiarities of this kind, in things which neither have one common
essence, nor an equal contradistinction, nor receive a composition
from something common, which is indefinite, and defines the
peculiarity. But if you apprehend the peculiarity to be, as in prior and
secondary natures, differing in their whole essence and whole genus,
a certain simple condition of being, definite in itself; in this case,
your conception of peculiarities will be reasonable. For these
peculiarities of things, which have an eternal subsistence, are simple,
and entirely exempt. The inquiry, however, proceeds imperfectly. For
it was necessary, in the first place, to inquire what the peculiarities
are of the more excellent genera, according to essence; in the next
place, what they are according to power; and thus afterwards, what
they are according to energy. But, as your question now stands, with
respect to the peculiarities by which these genera are separated, you
alone speak of the peculiarities of energies. Hence you inquire
concerning the difference in the last things pertaining to them; but
you leave uninvestigated such things as are first, and most
honourable in them, and which are the elements of their difference.
In the same place, also, something is added concerning “efficacious
and passive motions,” which is a division by no means adapted to
the difference of the more excellent genera. For the contrariety of
action and passion is not inherent in any one of them; but their
energies are unrestrained, immutable, and without habitude to their
opposites. Hence, neither must we admit in them motions of such a
kind as arise from action and passion. For neither do we admit in the
soul a self-motion, which consists of the mover and that which is
moved; but we conceive that it is a certain simple essential motion,
subsisting from itself,[26] and not possessing a habitude to another
thing, and exempt from acting on, and suffering from, itself. Who,
therefore, can endure that the peculiarities of the genera superior to
the soul, should be distinguished according to active or passive
motions?
That also which is added by you, “or of accidents,” is foreign from
these genera. For in composites, and things which exist together
with, or in others, or are comprehended by others, some things are
conceived to be precedaneous, but others consequent; and some as
essences, but others, as afterwards acceding to essences. For there is
a certain coarrangement of them, and incongruity and interval
intervenes. But, in the more excellent genera, all things must be
conceived in τῳ ειναι, i. e. in merely existing; and wholes have a
precedaneous subsistence, are separate by themselves, and have not
their hypostasis from, or in others; so that there is not any thing in
them which is accidental. Hence the peculiarity of them is not
characterized from accidents.
At the end, likewise, of your inquiry, you introduce a distinction
according to nature. For your question asks, “How essences are
known by energies, by physical motions, and by accidents?” The
very contrary, however, to all this takes place. For if energies and
motions were constitutive of essences, they would be the lords of the
difference which is between them. But if essences generate energies,
the former being separate prior to the latter, will impart to motions,
energies, and accidents, that by which they differ from each other.
This, therefore, subsists contrarily to what you suppose, for the
purpose of discovering the peculiarity which you now investigate.
In short, whether you think that there is one genus of the Gods,
one of dæmons, and in a similar manner of heroes, and souls
essentially incorporeal; or whether you admit that these are severally
many, you inquire what the difference of them is according to
peculiarities. For if you apprehend that each of these is one [and the
same genus] the whole arrangement of scientific theology is
confounded. But if, as truth requires, you admit that they are
genetically distinguished, and that there is not in them one common
essential definition, but that those of them which are prior, are
exempt from those that are inferior, it is not possible to discover
their common boundaries. And even if this were possible, this very
thing would destroy their peculiarities. In this way, therefore, the
object of investigation cannot be found. He, however, he who directs
his attention to the analogous sameness which exists in superior
natures, as, for instance, in the many genera of the Gods, and again
in dæmons and heroes, and, in the last place, in souls, will be able to
define their peculiarities. Hence through this, it is demonstrated by
us what the rectitude is of the present inquiry, and what its
[accurate] distinction, and also in what manner it is impossible, and
in what manner it is possible, for it to subsist.
CHAP. V.

In the next place, let us direct our attention to the solution of your
inquiries. There is, therefore, the good itself which is beyond essence,
and there is that good which subsists according to essence; I mean
the essence which is most ancient and most honourable, and by itself
incorporeal. And this is the illustrious peculiarity of the Gods, which
exists in all the genera that subsist about them, preserving their
appropriate distribution and order, and not being divulsed from it,
and at the same time being inherent with invariable sameness in all
the Gods, and their perpetual attendants.
In souls, however, which rule over bodies, and precedaneously pay
attention to them, and which, prior to generation, have by
themselves a perpetual arrangement, essential good is not present,
nor the cause of good, which is prior to essence; but to these a certain
participation[27] and habit, proceeding from essential good, accedes;
just as we see that the participation of beauty and virtue is very
different [in these souls] from that which we behold in men. For the
latter is ambiguous, and accedes to composite natures as something
adventitious. But the former has an immutable and never failing
establishment in souls, and neither itself ever departs from itself, nor
can be taken away by any thing else. Such, therefore, being the
beginning and end in the divine genera, conceive two media between
these extreme boundaries, viz. the order of heroes, which has an
arrangement more elevated than that of souls, in power and virtue,
in beauty and magnitude, and in all the goods which subsist about
souls, and which, though it entirely transcends the psychical order,
yet, at the same time, is proximately conjoined to it, through the
alliance of a similar formed life. But the other medium, which is
suspended from the Gods, though it is far inferior to them, is that of
dæmons, which is hot of a primarily operative nature, but is
subservient to, and follows the beneficent will of the Gods. It likewise
unfolds into energy the invisible good of the Gods, being itself
assimilated to it, and gives completion to its fabrications
conformably to it. For it renders that which is ineffable in the good of
the Gods effable, illuminates that which is formless in forms, and
produces into visible reasons [or productive forms] that which in
divine good is above all reason. Receiving also a connascent
participation of things beautiful, it imparts and transfers it, in
unenvying abundance, to the genera posterior to itself. These middle
genera, therefore, give completion to the common bond of the Gods
and souls, and cause the connexion of them to be indissoluble. They
also bind together the one continuity of things from on high as far as
to the end; make the communion of wholes to be inseparable; cause
all things to have the best, and a commensurate mixture; in a certain
respect, equally transmit the progression from more excellent to
inferior natures, and the elevation from things posterior to such as
are prior; insert in more imperfect beings order and measures of the
communication which descends from more excellent natures, and of
that by which it is received; and make all things to be familiar and
coadapted to all, supernally receiving the causes of all these from the
Gods.
You must not, therefore, think that this division is the peculiarity
of powers or energies, or of essence; nor assuming it separately, must
you survey it in one of these. But by extending it in common through
all the genera, you will give perfection to the answer concerning the
peculiarities of Gods, dæmons, and heroes, and also of those in souls
which are now the subjects of your inquiry.
Again, however, according to another mode of considering the
subject, it is necessary to ascribe to the Gods the whole of that which
is united, of whatever kind it may be; that which is firmly established
in itself, and which is the cause of impartible essences; the
immoveable, which also is to be considered as the cause of all
motion, and which transcends the whole of things, and has nothing
in common with them; and the unmingled and the separate,
understood in common in essence, power and energy, and every
thing else of this kind. But that which is now separated into
multitude, and is able to impart itself to other things, and which
receives from others bound in itself, and is sufficient in the
distributions of partible natures, so as to give completion to them;
which also participates of the primarily operative and vivific, having
communion with all real and generated beings; receives a
commixture from all things, imparts a contemperation to all things
from itself, and extends these peculiarities through all the powers,
essences, and energies, in itself; all this we shall truly ascribe to
souls, by asserting that it is naturally implanted in them.
CHAP. VI.

What, therefore, shall we say concerning the media? I think,


indeed, that from what has been before said, they will be manifest to
every one; for these give completion to the indivisible connexion of
the extremes. Nevertheless, it is necessary to be more explicit. I
consider, therefore, the dæmoniacal tribe to be multiplied, but,
unitedly, to be comingled, but in an unmingled manner, and to
comprehend all other things of a subordinate nature, according to
the idea of that which is more excellent. But again, the tribe of heroes
supernally presides over a more obvious division and multitude, and
likewise over motion, commixture, and things allied to these. It also
receives gifts of a more excellent nature, concealed as it were
inwardly; I mean union, purity, a firm establishment, impartible
sameness, and a transcendency above other things. For one of these
middle genera is proximate to the first, but the other to the last, of
the extremes. But it reasonably follows, according to continuity of
alliance, that the medium which begins from the most excellent
natures, should proceed to such as are less excellent; but that the
medium which primarily produces a contact with the last of things,
should also in a certain respect communicate with the natures that
transcend it. From these media, also, the completion may be seen of
the first and last genera, and this entirely connascent, in a similar
manner, in existence, in power, and in energy. As we have, therefore,
in these two ways, perfectly completed the division of the four
genera, we shall deem it sufficient in the others, to exhibit the
extreme peculiarities alone, for the sake of conciseness, and because
what remains, i. e. the comprehension of the media, is in a certain
respect evident. But the media themselves, as being known from the
extremes, we shall omit; making a definition of the extremes in the
shortest way, as follows.
CHAP. VII.

Of the extremes, therefore, one is supreme, transcendent, and


perfect; but the other is last in dignity, deficient, and more imperfect.
And the former, indeed, is capable of accomplishing all things at
once, uniformly in an instant; but the latter is neither able to effect
all things, nor at once, nor suddenly, nor impartibly. The former also
generates and governs all things, without being inclined towards
them; but the latter is naturally disposed to verge, and be converted
to the things which it generates and governs. And the former, indeed,
as primordial and cause, precedes all things in power; but the latter,
being suspended from the will of the Gods, as from a cause, is from
eternity consubsistent with it. The former, likewise, according to one
vigorous acme, comprehends the ends of all energies and essences;
but the latter passes from some things to others, and proceeds from
the imperfect to the perfect. Farther still, to the former that which is
highest and that which is incomprehensible pertain, and also that
which is better than all measure, and is in such a manner formless,
as not to be circumscribed by any form; but the latter is vanquished
by inclination, habitude, and propensity; and is detained by appetites
directed to that which is less excellent, and by familiarity with
secondary natures. Hence, in the last place, it is formalized by all-
various measures derived from them. Intellect, therefore, which is
the leader and king of all beings, and which is the demiurgic art of
the universe, is always present with the Gods with invariable
sameness, perfectly, and without indigence, being purely established
in itself, according to one energy. But soul participates of a partible
and multiform intellect, having its attention directed to the
government of the whole. It also providentially attends to inanimate
natures, becoming at different times ingenerated in different forms.
From the same causes, therefore, order and beauty itself are
consubsistent with the more excellent genera; or, if some one had
rather admit it, the cause of these is consubsistent with them. But

You might also like