You are on page 1of 27

IPE 115, Semester 2 Lecture 1

Introduction
What is a Computer? Up until the late 1940s, a Computer was a person who performed calculations. What about now?
Programs Programs are sequence of step by step instructions to the computer Programs, and the data values processed by programs, are called software.

Programming languages
Low-Level Programming Languages Machine language Assembly language
High-Level Programming Languages Instructions look more like English and Math Generally result in multiple low level commands, for a single high level statement.

Machine Language
Used by early computers Executable by machines, almost incomprehensible to

humans Programming in machine language is very tedious and prone to errors


Ex:

11001010000100101000010101110100 11000101010001110010101000110010

Assembly Language
Mnemonics used for instruction codes and memory locations Not directly understandable by machine. They must be translated Easier for humans to use and still in use today. Ex:

ADD X, Y, Reg1 ADD Reg1, Z, Reg2 STORE Reg2 SUM


5

High Level Programming Language


Uses syntax resembling combination of

mathematical notation and English Easy for humans to understand. Not understandable by machines, must be translated using a compiler or an interpreter. Programming tools such as integrated programming environment with a debugger are available to aid in programming process.

High Level Programming Languages


Pascal FORTRAN COBOL C C++ Ada PL/1

RESULT := X + Y+ Z; RESULT = X + Y + Z COMPUTE RESULT = X + Y + Z. RESULT = X + Y + Z; RESULT = X + Y + Z; RESULT := X + Y + Z; RESULT = X + Y + Z;

Programming Language Translation


Source Program Translator Program Object Code

Assemblers Interpreters

Compilers

Program Language Translation


Assemblers
Translate statement from assembly language to machine

language Generally use table look-up techniques

Interpreters
Translate and execute each high-level statement, one at a

time

Program Language Translation


Compilers
Translate the entire high level language program, called

the source code, to machine language and store the result. Machine language code produced by compilers is called object code

10

Programming Paradigms
Procedural Paradigm

Object-Oriented Paradigm

11

System Software
Operating System
Memory and resource management Job scheduling Security

Command Line vs. Graphical User Interface


Note: the vi editor

12

Problem Solving and Software Development


Development and Design

Analyze the problem Develop a solution Code the solution Test and debug

Documentation
Internal documentation Comments Notes to the reader of the program Identifiers should represent the information they hold or the task they define. External documentation Users manual Test plan Design document

Maintenance
Correcting new problems Adding new features Modifications due to change in requirements
13

Algorithms
An Algorithm is a step by step sequence of

instructions.
It must be unambiguous It must be doable Each step must terminate, and the entire

algorithm must terminate

Expressions of Algorithms are


Pseudo code
Flowcharts

14

Example of Algorithm
Write an algorithm that will determine the largest value of four values.

15

A flowchart solution
INPUT first value, STORE value

start
Count =0

in Largest. Loop to determine if any other numbers are larger. DISPLAY Largest.

Input number Largest = number


FALSE

count < 3
TRUE

Input Number
TRUE

Print The Largest is Largest

Number > Largest


TRUE

end

Largest = number Count = Count +1

FALSE

16

A pseudocode solution
INPUT first value, STORE value in Largest Repeat three times INPUT next value, store in Number IF Number >Largest,

STORE Number in Largest

DISPLAY largest

17

Control Structures
Sequence
Execute sequence of statements in order given.
This is the default control structure.

Selection
Select between alternative paths.

Iteration
Repeat a statement or collection of statements over

and over again.

Invocation
Execute a complex task, which is written separately

18

First C++ Program


//File: welcome.cpp //A program to print a welcoming message
#include <iostream> using namespace std; int main() { cout << Welcome to SLIIT << endl; return 0; } //main

19

First C++ Program


Note the following: The include file is iostream Therefore no .h in the header The use of using namespace std will be discussed later The main() function has a return value The use of cout for outputting to the monitor The use of endl for new line.

20

// File: welcome.cpp // A program to print a welcoming message


Comments provide information to the people who read the program. Comments are removed by the preprocessor, therefore the compiler ignores them. In C++ there are two types of comments Line comments Delimited comments

21

More on Comments
Line comments begin with // and continue for the rest

of the line.
Delimited comments begin with /* and end with */ Only delimited comments can be used in C.

22

Preprocessor Command
#include <iostream>
When using classes or functions that are stored in different files from the one you are writing, include the header file for those classes. The header file containing the class needed for the object cout is iostream.h
#include <iostream>

23

Preprocessor Command
using namespace std;
The keyword namespace is used to define a scope. std is a namespace that is defined by C++. The object cout is part of the scope defined by std To access the object cout, you need to type std::cout The directive/keyword using is used to simplify the access.
24

cout <<Welcome to SLIIT << endl;


Produces output:

Welcome to SLIIT -

cout is an object which displays whatever is to it on the screen. << is the insertion operator used to send information to cout

sent

25

Free Format
A language has free format if statements can appear anywhere on one or several lines. Blank lines are ignored. Extra spaces are ignored. Multiple statements can be placed on the same line. Statements can be broken over more than one line anywhere other than in the middle of a string

literal, operator, or identifier.

26

Program Style
Use blank lines to separate parts of the program. Use indentation to align curly braces and match the opening and closing braces by placing them under each other. Note: When using the vi editor, use 3 spaces for every indentation. Use blank spaces to separate the parts of a statement to make it easier to read.
27

You might also like