0% found this document useful (0 votes)
47 views20 pages

AU Chapter 1

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

AU Chapter 1

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

Computer Programming with C++

1
Chapter one
Introduction
 Computer Architecture Basics
 Hardware and Software
 Program Development
 Algorithms and flow chart

2
What is a Computer?
• Computer
– Device capable of performing computations and making
logical decisions
• Hardware
– Various devices comprising computer Keyboard, screen,
mouse, disks, memory, CD-ROM, processing units, …
• Software
– Instructions to command computer to perform actions and
make decisions
• Computer programs
– Sets of instructions that control computer’s processing of data
– instructions that tells the computer what to do.
• Computer programming
– is the process of writing, testing, debugging/troubleshooting,
and maintaining the source code of computer programs. 3
Computer Architecture Basics

Six logical units of computer


1. Input unit
• “Receiving” section
• Obtains information from input devices
– Keyboard, mouse, microphone, scanner……
2. Output unit
• “Shipping” section
• Takes information processed by computer
• Places information on output devices
– Screen, printer…
– Information used to control other devices
3. Memory unit
• Rapid access, relatively low capacity “warehouse” section
• Retains information from input unit
– Immediately available for processing
• Retains processed information
– Until placed on output devices
• Memory, primary memory 4
4. Arithmetic and logic unit (ALU)
• “Manufacturing” section
• Performs arithmetic calculations and logic decisions
5. Central processing unit (CPU)
• “Administrative” section
• Supervises and coordinates other sections of computer
6. Secondary storage unit
• Long-term, high-capacity “warehouse” section
• Storage
– Inactive programs or data
• Secondary storage devices
– Disks
• Longer to access than primary memory
• Less expensive per unit than primary memory

5
Programming language
• is an artificial language that can be used to control the behavior of
a machine, particularly a computer.

 computers do exactly what they are told to do, and cannot


understand the code the programmer "intended" to write.

Programming languages can be divided in to two major categories:


• low-level languages
• Machine Languages
• Assembly Languages
• high-level languages.

6
1. Machine language
• Only language computer directly understands
• “Natural language” of computer i.e computer easily understood
these programs
• Defined by hardware design
Machine-dependent
• Generally, consist of strings of numbers: Ultimately 0s and 1s
• Instruct computers to perform elementary operations One at a
time
• Cumbersome for humans
Example:
+1300042774
+1400593419

7
2. Assembly languages
• English-like abbreviations representing elementary computer
operations
• Clearer to humans
• Incomprehensible to computers i.e not able to be understood
by computers
• Translator programs (assemblers) Convert to machine
language
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
ADD A, B – adds two numbers in memory location A and B

8
3. High-level languages
• Similar to everyday English, use common mathematical
notations
• Single statements accomplish substantial tasks
• Assembly language requires many instructions to
accomplish simple tasks
• Translator programs (compilers)
• Convert to machine language
• Interpreter programs
• Directly execute high-level language programs
• Example:
grossPay = basePay + overTimePay

FORTRAN (FORmula TRANslator), BASIC (Beginner's All-purpose


Symbolic Instruction Code), PASCAL, C, C++, Java are some
examples of high-level languages.

9
Programming languages: by programming paradigm (programmer's view of
code execution ) can be categorized into three most influential
paradigms(Chronological order)
• Procedural Programming Languages
• Structural Programming Languages
• Object-oriented Programming Languages
1. Procedural Programming Languages
• specifies a list of operations that the program must complete to reach the
desired state.
• Each program has a starting state, a list of operations to complete, and an
ending point.
• Procedures, also known as functions, subroutines, or methods, are small
sections of code that perform a particular function . 10
2. Structured Programming Languages
• Disciplined approach to writing programs
• Clear, easy to test and debug, and easy to modify
• is a special type of procedural programming.
• requires that programmers break program structure into small pieces
of code that are easily understood.
• One of the well-known features of structural programming is that it
does not allow the use of the GOTO statement.
• It is often associated with a "top-down" approach to design.

11
3. Object-Oriented Programming Languages
• is one the newest and most powerful paradigms
• the designer specifies both the data structures and the types of
operations that can be applied to those data structures.
• This pairing of a piece of data with the operations that can be
performed on it is known as an object.
• A program thus becomes a collection of cooperating objects, rather
than a list of instructions.
• Objects can store state information and interact with other objects, but
generally each object has a distinct, limited role.
• More understandable, better organized and easier to maintain

12
Problem solving Techniques

In computer programming two facts are given more weight:


• The first part focuses on defining the problem and logical
procedures to follow in solving it.
• The second introduces the means by which programmers
communicate those procedures to the computer system so that it
can be executed.
• The procedure, or solution, selected is referred to as an algorithm.
• An algorithm is defined as a step-by-step sequence of instructions
that must terminate and describe how the data is to be processed to
produce the desired outputs.
• There are three commonly used tools to help to document program
logic (the algorithm). These are :
• Pseudo code.
• Structured chart, and
• Flowcharts
13
Pseudocode

Pseudocode (derived from pseudo and code) is a compact and informal


high-level description of a computer algorithm that uses the structural
conventions of programming languages, but typically omits details such
as subroutines, variables declarations and system-specific syntax.

Example:
Original Program Specification:

Write a program that obtains two integer numbers from the user. It
will print out the sum of those numbers.
Pseudocode:
Prompt the user to enter the first integer
Prompt the user to enter a second integer
Compute the sum of the two user inputs
Display an output prompt that explains the answer as the sum
Display the result 14
Structured Charts
• Structured chart depicts the logical functions to the solution of the
problem using a chart.
• It provides an overview that confirms the solution to the problem
without excessive consideration to detail. It is high-level in nature.
Example: Write a program that asks the user to enter a temperature
reading in centigrade and then prints the equivalent Fahrenheit value.
Input Process Output

Centigrade  Prompt for centigrade value Fahrenheit

 Read centigrade value


 Compute Fahrenheit value
 Display Fahrenheit value

15
Flowchart
• is a schematic representation of an algorithm or a process.
• it doesn’t depend on any particular programming language, so that it
can use, to translate an algorithm to more than one programming
language.
• uses different symbols (geometrical shapes) to represent different
processes. The following table shows some of the common symbols.

16
Example 1: - Draw flow chart of an algorithm to add
•The flow chart is
two numbers and display their result.
Start
Algorithm description
Read A,B
• Read the rules of the two numbers (A and B)
• Add A and B C=A+B
• Assign the sum of A and B to C
• Print C
Display the result ( c)
17
End
Example 2: Write an algorithm description and draw a flow chart to
check a number is negative or not.

Algorithm description.

1/ Read a number x
2/ If x is less than zero write a message negative
else write a message not negative
Start

Read X

Write not X<0 Print message


negative Write negative

18
Stop
19
20

You might also like