COMPUTER METHODS 1
LECTURE 1
Introduction
Programming Background
Introduction to Computer Hardware and Software
Introduction and History
Algorithm
Algorithm : Means to solve a problem
Antiquity : Euclid described how to find the Greatest
Common Divisor of two numbers. Archimede computed π
with an arbitrary precision.
Muhamed Ibn Al Khou Warizmi: Decimal representation and
computation rules .
Exercise : Give some examples of algorithm in your daily life.
Human vs Computer
Tedious execution of algorithm by a human being
⇒ repetitive rules
⇒ large number of steps
Computers have boosted the development of algorithmics.
2 / 19 Lecture 1 Computer Methods 1
Programming Background
Introduction to Computer Hardware and Software
Algorithms vs programs
Specification of an Algorithm
An algorithm constructs a solution from input data.
There is an automatic execution. No Ambiguity of rules
(⇒Semantics).
The input of an algorithm has to be well defined and finite.
An algorithm can be considered as a sequence of operations
on a string of symbols (Automata, Turing Machine ).
To be executed by a computer an algorithm needs to be
coded in a particular programming Language.
Programs
A program is written in a particular programming language ( C++,
C, Java, LISP, Pascal,ADA etc.) and is executed on a computer
which has a memory.
3 / 19 Lecture 1 Computer Methods 1
Programming Background
Introduction to Computer Hardware and Software
C a programming language for Engineers
Factors that influence program efficiency are
Problem being solved
Programming language
Compiler
Computer hardware
Programmer ability
Algorithm.
Why C for Engineers
C offers performance that is close to assembly language but is far
easier to develop than assembly language.
4 / 19 Lecture 1 Computer Methods 1
Programming Background
Introduction to Computer Hardware and Software
Specific Goals of the course
Introduce general concepts of programming
Present a consistent methodology for solving engineering
problems using computers
Begin to think like a programmer
Learn to appreciate Programming and Computer Science
Design and implement solutions to engineering problems in C
Clearly communicate, and concisely document intended
solutions
5 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Computer Role
Computers have become an integral part of everyday life.
Computer is used to:
Write a report
Withdraw money from an automatic teller machine
Synthesize music
Solve a set of simultaneous equations
Design a suspension bridge
Compute the orbital path of the space station
Etc.
6 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
What are the Basic operations of a computer?
Strictly speaking, it really performs very simple operations
Store and retrieve numbers
very quickly
very accurately
Add, subtract, multiply, and divide
also fast and accurate
Compare numbers (with 0)
Follow a list of instructions
jump around in the list
7 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
What about everything Else?
But problems are specify in terms of:
More complex math
Combination of atomic operations
Interaction with peripheral devices
Output: graphics cards and printers
Input: keyboards, mice, joysticks
All sorts of specialized devices
Everything done using numbers
To the computer everything is numbers
How do computers handle things that are not numbers?
8 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Basic Computer Model
9 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Components of Computer system
There are three components required for implementation of
computerized input-processing-output model:
hardware
Software : applications and system (programs)
Data
For modern computers there is a fourth component:
communication component.
10 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
A Computer Program
What is a computer program?
A sequence of processor instructions designed to achieve a
specific purpose.
The instructions are executed sequentially.
Each instruction has a numerical code
Example of instructions?
Load data (from an address in the memory)
Store data (in an address)
Add two numbers
If two numbers are equal, jump to another part of the program
Instructions are numbers!
11 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Machine Language
Computers understand only machine language.
Every processor has its own machine language.
Basically looks like a sequence of 1’s and 0’s.
Very inconvenient to work with and non intuitive.
All other computer languages were created for human convenience
The computer does not understand C.
Must be converted into machine language.
12 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Computer languages
Translation of source code to machine language
Assembly : machine language with some text codes (still
inconvenient)
Interpreted languages : Java, Perl, MATLAB
The program is translated into machine language line by line
during execution
Compiled languages : C, C++, Pascal, Fortran
The program is translated into machine language before
execution
13 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
High Level Languages vs Machine Machine Languages
14 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
C is a procedural language
High Level program specification
It enables the programmer to create new instructions (procedures) from
existing ones.
Instead of re-writing the same code over and over again, write it once and
call it when needed.
For a program written in C to run it is translated ( compiled) into a
machine code
How do we compile?
A special program , the compiler, translates from computer language to
machine language.
There are many compilers on the market.
In our class we will use GCC or Microsoft Visual C++.
The GNU Compiler Collection (GCC) is the most important piece of open
source software in the world.
15 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Programming process
Edition, Compilation, Linking and execution of a program
Write a program
Using your favorite text editor
Compile and Link the program
In our case a C compiler will be used
This compiler will do one of two following things:
print error messages and abort (most probably)
produce an executable program
Run the program
16 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Compilation
17 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
My first C program
A program that displays Hello, World! on the screen and
positions the cursor on the next line
/* HelloWorld - An example program */
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}
18 / 19 Lecture 1 Computer Methods 1
Programming Background
Computer System
Introduction to Computer Hardware and Software
Your To Do Work
1 Revisit your Electrical Design 1 notes
2 Download and install Octave on your machine and code some
few simple Matlab programmes.
19 / 19 Lecture 1 Computer Methods 1