CHAPTER 1: Programming Fundamentals: Cseb113 Principles of Programming
CHAPTER 1: Programming Fundamentals: Cseb113 Principles of Programming
Fundamentals
CSEB113 PRINCIPLES of
PROGRAMMING
by
Badariah Solemon
BS (May 2013) 1
Topics
1. Computer Programs and Programming
Introduction
Why Do Engineering Undergraduates Need to Take
Programming Course?
2. Programming Languages
Machine Language ; Assembly Language; High-level
Language
3. The C Language
Your first C Program
C Programming Environment
BS (May 2013) 2
Topic 1
COMPUTER PROGRAMS AND
PROGRAMMING
BS (May 2013) 3
Elements of a Computer
3
2
Application
1 software
4 5
2
1
system
software
Hardware Software
BS (May 2013) 4
Computer and Software
Computers can do a lot of exciting tasks.
However, computers must be given instructions in the form of
computer programs before they can perform actions and make
decisions.
Software/program a set of instructions stored inside a
computer that allows the user to do a particular thing.
BS (May 2013) 6
What is Programming?
Computer programming is:
not only about writing computer programs
the iterative process of designing, writing, testing,
debugging, and maintaining the source code of
computer programs
This source code is written in one or more
programming languages (such as C, C++, C#, Java,
Python, Smalltalk, etc.)
often shortened to programming,
scripting, or coding
BS (May 2013) 7
Why Should I Know
Programming?
Everybody in this country should learn how
to program a computer because it teaches
you how to think Steve Jobs
Watch Me
Source: http://www.youtube.com/watch?v=sGyH9tBie4M
BS (May 2013) 8
Why Take Programming
Course?
Programming is not only for computer science people only.
Writing computer programs to solve complicated engineering
problems and to control mechanical devices is a basic skill all
engineers must master.
Introductory programming course isn't trying to teach you to
program so that you can be a programmer.
Instead, such course just want you to think like programmers
because in the future you will run into problems that are too
long and complex to do by hand.
In those cases, you'll have to use MATLAB or Mapple or mathworks or some other
math related application that allows you to solve these problems.
Unfortunately, if you can't code your problem into the application, it won't do you
any good.
BS (May 2013) 9
Topic 2
PROGRAMMING LANGUAGES
BS (May 2013) 10
What is a Programming
Language?1
Technically, it is an artificial language designed to
communicate instructions to, or to control the
behavior of a machine, particularly a computer.
It is different from our everyday-language (natural
language -NL)
NL : Depends on circumstances; the context one word
can have many meaning depending on the situation (e.g.,
OPERATE)
PL: Very specific (one word means one thing context
free) since to 'talk' to a computer; to instruct a computer;
our commands must be 100% clear and correct.
BS (May 2013) 11
What is a Programming
Language?2
Conceptually, programming language is a
framework within which we organize our ideas
about data and procedures.
Data: 'objects' or things we want to manipulate
Procedures: 'descriptions' or 'rules' or
processes that define how to manipulate data
Example:
A simple program that determine sum of two numbers
Data ?
Procedures?
BS (May 2013) 12
Types of Programming
Languages
printf (Hello);
High-Level total = quiz + assignment;
Language printf(Total = %d, total);
Assembly LOAD
LOAD A,A, 9999
9999
LOAD
LOAD B,B, 8282
8282
Language SUB
SUB BB
MOV
MOV C,
C, AA
BS (May 2013) 13
1. Machine Language
The only language that is directly understandable by a computers
processor.
Certainly difficult for humans to understand
Consists of binary codes: 0 and 1.
Example: 1101 0001 1000 0101 1000 0110 1111 0001
0100 1100 0101 1110 0101 1010 0001 1100
is the language into which all programs must be converted before
they can be run
is generally machine dependent, as it varies from processor to
processor (e.g., Intel, AMD and ARM processors)
is NOT portable
program may sometimes have to be completely rewritten to work on
different type of processors
Programming in machine language is very slow and tedious since it
is hard to memorize all the instructions and mistakes can happen
very easily
BS (May 2013) 14
2. Assembly Language
Uses a mnemonic code to represent each machine operation
LOAD A, 9999
in words and numbers LOAD B, 8282
SUB B
MOV C, A
BS (May 2013) 15
3. High-level Languages1
Use more English words so easier to program in these languages.
Example:
printf (Hello);
total = quiz + test + assignment;
BS (May 2013) 16
3. High-level Languages2
Example:
C PHP Ruby Ada
Java Visual Basic Visual Basic.NET MATLAB
Objective-C Python LISP Lua
C++ Perl Pascal Bash
C# Javascript Delphi FORTRAN
BS (May 2013) 17
Topic 3
THE C LANGUAGE
BS (May 2013) 18
The C Language1
It was developed by Dennis Ritchie in the early 1970s
at Bell Laboratories (now a part of Lucent
Technologies, Inc).
A high-level language that is highly portable.
C combines the power of high-level languages with
the power of assembly languages.
It has influenced the newly created high-level
language name Objective-C
which is the main programming language used by Apple
for the OS X and iOS operating systems and their
respective APIs, Cocoa and Cocoa Touch frameworks.
BS (May 2013) 19
The C Language2
C is a highly imperative programming language. This
means:
It expresses what the program should accomplish by
prescribing how to do it in terms of sequences of actions
to be taken.
It was designed to be compiled using a relatively
straightforward compiler.
The language has become available on a very wide
range of platforms, from embedded microcontrollers
to supercomputers.
BS (May 2013) 20
Your First C Program
A C program (also called C source code):
/**********************************************************
Author: Badariah Solemon
Date: 01/01/2013
Description: A program that prints the famous
Hello World message on the computer screen
**********************************************************/
#include <stdio.h>
void main (void)
{
printf(****************\n);
printf( Hello World\n);
printf(****************\n);
}
BS (May 2013) 21
C Programming
Environment
A modern C programming often made easy by the use of
integrated development environments (IDEs).
IDEs that support C language include Microsoft Visual Studio,
Eclipse, and etc.
Ms Visual Studio 2010 Express or Ms Visual Studio Express
2012 is free!
Highly recommended for your personal use
You must register to obtain a free product key for ongoing use
BS (May 2013) 22
Visual Studio C++ Express
BS (May 2013) 23
Summary
Computers must be given instructions in the form of computer programs
before they can perform actions and make decisions.
Programming is the iterative process of designing, writing, testing,
debugging, and maintaining the source code of computer programs.
Conceptually, programming language is a framework within which we
organize our ideas about data (object we want to manipulate) and
procedures (how to manipulate the data).
In general, programming languages may be categorized as 1) machine
language (also called machine code), 2) assembly language, and 3) high-
level languages.
C is a highly imperative programming language.
A modern C programming often made easy by the use of integrated
development environments (IDEs).
BS (May 2013) 24