Chapter 1 – Introduction
Chapter 1 – Introduction
PROGRAMMING BASIC
– IN C
MODULE CODE: CS 6224
MODULE NAME: Computer Programming Basic in C
FACILITATOR: Pangahela, R. A
Email: [email protected] Phone: +255 742 926 569
COMPUTER
PROGRAMMING BASIC – IN C
CHAPTER 1 – INTRODUCTION
1.1 Introduction to Programming
1.2 Program Development
1.2.1 Define the Problem
1.2.2 Outline the Solution
1.2.3 Develop the Algorithm
1.2.4 Test the Algorithm for Correctness
1.2.5 Code the Algorithm
1.2.6 Compile
1.2.7 Run the Program
1.2.8 Test, Document and Maintain the Program
1.3 Running a Program
1.4 Programming Languages
1.5 Overview of C
1.6 Steps in Developing a Program in C
1.2 Program Development
Developing a program involves a set of steps:
1. Define the problem
2. Outline the solution
3. Develop an algorithm1
4. Test the algorithm for correctness
5. Code the algorithm using a suitable
programming language
6. Compile and correction of compile errors
7. Run the program on the computer
8. Test, document and maintain the program
Most of these steps are common to any problem
solving task. Program development (software
development) may take several hours, days, weeks,
months or years. After development, customers will
make use of the system. While in use, the system
needs to be maintained. The maintenance phase will
continue for several months, years or even several
decades. Therefore software development is not a
onetime task; it is a lifecycle where some of the
above steps are reformed again and again. The
steps are discussed in the following.
1.2.2 Outline the Solution
The programmer should define:
• the major steps required to solve the problem
• any subtasks
• the major variables and data structures
• the major control structures (e.g. sequence,
selection, repetition loops)2 in the algorithm
• the underlined logic
Consider the above mentioned example. In order
to calculate the circumference:
• Variables – radius (r), circumference (c)
• Calculation – c = 2pr
In order to calculate the area:
• Variables – radius (r), area (a)
• Calculation – a = pr2
Start
Input r
Calculate circumference
c = 2 * PI* r
Calculate area
a = PI* r^2
Output c & a
End
In here PI is a constant that represents the value
of p.
1.2.4 Test the Algorithm for Correctness
The programmer must make sure that the algorithm
is correct. The objective is to identify major logic
errors early, so that they may be easily corrected.
Test data should be applied to each step, to check
whether the algorithm actually does what it is
supposed to.
Our simple example can be quite easily check by
submitting some values for radius (r) and walking
through the algorithm to see whether the resulting
output is correct for each input.
1.2.5 Code the Algorithm
After all the design considerations have been
met and when the algorithm is finalized code it
using a suitable programming language.
1.2.6 Compile
The next step is to compile (section 1.3) the
program. While compiling syntax errors can be
identified. When the written program does not
adhere to the programming language rules those
are called syntax errors.
These programs convert the high-level language
program, into machine language programs.
Programs written in programming languages such
as FORTRAN, COBOL, C, C++ and Pascal must be
compiled before executing.
Input Masks
An input mask is used to pre-format a field to
“look/act” a certain way when a user inputs data.
Examples: Social Security Number input mask
automatically inserts the dashes; phone numbers
automatically inserts the parentheses and dashes.
The input mask data can either be stored in the
table or simply displayed and not stored.
To Create an Input Mask for a Field:
1. In Design View, click in a field for which
you’d like to apply an input mask
2. In the Field Properties section at the
bottom of the screen, click in the Input Mask
line and notice the Build button that appears
at the right end of the line (see on next
page):
As in Figure 1.2 when the executable file is
available it can be executed by providing
necessary input data so that it produces the
desired outputs.
Interpreters convert a source program and execute
it at the same time (Figure 1.3). Each time the
program runs, the interpreter converts high-level
language instructions and input data to a machine
readable format and executes the program. This
process can be slower than the process which
compiles the source program before execution.
The program need to be converted as well as
executed at the same time. Programs written in
languages like BASIC, Perl, Smalltalk, Lisp and VB
Script are interpreted.
3
Machine language is the native language of the computer (i.e. what is understood by the hardware).
1.4 Programming Languages
Programming languages were invented to make
programming easier. They became popular because
they are much easier to handle than machine
language. Programming languages are designed to
be both high-level and general purpose. A language
is high-level if it is independent of the underlying
hardware of a computer. It is general purpose if it
can be applied to a wide range of situations. There
are more than two thousand programming
languages and some of these languages are general
purpose while others are suitable for specific classes
of applications.
Languages such as C, C++, Java, C# and Visual
Basic can be used to develop a variety of
applications. On the other hand FORTRAN was
initially developed for numerical computing, Lisp
for artificial intelligence, Simula for simulation and
Prolog for natural language processing (yet, these
languages are general enough to be used for a
wide range of problems.
However, programs developed in 4GL generally do
not utilize resources optimally. They consume
large amount of processing power and memory
and they are generally slower than the programs
developed using languages belonging to other
generations. Most of these 4GL support
development of Graphical User Interfaces (GUIs)
and responding to events such as movement of
the mouse, clicking of mouse or pressing a key on
the keyboard.
4
Computer organization describes; the internal organization of a computer, the instruction set,
instruction format, how to make use of registers, allocate and de allocate memory, talking to various
I/O devices, etc.
5
Running the same program on machines with different hardware configurations.
1.5 Overview of C
“C’ seems a strange name for a programming
language but it is one of the most widely used
languages in the world. C was introduced by Dennis
Ritchie in 1972 at Bell Laboratories as a successor of
the language called B (Basic Combined
Programming Language – BCPL). Since C was
developed along with the UNIX operating system it
is strongly associated with UNIX. UNIX was
developed at Bell Laboratories and it was written
almost entirely in C.
For many years, C was used mainly in academic
environments. However with the release of C
compilers for commercial use and increasing
popularity of UNIX, it began to gain wide-spread
interest among computer professionals. Various
languages such as C++, Visual C++, Java and C#
have branched away from C by adding object-
orientation and GUI features. Today C compilers are
available for a number of operating systems
including all flavors of UNIX, Linux, MS-DOS,
Windows and Apple Mac
The syntax and coding style of C is simple and well
structured. Due to this reason most of the modern
languages such as C++, Java and C# inherit C
coding style. Therefore it is one of the best
languages to learn the art of programming. C is
also suitable for many complex engineering
applications.
END
THANK YOU