Sie sind auf Seite 1von 47

BITG 1233:

Introduction To Computers And


Programming Language
by: ZARITA (FTMK)

LECTURE 1

LECTURE 1 1
Learning Outcomes
At the end of this lecture, you should be able to:
• tell the purpose of computer programs.
• describe the hardware and software components of a
computer system.
• tell about the language of a computer.
• describe the evolution of programming languages.
• list the high-level programming languages.

LECTURE 1 2
Learning Outcomes (cont.)
At the end of this lecture, you should be able to:
• tell about the history of C++ language.
• recognize a C++ program.
• explain the different types of program errors.
• explain how a C++ program is processed and tested.
• explain what compiler, linker and loader are and what
they do.

LECTURE 1 3
Why Program?
• Computer – programmable machine designed to follow
instructions.
• Program – a set of instructions for a computer to follow.
– expressed in a language that the computer can
understand.
• Programmer – person who writes instructions (program)
to make computer perform a task.

• SO, without programmer, no program; without


program, a computer cannot do anything.

LECTURE 1 4
LECTURE 1 5
Computer Components
• Computer is an electronic device, with two
major components.

Computer

Hardware Software

LECTURE 1 6
Computer Hardware
•Hardware refers to the physical parts of the computer
that have mass (they can be touched).
•Hardware for a typical computer system includes the
following FIVE main categories :
1. Main Memory / Primary Storage / Internal Memory
2. Central Processing Unit (CPU)
3. Secondary Storage / Auxiliary Storage / External
Memory
4. Input Devices
5. Output Devices
LECTURE 1 7
Categories of Computer Hardware

LECTURE 1 8
Main Memory
• Main memory stores the instructions and data of the programs
that are running on the computer.
• Main memory’s content can change during program execution.
• It is volatile, which means the main memory’s content is erased
when program terminates or computer is turned off.
• It is also called Random Access Memory (RAM)
• Main memory consists of long list of memory locations.
−Each memory location is called a byte, which has eight bits
(binary digits) that contains zeros and ones.
−Binary Digit or Bit : A digit that can only be zero or one.

LECTURE 1 9
LECTURE 1 10
Main Memory

• Data and instructions of programs are kept as binary digits in


memory locations.
− Each memory location has an address that is a unique
number that identifies a memory location.

• Some data is too large for a single byte.


– Most integers and real numbers are too large.
– Next few consecutive bytes can store the additional bits for
larger data.
– Address of large data refers to the address of the first byte
used by it.
LECTURE 1 11
Illustration of Main Memory

LECTURE 1 12
Central Processing Unit (CPU)
• Also known as Processor; ”Brain” of the
computer.
• Comprised of:
– Control Unit (CU)
• Retrieves, decodes and executes program
instructions from RAM
• Coordinates activities of all other parts of
computer
– Arithmetic & Logic Unit (ALU)
• Hardware optimized for high-speed numeric
calculation
• Hardware designed for true/false, yes/no decisions

LECTURE 1 13
CPU Organization

LECTURE 1 14
Secondary Storage
• Secondary memory stores instructions and data
between sessions
• Non-volatile: data is preserved when program is
not running, or computer is turned off.
• Comes in a variety of media:
– magnetic: floppy disk drive (FDD), hard disk drive
(HDD), magnetic tape drive
– optical: Compact Disc (CD), Digital Video Disc (DVD)
– flash memory : USB Flash drive

LECTURE 1 15
Input Devices
• Devices that are sources to get input.
• Input is the information sent to the computer.
• Input consists of:
– A program
– Some data
• Many devices can provide INPUT:
– Keyboard, mouse, scanner, digital camera,
microphone, barcode reader, joystick
– HDD, FDD, flash drive, magnetic tape, CD-ROM
LECTURE 1 16
Output Devices
• Devices that send output.
• Output is information from the computer to
the outside world.
• Many devices can be used for OUTPUT:
– Computer monitor, printer, projector, speaker,
headphone, plotter
– HDD, FDD, flash drive, magnetic tape, CD-RW,
DVD-RW

LECTURE 1 17
Computer Software
• Software: refers to program that resides and
executes electronically on the hardware.
• Software is divided into 2 categories:

Software

System Software Application Software

LECTURE 1 18
System Software
• Normally supplied by the manufacturer of the computer.
• Software that manages computer hardware resources,
and the programs that run on them.
• Basic types of system software:
− BIOS, operating systems, utility programs, software
development tools.
• The operating system is the most important type of
system software. Without it, a user cannot run an
application program on their computer, unless the
application program is self booting.
LECTURE 1 19
Operating System
• The operating system:
− Is a program
− Allows us to communicate with the computer
− Allocates the computer’s resources
− Responds to user requests to run other programs

• Common operating systems include:


UNIX Linux DOS
Windows Macintosh VMS

LECTURE 1 20
Application Software
• Programs that provide services (problem solution)
to the user.
• Designed to perform a specific task (e.g. : course
registration system, banking system) OR a general-
purpose task (e.g. : word processing, games).
• May be acquired by purchasing off-the-shelf or by
designing for own purpose (custom made).
• Off-the-shelf software : Prewritten and ready to
use. For general-purpose task.
• Custom made software: Written by in-house,
consulting firm or software
LECTURE 1
house. For specific task. 21
Where are the application
and system software?

LECTURE 1 22
Programs and
Programming Languages
• A computer program is a set of
written instructions given to a
computer for it to follow. To write a
program needs a programming
language.
• Types of programming languages:
– High-level: closer to human
language
– Low-level: used for
communication with computer
hardware directly. Often written
in binary machine code (0’s/1’s)
directly. LECTURE 1 23
The Language of a Computer
• Machine Language is the language of a
computer.
• Machine Language consists of binary digits
(bits); sequences of 0s and 1s. 0 (signal off) , 1
(signal on)
• Example :
1011010000000101

LECTURE 1 24
History Of Computer Languages

Computer language evolution

The only language understood by a computer is


machine language

LECTURE 1 25
History Of Computer Languages
(cont.)
1. Machine Language
• Computer only understand this language.
• Series of 1’s and 0’s (binary numbers), such as
1011010000000101
• Difficult to write.
• Low level language

LECTURE 1 26
History Of Computer Languages
(cont.)
• Early computers were programmed in machine
language
• Using machine language, to calculate wages = rates x
hours can be written as:
100100 010001 To load a Value
100110 010010 To multiply it with
another value
100010 010011 To store the result

LECTURE 1 27
History Of Computer Languages
(cont.)
2. Symbolic/Assembly Language
• Unique to particular computer.
• Use mnemonics symbols. E.g. “MULT” –Multiply
• Easier to understand.

LECTURE 1 28
History Of Computer Languages
(cont.)
• Using assembly language instructions,
wages = rates x hours
can be written as:
LOAD rate
MULT hours
STOR wages
• Must be translated to machine language (zeros and
ones) for the CPU to execute a program written in
assembly language.
LECTURE 1 29
History Of Computer Languages
(cont.)
3. High-Level Language
• Are designed to be easy to read and write.
• Programmers use this language to write programs.
• Compiler: is use to translate a program written in a high-
level language to machine language
• Portable to many different computers.
• E.g. COBOL , FORTRAN , Visual Basic, Pascal, C, C++, C#,
Java, Lisp, Ada
• The equation wages = rates x hours can be written in C++
as:
wages = rate * hours;
LECTURE 1 30
Some Well-Known High-Level
Programming Languages

LECTURE 1 31
History Of Computer Languages
(cont.)

4. Natural Language
• Like our natural language (such as English,
French, or Chinese)
• Its use is still quite limited.

LECTURE 1 32
C++ History
• C++ evolved from C
• C++ designed by Bjarne Stroustrup at Bell
Laboratories in early 1980s
• Overcame several shortcomings of C
• Incorporated object oriented programming
• C remains a subset of C++
• C++ programs were not always portable from one
compiler to another
• In mid-1998, ANSI/ISO C++ language standards were
approved
LECTURE 1 33
A Sample of C++ Program
• A simple C++ program begins this way:
#include <iostream>
using namespace std;
int main()
{
• And ends this way:
return 0;
}

LECTURE 1 34
Example of a C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << "My first C++ program." << endl;
cout << "The sum of 2 and 3 = " << 5 << endl;
cout << "7 + 8 = " << 7 + 8 << endl;
return 0;
}

Output of a sample Run :


My first C++ program.
The sum of 2 and 3 = 5
7 + 8 = 15

LECTURE 1 35
Program Development
• A computer understands a program only if the
program is coded in its machine language.
• Programmer have to write the program and turn it
into an executable code (machine language).
• Programmer needs to understand the problem ->
break into actions (by writing program)-> execute
by the computer (to see the output).
• In any program development, the output will only
be available if the program does not contain any
errors. LECTURE 1 36
Types of Program Errors
• Syntax errors
– Violation of the grammar rules of the language
– Discovered by the compiler
• Error messages may not always show correct location
of errors
• Run-time errors
– Error conditions detected by the computer at run-time.
• Logic errors
– Errors in the program’s algorithm (logic)
– Most difficult to diagnose
– Computer does not recognize this error
– Detected by the programmer, by checking output of the
program.
LECTURE 1 37
Processing a C++ Program :
From a High-level Program to an Executable Code
Involves these processes:
a) Editing : To create or edit file containing the program with a text editor.
(Program is also called 1 source code)
b) Compiling : The process involves the compiler. The compiler comprises of
two separate programs : preprocessor and translator. Firstly, preprocessor
is run to convert source file directives (instructions that begin with #) to
source code (program) statements. Secondly, the translator checks that
the program obeys the syntax. If all the syntax are being obeyed, the
translator convert the source code into machine language (2object code).
The two steps, are often performed by command COMPILE. Syntax errors
detected will prevent execution of the following process.
c) Linking : Run linker to connect system library functions code to the object
code, producing an 3executable code. Performed by command BUILD.
LECTURE 1 38
From a High-level Program to an Executable Code

LECTURE 1 39
Program Development (cont.)
• Then, after that to produce the output (result of the
program), there are another 2 processes:
d) Loading :
– Loader loads the executable code/program into the
main memory (RAM)
e) Executing:
– The last step is to execute (run) the program to see
the output of the program.
• These 2 processes are often performed by a single
command DEBUG.

LECTURE 1 40
Processing a C++ Program

LECTURE 1 41
Integrated Development
Environments (IDEs)

• An Integrated Development Environment, or


IDE, is a single software development tool that
combine all the tools needed (like a text
editor, compiler, linker, loader and debugger)
to write (create/edit), compile, link, load and
debug/execute a program.
• Examples are Microsoft Visual C++, Borland
C++ Builder, CodeWarrior, etc.

LECTURE 1 42
Using Visual C++ IDEs :
a) Editing Process

Text
editor
area

LECTURE 1 43
Using Visual C++ IDEs :
b) Compiling Process

Compiling
Status
Message

LECTURE 1 44
Using Visual C++ IDEs :
c) Linking Process

Linking
Status
Message

LECTURE 1 45
Using Visual C++ IDEs :
d) Loading & Executing Processes

Execution Result
(Program’s output)

LECTURE 1 46
Can you…
– List the five main components of a computer?

– List the data for a program that adds two numbers?

– Describe the work of a compiler?

– Define source code? Define object code?

– Describe the purpose of the operating system?

-the end-
LECTURE 1 47

Das könnte Ihnen auch gefallen