You are on page 1of 15

Chapter 1: Introduction to Computers and

Topics Programming
1.1 What is Computer & its applications?
1.2 Why Program? Computer Programming
1.3 Computer Systems: Hardware and Software
for Manufacturing Engineering 2nd
1.4 Programs and Programming Languages
year
1.5 Software development phases
1.6 Software development Process by Gebriye E.
1.7 Programming Languages Computer Science Department
1.8 C++ Program Compilation process

Gebriye Embafresu Computer Science Department 1-2

1.1.1 Application of Computer 1.1 Why is Computer & it application?


Think about some of the different ways people use Computer – Computer is an advanced electronic device
Computers in School, at Home and Work? that takes raw data as an input from the user and
processes it under the control of a set of instructions
In School: Students use Computers for tasks such as (called program), produces a result (output), and saves it
➢ Writing papers for future use.
➢ Searching for articles Data is anything that can be recorded.
➢ Sending emails Data can be anything like marks obtained by you in various
courses, video, audio, image, etc.
➢ and participating in online classes

Gebriye Embafresu Computer Science Department 1-4 Gebriye Embafresu Computer Science Department 1-3
1.1.1 Application of Computer… 1.1.1 Application of Computer…
At Home: People use Computers for tasks such as At Work: People use Computers
➢ Paying bills ➢ To analyze data
➢ Shopping online ➢ Make presentations
➢ Social networking (Facebook, imo, telegram, ➢ Make business transactions
twitter, YouTube) ➢ Communicate with customers and coworkers
➢ and playing games ➢ Control machines in manufacturing facilities and
SO, the use Computers are almost limitless in our do many other things.
everyday lives, because they are programmable.

Gebriye Embafresu Computer Science Department 1-6 Gebriye Embafresu Computer Science Department 1-5

1.3 Computer Systems: Hardware and


Software 1.2 Why Program?
Computer System– is the combination of Computer – programmable machine designed to
hardware, software and data which are used to follow instructions
solve the problem of human beings. Program/Software –is a set of instructions that
A typical computer system consists of the following a computer follows to perform a task.
major components:
Programmer/Software Developer – is person
1. Central Processing Unit (CPU) with the right skills who designs, creates, and
2. Main memory (RAM) tests programs for computers
3. Secondary storage devices
SO, without programmers, no programs; without
4. Input Devices
programs, the computer cannot do anything
5. Output Devices
Gebriye Embafresu Computer Science Department 1-8 Gebriye Embafresu Computer Science Department 1-7
1.3 Computer Systems: Hardware and
Main Hardware Component Categories Software…
Hardware – refers to the Physical components of
a computer.
Computer hardware is the collection of all
the parts you can physically touch.
Computer software, on the other hand, is not
something you can touch. Software is a set of
instructions for a computer to perform specific
operations. You need both hardware and
software for a computer system to work.

Gebriye Embafresu Computer Science Department 1-10 Gebriye Embafresu Computer Science Department 1-9

Secondary Storage Main Memory


• Holds both program instructions and data
• Holds data when the program is not
running or when the computer is • Volatile – erased when the program
turned off terminates or computer is turned off

• Several forms of secondary storage • Also called Random Access Memory


– disk drive: can be mounted inside the (RAM), because the CPU can access data
computer or connected to an external port. and instructions from any memory
Data is stored magnetically location.
– optical: CD or DVD drive
– flash: USB flash drive
Gebriye Embafresu Computer Science Department 1-12 Gebriye Embafresu Computer Science Department 1-11
Output Devices Input Devices

• Used to send information to the


computer from outside
• Used to send information from the
computer to the outside • Many devices can provide input
– keyboard, mouse, touch screen,
• Many devices can be used for output microphone, scanner, digital camera, disk
– Computer screen, printer, speakers, disk drive, CD/DVD drive, USB flash drive
drive, CD/DVD recorder, USB flash drive

Gebriye Embafresu Computer Science Department 1-14 Gebriye Embafresu Computer Science Department 1-13

1.4 Programs and Programming Software Programs That Run on a


Languages Computer
• Program • System software
– programs that manage the computer hardware and the
is a set of instructions a computer follows in programs that run on the computer
order to solve a problem or perform a task – Operating Systems
• Controls the operation of the computer
• Programming Language • Manages connected devices and access to storage devices
• Allows programs to run
is a special language used to write Computer – Utility Programs
programs • Support programs that enhance computer operations
• Examples: virus scanners, data backup, file compression
– Software development tools
• Used by programmers to create software
• Examples: compilers, integrated development environments
(IDEs)

Gebriye Embafresu Computer Science Department 1-16 Gebriye Embafresu Computer Science Department 1-15
Example Program 1.4.1 What Is a Program Made Of?
#include <iostream>
using namespace std; There are common elements in most
programming languages
int main()
{ 1) Language elements:
double num1 = 5, – Key Words
num2, sum; – Programmer-Defined Identifiers
num2 = 12;
– Operators
sum = num1 + num2; – Punctuation
cout << "The sum is " << sum; – Syntax
return 0;
}
Gebriye Embafresu Computer Science Department 1-18 Gebriye Embafresu Computer Science Department 1-17

Programmer-Defined Identifiers Key Words


• Names made up by the programmer • Also known as reserved words
• Not part of the C++ language • Have a special meaning in C++
• Used to represent various things, such as • Can not be used for another purpose
variables (memory locations) • Written using lowercase letters
• Example in program (shown in green): • Examples in program (shown in green):
double num1 using namespace std;
int main()

Gebriye Embafresu Computer Science Department 1-20 Gebriye Embafresu Computer Science Department 1-19
Punctuation Operators
• Characters that mark the end of a • Used to perform operations on data
statement, or that separate items in a list • Many types of operators
• Example in program (shown in green): – Arithmetic: +, -, *, /
double num1 = 5, – Assignment: =
num2, sum;
num2 = 12; • Examples in program (shown in green):
num2 = 12;
sum = num1 + num2;

Gebriye Embafresu Computer Science Department 1-22 Gebriye Embafresu Computer Science Department 1-21

Lines vs. Statements Lines vs. Statements


In a source file, In a source file,
A statement is an instruction to the computer to A line is all of the characters entered before a
perform an action. carriage return.
A statement may contain keywords, operators, Blank lines improve the readability of a
programmer-defined identifiers, and program.
punctuation.
Here are four sample lines. Line 3 is blank:
A statement may fit on one line, or it may
occupy multiple lines. 1. double num1 = 5, num2, sum;
2. num2 = 12;
Here is a single statement that uses two lines: 3.
double num1 = 5, 4. sum = num1 + num2;
num2, sum;
Gebriye Embafresu Computer Science Department 1-24 Gebriye Embafresu Computer Science Department 1-23
Variables Syntax
• A variable is a named location in computer memory.
• Rules that must be followed when constructing a
• It holds a piece of data. The data that it holds may
program.
change while the program is running.
• Syntax dictates how keywords and operators may
• The name of the variable should reflect its purpose
be used, and where punctuation symbols must
• A variable must be defined before it can be used. appear.
Variable definitions indicate the variable name and the
type of data that it can hold.
• Example variable definition:
double num1;

Gebriye Embafresu Computer Science Department 1-26 Gebriye Embafresu Computer Science Department 1-25

1. Requirements Specification 1.5 SOFTWARE DEVELOPMENT PHASES


• Software development method is a method of developing
• Consists of understanding exactly computer programs to solve problems using a computer.
– what the problem is, • The software development method consists of
– what is needed to solve it, the following steps:
– what the solution should provide, and
– if there are constraints and conditions.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
3. Design
• The next step is to design a method of solution 2. Analysis
for the problem. – In the analysis phase we should identify the
• A method of solution is also called algorithm following:
• Algorithm is a series of steps to be performed • Inputs to the problem, their form, and the input
media to be used
in a specific logical order.
• Outputs expected from the solution, their form,
• Algorithm can be designed by using either: and the output media to be used
– Pseudo codes or • Any special constraints or conditions
– Flow charts • Formulas or equations to be used

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

5. Testing and Verification 4. Implementation


• Check the correctness of the program and verify that • Translate each step of the algorithm into a language
the program will do what is expected to do. statement.
• Program Verification • Ends up with a computer program.
– is the process of ensuring that a program meets user • A computer program is a sequence of a finite number
requirements. One of the techniques that can be used for of statements expressed in a programming language in
program verification is Program Testing.
a specific logical order that, when executed, produce
• Program Testing the solution for a problem.
– is the process of executing a program to demonstrate its
correctness. • This phase consists of
– choosing the appropriate programming language and
• A program must be tested using a sufficiently large
– writing a program following the syntax of the language exactly.
sample of test data sets such that every logical path in
the program is traversed at least once.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
6. Program Documentation • Testing the program consists of :
• Prepare documents that explain
– how the program works and
– Desk-checking- is simply reading through, or
– how to use it. checking the program to make sure that it is
• Program documentation consists of these elements: free of errors and that the logic works
– A concise requirements specification. – Debugging the program- means to detect,
– Descriptions of problem inputs, expected outputs, constraints, locate and remove all errors in a computer
and applicable formula
– A pseudocode or flowchart for its algorithm.
program
– A source program listing. – Run real-world data
– A hard copy of a sample test runs of the program. • Testing the program with real data and real users
– A user’s guide explaining to non programmer users how the • It is also advisable to test it with faulty or
program should be used.
incomplete or overwhelming data

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

Pseudo coding and Flowcharting


1.6 Software Development Process
Pseudo coding: • Algorithm:
• Pseudocode is a semiformal, English-like language with a
limited vocabulary that can be used to design and – is a sequence of a finite number of steps
describe algorithms.
• A pseudocode language is a more appropriate algorithm arranged in a specific logical order which is
description language than any programming language. used to develop the solution for a problem
• A pseudocode can be used for:
– is a set of well-defined steps to performing a
– Designing algorithms task or to solving a problem
– Communicating algorithms to users – Order is important. Steps must be performed
– Debugging logic errors in program sequentially
– Documenting programs for future maintenance and • Pseudocodes and flowcharts can be used
expansion purposes to develop algorithms.
Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
• Flowcharting:
A flowchart is a diagram that shows the logical flow of a
program.
The geometrical shapes in a flowchart represent the types of
statements in an algorithm.
– The details of statements are written inside the shapes.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

Examples… Examples
4 . Wait for the user to enter an hourly pay rate . • suppose we want the computer to calculate
Once the user enters a number, store it in memory someone's gross pay. Here is a list of things the
computer might do:
5 . Multiply the number of hours by the amount 1. Display a message on the screen asking "How
paid per hour, and store the result in memory many hours did you work?"
2. Wait for the user to enter the number of hours
6. Display a message on the screen that tells the worked . Once the user enters a
amount of money earned. The message must number, store it in memory.
include the result of the calculation performed in 3. Display a message on the screen asking "How
step 5 much do you get paid per hour?"

Gebriye Embafresu Computer Science Department 1-40 Gebriye Embafresu Computer Science Department 1-39
Examples
• Example:1 The following set of instructions forms
a detailed algorithm in pseudo code for
calculating the payment of person.
• Input the three values into the variables Name,
Hours, Rate.
• Calculate Pay = Hours ´ Rate.
• Display Name and Pay.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

1.7 PROGRAMMING LANGUAGES


• Early programming languages were
designed for specific kinds of tasks.
• Modern languages are more general-
purpose.
• In any case, each language has its own
characteristics, vocabulary, and syntax.
• Many programming languages have some
form of written specification of their syntax
(form) and semantics (meaning).
Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
1. Low-level languages
1.8 Types of Programming Languages
• used for communication with computer
hardware directly. • There is only one programming language
• Not very easy for a person to read. that any computer can actually understand
• Machine language and assembly and execute:
languages are low level programs – its own native binary machine language.
• All other languages are said to be high
level or low level according to how closely
they can be said to resemble machine
code.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

Characteristics of LOW Level Languages: 1. Low-level languages…


• They allow instructions to be written at
• They are machine oriented: the hardware level.
– an assembly language program written for • Thus, a program written in a low-level
one machine will not work on any other language can be
type of machine unless they happen to use – extremely efficient,
the same processor chip. – making optimum use of both computer
memory and processing time.
• The program becomes long and time- • However, to write a low-level program
consuming to create. needs
– Each assembly language statement – a substantial amount of time,
generally translates into one machine – as well as a clear understanding of the inner
workings of the processor itself.
code instruction,

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
Characteristics of HIGH Level Languages: 2. High-level languages
• They are not machine oriented:
– they are portable, meaning that a program written for one • They permit faster development of large
machine will run on any other machine for which the appropriate
compiler or interpreter is available. programs.
• They are problem oriented:
– most high level languages have structures and facilities • The final program as executed by the
appropriate to a particular use or type of problem.
– For example, FORTRAN was developed for use in solving computer is not as efficient.
mathematical problems. Some languages, such as PASCAL
were developed as general-purpose languages. • closer to human language
• Statements in high-level languages usually resemble
English sentences or mathematical expressions Eg. BASIC, COBOL, FORTRAN, C, C++, C#,
– they tend to be easier to learn and understand than
assembly language. JAVA, JavaScript, Pascal
• Each statement in a high level language will be
translated into several machine code instructions.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

… C++ PROGRAM COMPILATION 1.9 C++ PROGRAM COMPILATION


• During the first phase of this process, • When a C++ program is written, it must be typed
– a program called the preprocessor reads the into the computer and saved to a file.
source code. – A text editor, which is similar to a word processing
program, is used for this task.
– The preprocessor searches for special lines
• The statements written by the programmer are
that begin with the # symbol.
called source code, and the file they are saved
– These lines contain commands that cause the in is called the source file.
preprocessor to modify the source code in
• After the source code is saved to a file, the
some way.
process of translating it to machine language
can begin.
Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
… C++ PROGRAM COMPILATION … C++ PROGRAM COMPILATION
• C++ is equipped with a library of prewritten code for • During the next phase
performing common operations or sometimes-difficult – the compiler steps through the preprocessed source
tasks. code,
• For example, the library contains hardware-specific code – translating each source code instruction into the
for displaying messages on the screen and reading input appropriate machine language instruction.
from the keyboard.
– This process will uncover any syntax errors that may
• It also provides routines for mathematical functions,
such as calculating the square root of a number. be in the program.
• Syntax errors are illegal uses of key words, operators,
• This collection of code, called the run-time library, is punctuation, and other language elements.
extensive.
• When the compiler generates an object file, however, it – If the program is free of syntax errors, the compiler
does not include machine code for any run-time library stores the translated machine language instructions,
routines the programmer might have used. which are called object code, in an object file.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department

… C++ PROGRAM COMPILATION


… C++ PROGRAM COMPILATION
• The following • During the last phase of the translation
illustrates the
process of process,
translating a – the linker combines the object file with the
source file
into an necessary library routines.
executable – Once the linker has finished with this step, an
file. executable file is created.
– The executable file contains machine language
instructions, or executable code, and is ready
to run on the computer.

Gebriye Embafresu Computer Science Department Gebriye Embafresu Computer Science Department
End of Chapter One

Gebriye Embafresu Computer Science Department 1-57

You might also like