0% found this document useful (0 votes)
270 views22 pages

Computer Programming: SECT-M1082

This document provides an overview of computer programming and key concepts: 1. It defines the main components of a computer system including hardware, software, input/output devices, memory, and processors. 2. It describes different types of computer programming languages from low-level like machine language to high-level languages. 3. It explains key programming concepts like algorithms, problem solving, program design, software life cycles, and the history and purpose of C++.

Uploaded by

ibrahim mohammed
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)
270 views22 pages

Computer Programming: SECT-M1082

This document provides an overview of computer programming and key concepts: 1. It defines the main components of a computer system including hardware, software, input/output devices, memory, and processors. 2. It describes different types of computer programming languages from low-level like machine language to high-level languages. 3. It explains key programming concepts like algorithms, problem solving, program design, software life cycles, and the history and purpose of C++.

Uploaded by

ibrahim mohammed
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/ 22

Computer Programming

SECT-M1082
Chapter 1
Introduction to Programming
SECT-M1082
1.1 Computer Systems
• A set of instructions for a computer to follow is called a
program. Personal Computer
• The collection of programs used by a computer is referred to as
the software.
• The actual physical machines that make up a computer
installation are referred to as hardware.
• There are three main classes of computers:
• PC
• Workstations
• Mainframes Workstations
• A network consists of a number of computers connected, so
they may share resources, such as printers, and may share
information.
• A network might contain a number of workstations and one or
more mainframes, as well as shared devices such as printers.

Mainframes

3
1.1 Computer Systems
Main Components of a Computer
1. Input Devices
• A device that allows a user to pass information to the computer.
Example: Keyboard, Mouse, Scanners, Microphones and etc
2. Output Devices
• Provide information from the computer to the user.
Example: Monitor, Speakers, Printer and etc
3. The Processor
• Also known as Central Processing Unit (CPU)
• It is the brain of the computer.
• It follows the instructions in a program and performs the calculations specified
by the program.
• It can add, subtract, multiply, and divide and can move things from one memory
location to another.
• It can interpret strings of zeros and ones as letters and send the letters to an
output device.
• The processor also has some primitive ability to rearrange the order of
instructions.
• Processor instructions vary somewhat from one computer to another.
• The processor of a modern computer can have as many as several hundred
available instructions.

4
Main Components of a Computer…
5. Main Memory
• Keep the program being executed.
• It is called random access because the computer can immediately
access the data in any memory location.
Example: Random Access Memory (RAM)
6. Secondary Memory or Auxiliary Memory
• Keep permanent record of information.
• It often requires sequential access, which means that the
computer must look through all (or at least very many)
memory locations until it finds the item it needs.
• A program is stored in a file in secondary storage and copied
into main memory when the program is run.
Example: Hard disks, Removable Storage and CD

5
1.1 Computer Systems
• Bit : a digit that can only be zero or one .
• A byte consists of eight binary digits ,bits, each either
zero or one.
• A computer’s main memory is divided into a series of
numbered locations called bytes.
• The number associated with one of these bytes is called
the address of the byte.
• Often several of these bytes are grouped together to
form a larger memory location. In that case, the address
of the first byte is used as the address of this larger
memory location.

6
Operating System
• Operating Systems: facilitates the communication
between a program and a computer.
• It allocates the computer’s resources to the different
tasks that the computer must accomplish.
• Some common operating systems are UNIX, DOS, Linux,
Windows, Macintosh, and VMS
• The input to a computer can be thought of as consisting
of two parts, a program and some data.
• The computer follows the instructions in a program, and
in that way, performs some process.
• The data is what we conceptualize as the input to the
program, and both the program and the data are input to
the computer through an operating system.

7
Types of Computer Programming Languages
1. Low-level Language
1.1 Machine Language
• A computer programming language consisting of
binary or hexadecimal instructions wich a computer
can respond to directly.[1]
• It is machine dependent. In other words, it is different
from machine to machine.
• The only language that computers directly
understand.
• Only programmers who build Software Compilers and
Operating Systems need to view a machine language.
• Cannot be easily understood by humans.
• It is a first-generation programming language.

8
Types of Computer Programming Languages
1. Low-level Language
1.2 Assembly Language
• English like abbreviations used to represent
elementary computer operations.
• Needs to be converted to a machine language to
execute.
• An assembler converts assembly language to machine
language.
• Generally consist of simple phrases like ADD, STORE,
and LOAD.

9
Types of Computer Programming Languages
2. High-level Language
• Resembles English language and common mathematical
notations.
• Easier for human beings to understand.
• It must be translated to machine language for the program to
execute.
• A compiler converts high-level language to machine language.
• Some of high level programming languages are C++, Python,
Java, JavaScript, Pascal, Visual Basic, FORTRAN, COBOL, Lisp,
Scheme, and Ada.

10
Linker and Compiler
• Compiler is a program that translates a high-level
language program, such as a C++ program, into a
machine-language program that the computer can
directly understand and execute.
• In the compiling process your C++ program is converted to an
object code and linked with other object codes and converted
to a machine language.
• This process of combining object code is called linking and is
done by a program called a linker.
• For simple programs, linking may be done for you
automatically .

11
1.2 Programming and Problem Solving
• Algorithms
• A sequence of precise instructions which leads to a
solution is called an algorithm.
• An algorithm is a finite sequence of well-defined,
computer-implementable instructions, typically to solve
a class of problems or to perform a computation.
• Algorithms are generally created independent of
underlying language.
• Some approximately equivalent words are 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.

12
1.2 Programming and Problem Solving
• Characteristics of Algorithms
• An algorithm should be clear and unambiguous.
• An algorithm should have one or more well-defined outputs and should match the
desired output.
• An algorithm should have 0 or well-defined set of inputs.
• An algorithm must terminate after finite number of steps.
• An algorithm should be feasible with available resource.
• An algorithm should have a step-by-step direction and should be independent of any
programming language.

13
1.2 Programming and Problem Solving
• Algorithm example
Question: Design an algorithm to add three
numbers and display the result.

• Step 1 − START
• Step 2 − declare three integers a, b, c & d
• Step 3 − get values of a, b and c from user
• Step 4 − add values of a and b
• Step 5 − store output of step 4 to d
• Step 6 − print d
• Step 7 − STOP

14
1.2 Programming and Problem Solving
Program Design
There is no complete set of rules, no algorithm to tell you how to write programs.
Program design is a creative process. Still, there is the outline of a plan to follow.
Program design is divided into two phases:
1. Problem Solving Phase
2. Implementation Phase

Problem Solving Phase


• The solution to the problem is stated in a step by step manner by sequence
of precise instructions.
• The output of this phase is an algorithm.

Implementation Phase
• The algorithm is implemented by a programming language and tested until
the intended output is achieved.

15
The Software Life Cycle
• Designers of large software systems, such as compilers and operating systems, divided the software
development process into six phases known as 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
• Maintain incase of failures and introduce changes to deployed software.
6. Obsolescence
• Being obsolete or outdated.

16
Introduction to C++
• Brief history of C++
BCPL => B => C => 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; many C++ programs are
definitely not C programs.
• Unlike C, C++ has facilities to do object-oriented
programming.

Bjarne Stroustrup
17
Layout of a Simple C++ Program
#include < >
- is called include directive.
- It tells the compiler where to find information about
certain items that are used in your program.
#include <iostream>
- In this case 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; iostream is a file that
contains some basic information about this library.
- The linker program that we discussed earlier in this
chapter combines the object code for the library iostream
and the object code for the program you write.

18
Layout of a Simple 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.

19
A Sample C++ Program

20
Testing and Debugging

• A mistake in a program is usually called a bug.


• The process of eliminating bugs is called debugging.
• Kinds of program errors:
1. 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.
2. Runtime Errors
• Errors that are detected by the computer when the program is run.
Example: Zero division error
3. Logical Errors
• A mistake made by a programmer during the development.
• It is not detected both by the computer and a compiler.
• To avoid logical errors programming carefully and testing the program with different data sets is
preferable.
Example: Accidentally using * instead of + to add two numbers

21
Thank you!

22

You might also like