Sie sind auf Seite 1von 10

Chapter 0

• Read 1-4 From A Book On C


• Fun stuff

1/9/2007 CECS 130-Ibrahim Imam 1


Course Calendar

1/9/2007 CECS 130-Ibrahim Imam 2


1.1 Introduction to Programming.
Programming Languages
•Computer Program: FORTRAN (FORmula TRANslation) was introduced
A sequence of instructions used to in 1957 and was used to translate formulas into
computer readable format.
operate a computer to produce a
desired result. COBOL (COmmon Business Oriented Language)
was introduced in 1960 and was used for translating
•Programming: business applications into computer readable
The Process (more than one step) format.
of writing these instructions in a BASIC (Beginners All-purpose Symbolic
language that the computer can Instructions Code) was developed in 1960 at
respond to and that other Dartmouth College as a straight forward language
that is easy to understand.
programmers can understand.
Pascal was developed in 1970 for the purpose of
•Programming Language: introducing a modular structured language and
The set of instructions that can be became mainly a language used for educational
used to construct a program. purposes.
C was developed in the 1970s at Bell Labs. It has
it’s roots in a language called B. C has an extensive
set of capabilities and gained wide acceptance as
the “professional programming language” and is
currently maintained by the American National
Standards Institute (ANSI).

1/9/2007 CECS 130-Ibrahim Imam 3


Introduction to Programming.
Algorithms
Algorithm:
A step-by-step sequence of instructions that describes how to perform a computation. The
programmer must clearly understand what the outcome of a procedure should be and how to achieve
it. Below are three different algorithms that may be used to add the integers from 1 to 100.

Step by step instructions for


implementing method three will be
as follows:
1)Set n = 100
2)Set a=1
3)Set b = 100
4)Set sum = n*(a+b)/2

1/9/2007 CECS 130-Ibrahim Imam 4


1.1 Introduction to Programming.
From Algorithms to Programs
• Converting an algorithm into a program is called coding.
• Coding is done using a programming language such as C which is easily understood by
programmers but not necessarily by computers.
• Such language is normally called high level language. The part of the program written in
the high level language is called source code and is saved in what we call a source file.
• Instructions that consist of 1s and 0s and are understood by the computer are called
machine instructions or collectively as machine language.
• To convert from source code to machine instructions we must use a translator.
– If we chose to use a translator that translates one instruction at a time and executes the corresponding
step immediately, then we are using an interpreter. Languages that allow for such translation are called
interpreted languages.
– If we chose to translate the entire algorithm at once an then execute it at a later stage, then we are said
to be using a compiled language. Translators used with compiled languages are called compilers.
Compiled code is machine code but it is not stand alone code. To make it so we must append additional
code provided by the designer/vendor of the compiler. Such a process is called linking and is performed
by a linker program. The result of compiling and linking is a stand alone program (executable) that can
be run on the computer for which it was designed.

1/9/2007 CECS 130-Ibrahim Imam 5


1.2 Introduction to Modularity
• A close examination of the power train of a motor vehicle reveals that it consist of
several components functioning together:
1. The engine is responsible for converting thermal energy into kinetic energy in the form of a rotating
flywheel.
2. The transmission is responsible for adjusting the output of the engine to produce the torque necessary
to propel the vehicle.
3. The axels responsible for transmitting this torque to the wheels
• Such design makes it easier to design, construct, and maintain the vehicle.
• Such a design strategy is called modular design strategy.
• Modular design strategy calls for dividing the whole product into well defined and clearly
separate components each of which is called a module.
• Each module should have a clearly defined task with a well defined input and well
defined output.
• Modular design strategy was successfully adapted in designing computer programs.
• A modularly designed program with all it’s tasks clearly marked and separated into well
defined modules is called a structured program. Thus, a structured program is a
complete program constructed by combining as many module (smaller programs
performing very limited number of tasks) as needed to perform the desired task.
• Example: I would like to retrieve all my students’ records from PeopleSoft, I would like to
sort these records, and finally I would like to print my class role. A typical design would
be to create three modules.
1. A data retrieval module,
2. A sorting module, and
3. A printing module.

1/9/2007 CECS 130-Ibrahim Imam 6


Programming Style
Both programs below will produce identical A computer engineer and Rear Admiral in
results, but if you are to work on one of the U.S. Navy named Grace Murray
these to fix a bug which one would you Hopper developed the first computer
rather work with: compiler in 1952 and the computer
programming language COBOL. Upon
discovering that a moth had jammed the
works of an early computer, Hopper
popularized the term "bug."

1/9/2007 CECS 130-Ibrahim Imam 7


Dev-C++ (Bloodshed)

1/9/2007 CECS 130-Ibrahim Imam 8


Output Window

1/9/2007 CECS 130-Ibrahim Imam 9


Downloading Dev-C++
• http://www.bloodshed.net/dev/devcpp.html

1/9/2007 CECS 130-Ibrahim Imam 10