Title: An introduction to Computer Science ITM 171 Chapters part of 7 and all of 8
1An introduction to Computer ScienceITM
171Chapters (part of) 7 and (all of) 8
2Examples of Programming Languages
- BASIC
- FORTRAN
- COBOL
- PASCAL
- C
- C
- JAVA
3Why do we have so many different programming
languages?
- Each language was designed to meet specific
needs. FORTRAN was designed with engineering
applications in mind COBOL was designed with
report generation in mind. - Just as we have different types of vehicles for
different types of transportation needs, we have
different types of programming languages for
different types of processing needs.
42 WAYS TO CATEGORIZE PROGRAMMING LANGUAGES
- 1. By generation
- 2. By philosophy or paradigm
51. BY GENERATION
- First
- Second
- Third
- Fourth
6First Generation Language
- The earliest pioneers of programming actually set
the ON/OFF switches to represent the op codes and
operands that made up programming statements. - Writing programs for even simple processes was
tedious and error prone.
7Machine Language looks like this
- 010001 0011100 000111
- 001101 1100111 110001
- 010101 0010111 001110
- 011000 0101011 101011
8Second Generation Language (aka Assembly language)
- Assembly language simplified a programmers job
by allowing the programmer to use mnemonics in
place of the 0s and 1s in the program. - Mnemonics are memory aids - alphabetic
abbreviations for instructions. For example,
ADD may represent the op code 0101001 for
addition, or MUL may represent the op code
101010 for multiplication. - Programs written in assembly language require an
assembler to translate the assembly language code
into machine language so the program can be run. - One line of programming code in assembly language
translates into one line of programming code in
machine language.
9Assembly Language looks like this
10Assembly language disadvantages
- The programmer must manually manage the
movement of data items between and among memory
locations. - The programmer must take a microscopic view of
tasks - Assembly language is machine specific (not
portable) - The language is not very English-friendly
11Third Generation Languages
- Most languages that you hear of today are third
generation languages. Examples FORTRAN, COBOL,
BASIC, C, C, JAVA, etc. - 3rd generation languages allow the programmer to
use instructions that more closely resemble the
English language. - One line of programming code in 3rd generation
language translates into several lines of
programming code in machine language. - 3rd generation languages must be translated into
machine language using a compiler or interpreter.
12Third Generation Language looks like this (BASIC)
- input Enter name names
- input Enter hours hours
- input Enter rate rate
- grosshours rate
- fedtax .2 gross
- socsec .07 gross
- net gross - fedtax - socsec
- print names, net
- end
13What 3GLs provide that 2GLs dont
- The programmer need not manage the details of
movement of data - The programmer can take a macroscopic view of
tasks - Programs are portable - not machine specific
- The language is more English-friendly
14Fourth Generation Languages
- Fourth-generation languages are programming
languages closer to human languages than typical
high-level programming languages. Most 4GLs are
used to access databases.
15Fourth Generation Language looks like this
- FIND ALL RECORDS WHERE NAME IS "SMITH"
162. Categorizing languages by paradigm (philosophy)
- IMPERATIVE (PROCEDURAL) LANGUAGES (Like C, COBOL,
BASIC, FORTRAN) - OBJECT ORIENTED LANGUAGES (Like C, JAVA, Visual
BASIC) - SPECIAL PURPOSE LANGUAGES
- FUNCTIONAL LANGUAGES
- LOGIC LANGUAGES
17IMPERATIVE (PROCEDURAL) LANGUAGES
- Philosophy A program is a series of tasks that
can be divided into sub-tasks.
18The Procedural approach to application
development
- Top-down, stepwise refinement.
- High-level goals and processes are defined first.
Then high-level processes are divided into tasks,
who are in turn divided into sub tasks and each
sub-task can be coded separately and then
integrated into the application. - A program written in an imperative language
consists of a sequence of statements that
manipulate data items that is, they change the
contents of memory cells. - It is the programmers task to devise the
appropriate step-by-step sequence of imperative
commands that will accomplish the desired task. - Examples FORTRAN, COBOL, Pascal, C, Ada
19FORTRAN
- Good for mathematically intensive programs (Can
be used to tell the computer how to carry out
extended precision arithmetic) - FORTRAN is still an effective language for
engineering applications
20COBOL
- Good for business applications which are not
mathematically intensive but require a lot of
repetitive (record) processing and report
generation (such as payroll applications or
inventory update programs) - In the 1970s, payroll and inventory data were
stored as records in a master file. Data needed
for weekly updates were stored in a transaction
file. Programs were written to use the data in
the transaction file to create a new (updated)
master file. COBOL was good at handling this type
of program.
21PASCAL
- A language designed for teaching computer science
majors how to program. - It is designed to be relatively easy to learn
- Rarely used in real business or engineering
applications
22C
- C has the power of a high level language but the
control of a low level language - Writing in C allows you to think at a high level
of abstraction but also allows you to have
control over memory access and storage.
Therefore, it is good for writing programs that
are need to be (1) highly efficient and (2) need
direct control over memory access and allocation
such as an operating system program (Unix) or a
compiler. (Yes, the compiler is also a program!)
23OBJECT ORIENTATED LANGUAGES
- Philosophy A program is a series of objects that
have attributes and behaviors (procedures).
24The OO approach to application development
- Instead of using task-focused approach where one
large task is subdivided into smaller tasks and
each task is coded separately, an OO programmer
uses an object-focused approach to designing an
application. - In other words, program design starts with
enumerating the objects involved in the
application.
25Objects Examples
- In a word processing program, you have objects
such as letter, paragraph, and document. A
document object is made up of paragraph objects
which are in turn, made up of letter objects. - In a spreadsheet program, you have objects such
as cell, column, row, block, pie chart, pie chart
title, line graph, legend, x-axis, y-axis. A
graph object is made up of a title object, an
x-axis object, a y-axis object, a gridline
object, data point objects, and a legend object. - In a presentation program (such as this one), you
have objects such as slide, slide title, bullet
point, graphic image, etc. A slide object is made
up of a slide title object, slide bullet point
objects and maybe one or more graphic image
objects. - In a bank account processing application, you
have objects such as customer, checking account,
savings account, loan account.
26The OO approach continued...
- After identifying the objects that are relevant
to the application, the program determines what
attributes the object must have and what
procedures need to be performed on the objects. - For example, the object bank account can have
attributes open date, balance, owner,
over-draft limit, etc. - An object bank account can have procedures such
as update balance, close, open, print
statement, etc.
27Other examples of object attributes and processes
- A letter object in a word processing document has
attributes such as a size, a font style, a color,
a boldness setting, an underline setting. etc. - Certain processes (behaviors) can be performed on
letter objects such as create, change size,
change color, move or delete. - Each time you type a letter you are creating an
instance of a letter object.
28Here is what an object definition looks like
- class date
-
- public
- void changeDate (int month, int day, int year)
- void displayDate( )
- private
- int month
- int day
- int year
-
- date payDay // This creates a date object named
PayDay
Two Methods(behaviors)
Three attributes
29Does OO abandon the idea of the procedural
approach to application development?
- No. The procedures (i.e. algorithms) reside in
the functions which perform processes on objects. - Instead of one big long procedure that runs from
start to finish (like a payroll processing
application), there are several short procedures
and the user controls their order and frequency
of execution (often by using mouse clicks).
30Programming in an OO language means
- 1. Defining and using objects their attributes
and the processes (behaviors) that can be
performed on them or that they can perform on
other objects (behaviors). - 2. Knowing how to use (and extend) predefined
objects Many objects have already been created
by someone else and stored in class (object)
libraries. You can download or purchase class
libraries that contain commonly-used objects such
as Window, scroll bar, or icon and
customize them for your own purposes. (Thus, the
idea of reusable code.)
31OOP Terminology
- Class - the definition of an object. A class
contains all of the attributes and all of the
behaviors that describe an object. First you
define a class/object then you instantiate it. - Encapsulation - the concept of combining an
objects attributes and behaviors into one
package - the class. - Abstraction - the concept of making the
implementation details of a class transparent to
the user. If a programmer obtains a class
definition from someone else (a class library),
the user need only know how to create an instance
of the class and how to tell it to perform
procedures. The programmer need NOT know any more
implementation details. (Example You need to
know how to start and stop the engine of your
car. You need NOT know how the engine actually
works.) - Inheritance - the concept that you can create a
new class by extending a base class. For example,
class BOX drawn on screen can be extended to
class WINDOW.
32JAVA
- Good for writing programs that use multi-media
and that need to run on many different types of
computers.
33C
- A language developed as an extension of the C
language. - Emphasizes software reuse
34SPECIAL PURPOSE LANGUAGES
- SQL - Structured Query Language - A language
designed to extract useful information from a
database. - PERL - Practical Extraction and Report Language -
used to scan arbitrary text files and extract
various kinds of information that is contained
within the text and print reports based on the
extracted information. - Perl is often used to process data submitted via
input forms embedded in Web pages. The data
submitted via on-screen form will be sent to the
server as a continuous stream of text. Perl can
be used to parse the string and structure the
data so it can be added to a database. - HTML - Hypertext Markup Language - used to create
documents that contain formatting codes
understandable to a Web browser.
35Functional Programming (LISP) -
- Philosophy a program is a series of function
calls - A function is a procedure which transform a
series of inputs into a single output. - The programmer to not have to focus on the
step-by-step procedures. - LISP is the well-known functional programming
language.
36Logic programming-
- Philosophy A program consists of a collection of
facts and rules which are used to infer other
facts to derive knowledge - Prolog is the most well-know logic language.
37Parallel Programming - Two approaches
- SIMD (single instruction steam/multiple data
stream) - a single control unit broadcasts a
single program instruction to multiple ALUs,
each of which carries out that instruction on its
own local data stored in its local memory. - MIMD (multiple instruction stream/multiple data
stream) - numerous inter-connected processors
execute their own programs on their own data,
communicating results as necessary.