bbs 514 - yapısal programlama (structured programming)1 bbs 514 yapısal programlama (structured...

43
BBS 514 - Yapısal Programlama (Structured Programming) 1 BBS 514 Yapısal Programlama (Structured Programming)

Post on 22-Dec-2015

242 views

Category:

Documents


2 download

TRANSCRIPT

BBS 514 - Yapısal Programlama (Structured Programming) 1

BBS 514

Yapısal Programlama(Structured Programming)

BBS 514 - Yapısal Programlama (Structured Programming) 2

Course Information

– Instructor:

Name: Prof. Dr. İlyas Çiçekli

Office: Dept. Of Computer Engineering, Room 109

Tel: 297-7500 Ext. 144

Email: [email protected]

Course Web Page: http://web.cs.hacettepe.edu.tr/~ilyas/BBS514

Text Book: Programming in ANSI C, Ram Kumar and Rakesh Agrawal, West Publishing Company, 1992.

BBS 514 - Yapısal Programlama (Structured Programming) 3

Course Organization (Exams)

• One midterm, one final exam.

• Dates and times will be announced on the web and in class.

• Programming assignments

• Grading policy on course web page

BBS 514 - Yapısal Programlama (Structured Programming) 4

Course Organization (Syllabus)

• Introduction to Course• Algorithms• Introduction to C• Variables, Assignment Statement, Simple IO • Decision Statements• Repetition Statement• Functions• Arrays • Pointers • More on Arrays and Pointers • Characters and Strings• Structures • File Processing• Recursion

BBS 514 - Yapısal Programlama (Structured Programming) 5

Computers

BBS 514 - Yapısal Programlama (Structured Programming) 6

Computers

• A computer is a device capable of performing computations and making logical decisions at very fast speeds.

• First electronic digital computer was ENIAC.– built in 1946 at University of Pennsylvania

– used to compute ballistic tables

– it was very huge

• Since from the first computer, computers are getting smaller, but they are getting much powerful.

• They are widely used in many areas of society.– banking, scientific research, schools, airplanes, space program, etc.

BBS 514 - Yapısal Programlama (Structured Programming) 7

Hardware & Software

• The set of instructions controls computers are known as computer programs (software).– programs and data

– a program is a series of instructions

• The physical structure of the computer is called as hardware.– the physical, tangible parts of a computer

– keyboard, monitor, disks, wires, chips, etc.

• A computer requires both hardware and software

• Each is essentially useless without the other

BBS 514 - Yapısal Programlama (Structured Programming) 8

Hardware

• A modern computer consists of five main components and they are all parts of computer hardware:

– Memory

– Central Processing Unit (CPU)

– Input Devices

– Output Devices

– Secondary Storage

BBS 514 - Yapısal Programlama (Structured Programming) 9

CPU and Main Memory

CentralProcessing

Unit

MainMemory

Chip that executes program commands

Intel Pentium 4Sun ultraSPARC IIIPrimary storage

area for programs and

data that are in active use

Synonymous with RAM

BBS 514 - Yapısal Programlama (Structured Programming) 10

Secondary Memory Devices

CentralProcessing

Unit

MainMemory

USB Disk

Hard Disk

Secondary memorydevices providelong-term storage

Information is movedbetween main memoryand secondary memoryas needed

Hard disksFloppy disksZIP disksWritable CDsWritable DVDsTapes

BBS 514 - Yapısal Programlama (Structured Programming) 11

Input / Output Devices

CentralProcessing

Unit

MainMemory

USB Disk

Hard Disk

Monitor

Keyboard

I/O devices facilitateuser interaction

Monitor screenKeyboardMouseJoystickBar code scannerTouch screen

BBS 514 - Yapısal Programlama (Structured Programming) 12

Computer Organization (Memory)

Memory

• Store information (data + instructions)

• A sequence of memory cells.– a byte is 8 bits

– a bit is smallest unit (0 or 1)

• Store, retrieve, update– changing pattern of 0 and 1s in memory cells

– copying these patterns into some internal registers

• Stored information in memory is volatile.

• Size of a memory of a typical PC system: 512MB, 1GB, 2GB– KB, MG, GB

BBS 514 - Yapısal Programlama (Structured Programming) 13

Computer Organization (CPU)

CPU (Central Processing Unit)

• Process and manipulate information stored in memory.

• It can be divided into two units: CU (Control Unit) and ALU (Arithmetic Logic Unit)

• CU coordinates activities of the computer and controls other devices of computer.

• ALU processes arithmetic and logical instructions.

BBS 514 - Yapısal Programlama (Structured Programming) 14

Computer Organization (Input and Output Devices)

Input and Output Devices

• Provide the interface between the user and the computer.

• Input devices are used to enter instructions or data by the user.

• Output devices are used to give results of computations.

• Input Devices: keyboard, mouse

• Output Devices: monitor, printer

BBS 514 - Yapısal Programlama (Structured Programming) 15

Computer Organization (Secondary Storage)

Secondary Storage

• Computers have limited main memory and information stored in main memory is volatile. i.e. when a computer is switched off, information in its main memory disappears.

• There are additional data storage unit, called secondary storage units.

• Data stored in these secondary storage units are permanent, i.e. data does not disappear when you switch off the computer.

• Some secondary storage units: – Floppy Disks

– Hard Disks

– Tape Drive

– Optic Disk (CD Drive, DVD Drive)

– Flash Disk (USB Disks)

BBS 514 - Yapısal Programlama (Structured Programming) 16

SOFTWARE

• Operating System– Controls all machine activities

– Provides the user interface to the computer.

– manages resources such as CPU and memory

– Widows 95, Widows 98, Solaris, Unix

• Application Program– generic form for all other kind of software

– games, word processors, compilers

• Most operating systems and application programs have a graphical user interface (GUI)

• Windows XP– an operating system

– uses a graphical user interface.

– consists of windows

– you point the mouse and click there, you start a program

BBS 514 - Yapısal Programlama (Structured Programming) 17

File/Directory

• File contains a document and Directory contains files or other directories.

• You will be able to create files and directories

• a file can contain different types of information, and normally the extension of that file reflects the content of that file.

– .doc : a word document

– .c : A C program file

– .exe : Executable file

– .java : a java program

– .class : a class file

– .html : a hypertext file used to represent a web page

BBS 514 - Yapısal Programlama (Structured Programming) 18

A Computer Specification

• Consider the following specification for a personal computer:

– 2.8 GHz Pentium 4 Processor

– 512 MB RAM

– 80 GB Hard Disk

– 48x CD-RW / DVD-ROM Combo Drive

– 17” Video Display with 1280 x 1024 resolution

– 56 Kb/s Modem

• What does it all mean?

BBS 514 - Yapısal Programlama (Structured Programming) 19

Memory

Main memory is divided into many memory locations (or cells)

927892799280928192829283928492859286

Each memory cell has a numeric address, which uniquely identifies it

BBS 514 - Yapısal Programlama (Structured Programming) 20

Storing Information

927892799280928192829283928492859286

Large values arestored in consecutivememory locations

1001101010011010Each memory cell stores a set number of bits (usually 8 bits, or one byte)

BBS 514 - Yapısal Programlama (Structured Programming) 21

Storage Capacity

• Every memory device has a storage capacity, indicating the number of bytes it can hold

• Capacities are expressed in various units:

KB 210 = 1024

MB 220 (over 1 million)

GB 230 (over 1 billion)

TB 240 (over 1 trillion)

Unit Symbol Number of Bytes

kilobyte

megabyte

gigabyte

terabyte

BBS 514 - Yapısal Programlama (Structured Programming) 22

Memory

• Main memory is volatile - stored information is lost if the electric power is removed

• Secondary memory devices are nonvolatile

• Main memory and disks are direct access devices - information can be reached directly

• The terms direct access and random access often are used interchangeably

• A magnetic tape is a sequential access device since its data is arranged in a linear order - you must get by the intervening data in order to access other information

BBS 514 - Yapısal Programlama (Structured Programming) 23

RAM vs. ROM

• RAM - Random Access Memory (direct access)

• ROM - Read-Only Memory

• The terms RAM and main memory are basically interchangeable

• ROM could be a set of memory chips, or a separate device, such as a CD ROM

• Both RAM and ROM are random (direct) access devices!

• RAM probably should be called Read-Write Memory

BBS 514 - Yapısal Programlama (Structured Programming) 24

Compact Discs

• A CD-ROM is portable read-only memory

• A microscopic pit on a CD represents a binary 1 and a smooth area represents a binary 0

• A low-intensity laser reflects strongly from a smooth area and weakly from a pit

• A CD-Recordable (CD-R) drive can be used to write information to a CD once

• A CD-Rewritable (CD-RW) can be erased and reused

• The speed of a CD drive indicates how fast (max) it can read and write information to a CD

BBS 514 - Yapısal Programlama (Structured Programming) 25

DVDs

• A DVD is the same size as a CD, but can store much more information

• The format of a DVD stores more bits per square inch

• A CD can store 650 MB, while a standard DVD can store 4.7 GB– A double sided DVD can store 9.4 GB

– Other advanced techniques can bring the capacity up to 17.0 GB

• Like CDs, there are DVD-R and DVD-RW discs

BBS 514 - Yapısal Programlama (Structured Programming) 26

The Central Processing Unit

• A CPU is on a chip called a microprocessor

• It continuously follows the fetch-decode-execute cycle:

fetch

Retrieve an instruction from main memory

decode

Determine what theinstruction is

execute

Carry out theinstruction

BBS 514 - Yapısal Programlama (Structured Programming) 27

The Central Processing Unit

• The CPU contains:

Arithmetic / Logic Unit

Registers

Control Unit

Small storage areas

Performs calculations and makes decisions

Coordinates processing steps

BBS 514 - Yapısal Programlama (Structured Programming) 28

The Central Processing Unit

• The speed of a CPU is controlled by the system clock

• The system clock generates an electronic pulse at regular intervals

• The pulses coordinate the activities of the CPU

• The speed is usually measured in gigahertz (GHz)

BBS 514 - Yapısal Programlama (Structured Programming) 29

Monitor

• The size of a monitor (17") is measured diagonally, like a television screen

• Most monitors these days have multimedia capabilities: text, graphics, video, etc.

• A monitor has a certain maximum resolution , indicating the number of picture elements, called pixels, that it can display (such as 1280 by 1024)

• High resolution (more pixels) produces sharper pictures

BBS 514 - Yapısal Programlama (Structured Programming) 30

Modem

• Data transfer devices allow information to be sent and received between computers

• Many computers include a modulator-demodulator or modem, which allows information to be moved across a telephone line

• A data transfer device has a maximum data transfer rate

• A modem, for instance, may have a data transfer rate of 56,000 bits per second (bps)

BBS 514 - Yapısal Programlama (Structured Programming) 31

Networks

• A network is two or more computers that are connected so that data and resources can be shared

• Most computers are connected to some kind of network

• Each computer has its own network address, which uniquely identifies it among the others

• A file server is a network computer dedicated to storing programs and data that are shared among network users

BBS 514 - Yapısal Programlama (Structured Programming) 32

Network Connections

• Each computer in a network could be directly connected to every other computer in the network

• These are called point-to-point connections

This technique is not practical formore than a few close machines

Adding a computer requiresa new communication linefor each computer alreadyin the network

BBS 514 - Yapısal Programlama (Structured Programming) 33

Network Connections

• Most networks share a single communication line

• Adding a new computer to the network is relatively easy

Network traffic must taketurns using the line, whichintroduces delays

Often information is brokendown in parts, called packets,which are sent to the receivingmachine and then reassembled

BBS 514 - Yapısal Programlama (Structured Programming) 34

Local-Area Networks

LAN

A Local-Area Network(LAN) covers a smalldistance and a smallnumber of computers

A LAN often connects the machinesin a single room or building

BBS 514 - Yapısal Programlama (Structured Programming) 35

Wide-Area Networks

LAN

A Wide-Area Network (WAN)connects two or more LANs,often over long distances

A LAN usually is ownedby one organization, buta WAN often connectsgroups in different countries

LAN

BBS 514 - Yapısal Programlama (Structured Programming) 36

The Internet

• The Internet is a WAN which spans the entire planet

• The word Internet comes from the term internetworking

• It started as a United States government project, sponsored by the Advanced Research Projects Agency (ARPA) - originally it was called the ARPANET

• The Internet grew quickly throughout the 1980s and 90s

BBS 514 - Yapısal Programlama (Structured Programming) 37

TCP/IP

• A protocol is a set of rules that determine how things communicate with each other

• The software which manages Internet communication follows a suite of protocols called TCP/IP

• The Internet Protocol (IP) determines the format of the information as it is transferred

• The Transmission Control Protocol (TCP) dictates how messages are reassembled and handles lost information

BBS 514 - Yapısal Programlama (Structured Programming) 38

IP and Internet Addresses

• Each computer on the Internet has a unique IP address, such as:

204.192.116.2

• Most computers also have a unique Internet name, which also is referred to as an Internet address:

spencer.villanova.edu

kant.gestalt-llc.com

• The first part indicates a particular computer (spencer)

• The rest is the domain name, indicating the organization (villanova.edu)

BBS 514 - Yapısal Programlama (Structured Programming) 39

Domain Names

• The last part of a domain name, called a top-level domain (TLD), indicates the type of organization:

educomorgnet

- educational institution- commercial entity- non-profit organization- network-based organization

Sometimes the suffixindicates the country: New TLDs have

recently been added:

biz, info, tv, name

ukaucase

- United Kingdom- Australia- Canada- Sweden

BBS 514 - Yapısal Programlama (Structured Programming) 40

Domain Names

• A domain name can have several parts

• Unique domain names mean that multiple sites can have individual computers with the same local name

• When used, an Internet address is translated to an IP address by software called the Domain Name System (DNS)

• There is no one-to-one correspondence between the sections of an IP address and the sections of an Internet address

BBS 514 - Yapısal Programlama (Structured Programming) 41

The World Wide Web

• The World Wide Web allows many different types of information to be accessed using a common interface

• A browser is a program which accesses and presents information– text, graphics, video, sound, audio, executable programs

• A Web document usually contains links to other Web documents, creating a hypermedia environment

• The term Web comes from the fact that information is not organized in a linear fashion

BBS 514 - Yapısal Programlama (Structured Programming) 42

The World Wide Web

• Web documents are often defined using the HyperText Markup Language (HTML)

• Information on the Web is found using a Uniform Resource Locator (URL):

http://www.lycos.com

http://www.villanova.edu/webinfo/domains.html

ftp://java.sun.com/applets/animation.zip

• A URL indicates a protocol (http), a domain, and possibly specific documents

BBS 514 - Yapısal Programlama (Structured Programming) 43

Software

• The set of instructions controls computers are known as computer programs (software).

• a software is a series of instructions

• In this course, we will how to write computer programs using C programming language.

• Before, we start to learn C programming language we will talk about:

– ALGORITHMS: a sequence of instructions to solve a problem