0.Introduction 2
0.Introduction 2
Computers and
Programming Languages
Introduction
Without software, the computer is useless
Software is developed with programming languages
◦ C is a programming language (High-Level Programming Language)
2
Elements of a
Computer System
Hardware
◦ CPU
◦ Main memory
◦ Secondary storage
◦ Input/Output devices
Software
System Software (Such as Operating System, and Device driver)
Application Software (such as Word processor and games)
3
Central Processing Unit
and Main Memory
4
The Language of a
Computer
Machine language: language of a
computer; a sequence of 0s and 1s
5
Text Representation
ASCII (American Standard Code for Information Interchange)
◦ 128 characters (27)
◦ A is encoded as 1000001 (=65)(66th character)
◦ 3 is encoded as 0110011 (=51)
◦ Extended ASCII (28 = 256 different characters)
Unicode
◦ 65536 characters (characters in other languages)
◦ Two bytes are needed to store a character
6
ASCII Table
7
The Evolution of Programming
Languages
Early computers were programmed in
machine language
To calculate wages = rate * hours in
machine language (Sequence of 1’s and 0’s):
100100 010001 //Load
100110 010010 //Multiply
100010 010011 //Store
8
The Evolution of
Programming
Languages (cont’d.)
Assembly language instructions are mnemonic ( )
قابلة للتذكر
9
The Evolution of
Programming
Languages (cont’d.)
High-level languages include Basic, FORTRAN,
COBOL, Pascal, C, C, C#, and Java
Compiler: translates a program written in a high-
level language into machine language
The equation
wages = rate • hours
can be written in C as:
wages = rate * hours;
10
Reasons to learn C
11
Applications of C
12
Processing a C Program
(cont’d.)
13
Processing a C Program
(cont’d.)
To execute a C program:
◦ Use an editor to create a source program in C
◦ Preprocessor directives begin with # and are
processed by the preprocessor
◦ Use the compiler to:
◦ Check that the program obeys the language rules
◦ Translate into machine language (object program)
14
Processing a C Program
(cont’d.)
To execute a C program (cont'd.):
◦ Linker:
◦ Combines object program with other programs provided by the SDK to
create executable code
◦ Library: contains prewritten code you can use
◦ Loader:
◦ Loads executable program into main memory
◦ The last step is to execute the program
15
Programming with the
Problem Analysis–Coding–
Execution Cycle
Algorithm:
◦ Step-by-step problem-solving process
◦ Solution achieved in finite amount of time
Programming is a process of problem solving
16
17
18
The Problem Analysis–
Coding–Execution Cycle
(cont’d.)
Thoroughly understand the problem and all requirements
◦ Does program require user interaction?
◦ Does program manipulate data?
◦ What is the output?
19
The Problem Analysis–
Coding–Execution Cycle
(cont’d.)
Once the algorithm is designed and correctness
verified
Write the equivalent code in high-level language
20
The Problem Analysis–
Coding–Execution Cycle
(cont’d.)
Linker links machine code with system resources
Once compiled and linked, loader can place
program into main memory for execution
The final step is to execute the program
Compiler guarantees that the program follows the
rules of the language
◦ Does not guarantee that the program will run correctly
21
Example
Design an algorithm to find the perimeter and area
of a rectangle
The perimeter and area of the rectangle are given
by the following formulas:
22
Example (cont’d.)
Algorithm:
◦ Get length of the rectangle
◦ Get width of the rectangle
◦ Find the perimeter using the following equation:
23
Programming
Methodologies
Two popular approaches to programming
design
◦ Structured
◦ Object-oriented
24
Structured
Programming
Structured design:
◦ Dividing a problem into smaller subproblems
Structured programming:
◦ Implementing a structured design
25
Rectangle.c
#include<stdio.h>
int main()
{
return 0;
26