0% found this document useful (0 votes)
2 views26 pages

0.Introduction 2

The document provides an overview of computers and programming languages, emphasizing the importance of software and programming languages like C. It explains the components of a computer system, the evolution of programming languages, and the process of programming including problem analysis, coding, and execution. Additionally, it discusses structured programming methodologies and provides an example of a C program for calculating the perimeter and area of a rectangle.

Uploaded by

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

0.Introduction 2

The document provides an overview of computers and programming languages, emphasizing the importance of software and programming languages like C. It explains the components of a computer system, the evolution of programming languages, and the process of programming including problem analysis, coding, and execution. Additionally, it discusses structured programming methodologies and provides an example of a C program for calculating the perimeter and area of a rectangle.

Uploaded by

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

An Overview of

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)

C suited for a wide variety of programming tasks

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 ( )
‫قابلة للتذكر‬

Assembler: translates a program written in assembly


language into machine language
Using assembly language instructions,
wages = rate • hours
can be written as:
LOAD rate
MULT hour
STOR wages

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

Some IDEs do all this with a Build or Rebuild


command

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?

If the problem is complex, divide it into subproblems


◦ Analyze and design algorithms for each subproblem

Check the correctness of algorithm


◦ Can test using sample data
◦ Some mathematical analysis might be required

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

Enter the program using text editor


Run code through compiler
If compiler generates errors
 Look at code and remove errors
 Run code again through compiler
If there are no syntax errors
 Compiler generates equivalent machine code

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:

perimeter = 2 * (length + width)


area = length * width

22
Example (cont’d.)
Algorithm:
◦ Get length of the rectangle
◦ Get width of the rectangle
◦ Find the perimeter using the following equation:

perimeter = 2 * (length + width)


◦ Find the area using the following equation:

area = length * width

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

The structured design approach is also called:


◦ Top-down (or bottom-up) design
◦ Stepwise refinement
◦ Modular programming

25
Rectangle.c
#include<stdio.h>

int main()
{

float width, length, Perimeter, Area;

printf ("\n Please Enter the Width of a Rectangle : ");


scanf ("%f",&width);

printf ("\n Please Enter the Length of a Rectangle : ");


scanf ("%f",&length);

Perimeter = 2 * (length + width);


Area = length * width;

printf("\n Perimeter of a Rectangle = %.2f", Perimeter);

printf("\n Area of a Rectangle = %.2f", Area);

return 0;

26

You might also like