0% found this document useful (0 votes)
8 views18 pages

Lecture 1

The document provides an introduction to computer programming, covering key concepts such as computer systems, types of programming languages, and the software life cycle. It explains the roles of hardware and software, the distinction between machine language, assembly language, and high-level languages, and introduces object-oriented programming principles. Additionally, it discusses the phases of program design, testing, and debugging processes.

Uploaded by

samy2mexa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views18 pages

Lecture 1

The document provides an introduction to computer programming, covering key concepts such as computer systems, types of programming languages, and the software life cycle. It explains the roles of hardware and software, the distinction between machine language, assembly language, and high-level languages, and introduces object-oriented programming principles. Additionally, it discusses the phases of program design, testing, and debugging processes.

Uploaded by

samy2mexa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Introduction to Computer

programming
1.1 Computer systems
• Computer
• hardware : actual physical machines
• Software : collection of programs used by a computer
• Program : set of instructions for a computer to follow
Computer systems …
• Bit : a digit that can only be zero or one
• Bytes :
• eight binary digits or bits
• computer’s main memory is divided into a series of numbered locations
• Address of the byte :
• the number associated with one of these bytes
• Often these bytes are grouped to form a larger memory location.
• address of first byte is used as address of the larger memory location
Computer systems …

• Operating system allocates computer’s resources to the different tasks


• Common OS are UNIX, DOS, Linux, Windows, Mac OS and VMS.

• Data is what we conceptualize as the input to the program.


• For example: a program that adds two numbers has two number as data.

• The program and the data are input to the computer via the operating system.
Types of computer languages
1) Machine Language (ML)
- The only language computers directly understand

- “natural language” of computer

- defined by hardware design

- Machine – dependent

- Generally consist of strings of numbers

- 1’s and 0’s

- Cumbersome for humans


Types of computer languages …
2. Assembly Language
- English like abbreviations used to represent elementary computer operations

- clearer to humans

- incomprehensible to computers

- converted to machine language using assembler

- Generally consist of simple phrases like:

- ADD

- STORE

- LOAD
Types of computer languages …
3 . High- level Language (HLL)
- similar to everyday English and use common mathematical notations

- single statement will accomplish a certain task

- Assembly language will require many instruction to accomplish a task.

- incomprehensible to computers

- converted to machine language using compiler

- Examples of high-level language :

- C++

- Java

- Python … etc
Compiler and linker

• Compiler: a program that translates a HLL program into a ML program

• Linker: a program that does the process of linking

• combines object codes of different routines.

• e.g. combining your object code with input and output routines that your program uses

• For simple programs, linking may be done automatically .


Programming and problem solving
• Algorithms:

• a sequence of precise instructions which leads to a solution

• a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to

perform a computation.

• Like a recipe, method, directions, procedure, and routine.

• To qualify as an algorithm, a set of instructions must

• Completely and unambiguously specify the steps to be taken.

• Specify the order in which they are taken.


Program design
• Program design is devided into two phases:

• Problem Solving Phase

• The solution to the problem is stated in a step by step manner

• Sequence of precise instructions

• Output is an algorithm

• Implementation Phase

• The algorithm is implemented by a programming language


Object oriented programming
• A program is viewed as a collection of interacting objects.

• Consists of designing the objects and the algorithms they use.

• The main characteristics of OOP are:

• Encapsulation:

• Hiding or abstraction of the detailed implementation for simplification of description.

• Inheritance

• Making a code reusable again for objects having the same behavior and properties.

• Polymorphism

• Having a single name but multiple behaviours incase of inheritance


The software life cycle
The six phases of this life cycle are:

1. Analysis and specification of the task (problem definition)

2. Design of the software (object and algorithm design)

3. Implementation (coding)

4. Testing

5. Maintenance and evolution of the system

6. Obsolescence
Introduction to c++
• Bjarne Stroustrup of AT&T Bell Laboratories developed C++ in the early 1980s.

• Stroustrup designed C++ to be a better C.

• Most of C is a subset of C++, and so most C programs are also C++ programs.

• The reverse is not true;

• Unlike C, C++ has facilities to do object-oriented programming.


A sample c++ program
#include <….>
-The include directive.

-It tells the compiler where to find information about certain items that are used in your program.

#include <iostream>
-iostream is the name of a library that contains the definitions of the routines that handle input from the keyboard

and output to the screen

-The linker program combines the object code for the library iostream and the object code for the program you write.
A sample c++ program ….
#using namespace std;
-the names defined in iostream are to be interpreted in the “standard way”
-std is an abbreviation of standard

int main( ){ }
-Specifies that the program starts executing here.
-The curly brace shows the start and end of the body of the main part.

return 0;
-It is called a return statement.
-It tells the program to end the execution.
A sample c++ program
Testing and debugging
• A Bug: a mistake in a program.

• Debugging : the process of eliminating bugs

• Kinds of program errors:

• Syntax Errors

• Occur by the violation of the syntax (grammar).

• The compiler tells you that your program contains a syntax error.

• Example: Missing a closing curly brace.


Testing and debugging

• Runtime Errors
• Errors that are detected by the computer when the program runs.

• Example: Division by Zero error

• Logical Errors
• A mistake made by a programmer during the development.

• It is not detected both by the computer and a compiler.

• Example: Accidentally using * instead of + to add two numbers

• To avoid logical errors programming carefully and testing the program with different
data sets is preferable.

You might also like