Top Banner
Introduction to Programming Instructor: Sanchita Mal- Sarkar Course: CIS 260
58

Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Introduction to Programming

Instructor: Sanchita Mal-Sarkar

Course: CIS 260

Page 2: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer

• An electronic machine that accepts input, processes data, stores data, and produces output.

• Data can be numbers, text, images, graphics, and sound, etc.

• Computer program is a set of instructions. Without it computer is useless.

• Programming languages allow us to write these instructions (e.g. C, C++, Java, etc).

Page 3: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer system

• A computer system consists of a computer, peripheral devices, and software.

• The computer itself can take care of the processing function, but it needs additional components, called peripherals, to accomplish its input, output and storage functions.

• Example of an internal peripheral device is hard disk drive.

Page 4: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer Hardware

• Hardware is the physical component of a computer.

• Hardware is the equipment used to perform the necessary computations.

• Examples: Main memory (RAM, ROM), secondary

memory (hard disk drive, floppy disk drive), CPU, input devices (keyboard and mouse), and output devices (monitor and printer).

Page 5: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Hardware Components of a Computer System

Input Devices

• Keyboard• Computer mouse• Touch screen• Source data automation

Central Processing Unit (CPU)• Arithmetic-Logic Unit• Control Unit

Primary Storage

Output Devices

• Printers• Video display terminals• Plotters• Audio output

Secondary Storage

• Magnetic disk• Optical disk• Magnetic tape

Communications Devices

Buses

Page 6: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Central Processing Unit (CPU)• Coordinating all computer operations.• Performs arithmetic and logical operations on data.• To process a program stored in main memory, - CPU retrieves each instruction in sequence.

- Interprets the instruction to determine what should be done.

- Retrieves any data needed to carry out that instruction

- Then CPU performs the actual manipulation.

• CPU’s current instruction and data values are stored temporarily inside the CPU in special high-speed memory locations called registers.

Page 7: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Central Processing Unit (CPU)

• The CPU consists of a control unit and an arithmetic-logic unit.

• Three kind of buses link the CPU, primary storage, and other devices in the computer systems.

• The data bus moves data to and from primary storage.• The address bus transmits signals for locating a given

address in primary storage.• The control bus transmits signals specifying whether

to read or write data to or from a given primary storage address, input device, or output device.

Page 8: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Data Bus, Address Bus, and Control Bus

Arithmetic-Logic Unit 24 + 12 = 36 12 < 24

Control Unit

Primary Storage

1

T

U

#

8

Input Devices Output DevicesSecondary

Storage

Central Processing Unit (CPU)

Data Bus

Address Bus

Control Bus

Page 9: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Main Memory

• Computer memory is a set of storage locations on the main circuit board (motherboard).

• Four types of memory:

– RAM, virtual memory, ROM, and CMOS (complementary metal oxide semiconductor memory)

Page 10: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Random access memory• Consists of electronic circuits on the

motherboard (main circuit board).

• Temporarily hold programs and data while the computer is on.

• Each circuit has address that is used by the microprocessor to transmit and store data.

• RAM is constantly changing (volatile).

• E.g. When we write a paper, the word processing program will be temporarily copied into RAM so that microprocessor can quickly access the required instructions.

Page 11: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Virtual Memory• Today’s microcomputer software uses

space on computer’s storage devices to simulate RAM if more needed.

• This extra memory is called virtual memory.

• How it works?

• Suppose my computer is running a word processing program that takes up most of the memory in RAM, but I want to run a spreadsheet program at the same time.

Page 12: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Virtual Memory (Cont.)• The OS moves the infrequently used

segment of the word processing program into virtual memory on disk.

• The spreadsheet program now can be loaded into RAM.

• If that segment is later needed, it is copied from virtual memory back to RAM.

• Disadvantage:It is much slower than RAM.

Page 13: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Read-only memory(ROM)• Another set of electronic circuits on the

motherboard inside the computer.• We cannot increase ROM capacity.• Manufacturer permanently installs ROM.• When computer is on, the sets of

instructions in ROM checks all the computer system’s components to

make sure they are working and activates the essential software that controls

the processing function.

Page 14: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Complementary metal oxide semiconductor(CMOS)

• A chip installed on the motherboard.

• Activated during the boot process.

• Contains information about where the essential software is stored.

• A small rechargeable battery powers CMOS.

• It changes every time we add or remove hardware to the computer system.

• CMOS is referred as semipermanent memory.

Page 15: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Secondary Storage Devices

• RAM retains data only when the power is on, so computer must have a more permanent storage option.

• The most common magnetic storage devices are hard disk drive, floppy disk drives, and tape drives.

Page 16: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Hard disk drive• most computers contains one hard disk that

cannot be removed from drive.

• Provides a storage area to be shared by all users of the computer.

• Generally, the programs that are needed to operate the computer system are stored here.

• Advantages over floppy disk: speed and capacity.

Page 17: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Hard Disk Drive

Internal Components

Page 18: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Floppy disk drive• Most common magnetic storage device.

• Users can have any number of floppy disks that can be inserted into computer’s floppy disk drive.

• High density disk- capacity to store 1.44 MB.

• Low-density disk - capacity to store 720 KB.

Page 19: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Tape drive• Another magnetic storage device.

• Provides inexpensive archival storage for large quantities of data.

• Too slow to be used for day-to-day tasks.

• Used to make backup copies of data stored on hard disks.

• If a hard disk fails, data from the backup tape can be reloaded on a new hard disk.

Page 20: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Compact Disk Read Only Memory (CD-ROM)

• Optical storage device.• Uses laser technology to read and write data on

compact discs (CDs).• High capacity and portability. Can store up to 680

MB, equivalent to more than 450 floppy disks.• Disadvantage: The surface of the CD is not

rewriteable like magnetic media. Once the laser cuts a pit in its surface, the pit cannot be recut, so the data stored there cannot be changed.

• Relatively slow access. Mainly used for software distribution and storing large data files such as graphics, animation, and video.

Page 21: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Input Devices• Input device - keyboard, mouse.

• When we press a letter or digit key on a key board, that character is sent to main memory and displayed on the monitor.

• Keyboard consists of three major parts: main keyboard, keypads, and function keys.

• A mouse is a hand-held device used to select an operation.

Page 22: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Output Devices

• Shows the result of processing data.

• Output devices - monitor and printer.

• Monitor is the TV-like device that displays the output from a computer.

• Printer produces a hard copy of the text or graphics processed by the computer.

Page 23: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Processing Hardware

• The most important computer function is processing data. To understand this you need to learn how the computer represents and stores data.

• Computer does not understand human language because it is an electronic device that interpret every signal as either “on” or “off” like a light bulb.

Page 24: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Binary Representation of Data• For information to flow through a computer system, it must be in

form suitable for processing.

• All symbols, pictures, or words must be reduced to a string of binary digits.

• A binary digit is called a bit and it represents either a 0 or a 1.

• In the computer, the presence of an electronic or magnetic signal means “one” and its absence means “zero”.

• A string of 8 bits that computer stores as a unit is called a byte.

• Each byte is used to store a decimal number, a symbol, a character, or a part of a picture.

• By using binary number system a computer can express all numbers as group of zeroes and ones.

• There are two standard binary codes:

EBCDIC (Extended Binary Coded Decimal Interchange Code)

ASCII (American Standard Code for Information Interchange).

Page 25: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Bits and Bytes0 1or One bit

0 1 00 0 00 1 One byte for character A

The Computer representation in ASCII for the name ALICE is:

0 1 00 0 00 1

0 1 00 1 01 0

0 1 00 1 00 1

0 1 00 0 10 1

0 1 00 0 01 1

A

L

I

C

E

Page 26: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Data representation

• Computer represents “on” with a 1 and “off” with a 0. These numbers are called binary digits or bits.

• Binary number system: most widely used method for interpreting bit settings as nonnegative integers.

• 38 (decimal) = 21 +22+25 = 00100110

Page 27: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Ones complement notation

• One of the widely used methods for representing negative binary numbers.

• A negative number is represented by changing each bit to the opposite bit setting.

• Example:

• 38 (decimal) = 00100110 (binary)

• -38 (decimal) = 11011001 (binary)

Page 28: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Twos complement notation• Another popular method of representing

negative binary number

• In this method, 1 is added to the ones complement representation of a negative number.

• Example:

-38 (decimal) = 11011001 (ones complement)

-38 (decimal) = 11011010 (twos complement)

Page 29: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Floating-point notation• Usual method to represent real numbers• Real number is represented by a number, called a

mantissa, times a base raised to an integer power, called an exponent.

• Example:

387.53 = 38753 x 10 -2

Other possibilities .38753 x 10 3, 387.53 x100

(we choose mantissa is an integer with no tailing 0s)

Page 30: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Floating-point notation(cont.)• A real number is represented by a 32-bit string.• 24-bit for mantissa and 8-bit for exponent.• Base is fixed to 10.• Example

100 = 0000000000000000000000100000010

-387.53 = 11111111011010001001111111111110

387.53 = 00000000100101110110000111111110

24-bit binary representation of 38753 is 000000001001011101100001

8-bit twos complement binary representation of -2 is 11111110

Page 31: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Data Communications

Channel => The message needs some kind of medium to be transmitted. This medium is called channel. For example, telephone or coaxial cable, microwave signal, or optical fibers

Protocol => The rules that establish an orderly transfer of data between the sender and the receiver are called protocols.

• Computer software and hardware establish these protocols at the beginning of the transmission, and both computers have to follow the protocols to ensure accurate transfer of data.

Page 32: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Data Communications• The transmission of text, numeric, voice, or video data

from one machine to another is called data communications.

• For example, Send an electronic mail to your friends around the globe.

• The four essential components of data communications are a sender, a receiver, a channel, and a protocol.

Sender => The computer that originates the message is called the sender.

Receiver => The computer at the message’s destination is called the receiver.

Page 33: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Networks• One of the most important types of data communications in

the business world is a network connection.• A network connects one computer to another computers and

peripheral devices to share data and resources.• There is a number of network configurations.• local area network (LAN) => computers and peripheral

devices are located relatively close to each other, generally in the same building.

• Client/server networks =>Some networks have file servers (one or more computers) that act as the central storage location for programs and that provide mass storage for most of the data used on the network. A network with a file server is called a client/server networks.

Page 34: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Networks• Peer-to-peer networks => When a network does not

have a file server, all the computers essentially are equal, and programs and data are distributed among them. This is called a peer-to-peer network.

• Each computer that is part of the network must have a network interface card installed. This device creates a communication channel between the computer and the network.

• Network software is also essential to establish the communications protocols.

• Standalone computer => A microcomputer that is not connected to a network is called a standalone computer.

Page 35: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Telecommunications• Allows us to send and receive data over telephone

lines.• A modem connects a computer to a telephone

jack.• At the sending site, modem converts the digital

signal from a computer into analog (continuous wave) signals (sound waves) that can traverse ordinary phone lines (modulation).

• At the receiving site, a second modem converts the analog signals back into digital signals (demodulation).

Page 36: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Telecommunications

Page 37: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Internet• The internet was originally developed for the government

to connect the researchers around the world to share data.• Today, the internet is the largest network in the world that

connects millions of people in almost 200 countries.• The use of internet: electronic mail => This is the capability to send a message

from one user’s computer to another user’s computer where it is stored until the receiver opens it. Message passes through electronic links called gateways.

World Wide Web (Web) => Web is a huge database of information that is stored on the network servers in places that allow public access. The information is stored as text files called web pages.

Page 38: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Internet

• Hyperlinks => a place on a computer screen that is programmed to connect to a particular file on the same network server, or on a network server on the other side of the globe.

• Web browser => communication software that help us navigate the WWW is called web browsing software or web browser.

Page 39: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer Software• Software consists of the computer

programs that allow us to solve problems by providing sets of instructions.

• Examples:

DOS, Windows, Mac. Office family, Lotus, Netscape, Internet Explorer, Virus scans, tax programs, computer games, GUI - Graphical User Interface.

Page 40: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer Software• Computer hardware is useless without software.• Software is the set of instructions and associated

data that direct the computer to do a task.• Software can be divided into two categories:• system software and application software.• System software helps the computer carry out its

basic operating tasks.• Application software helps the user carry out a

variety of tasks.

Page 41: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

The major types of software

Application software

Hardware

System software

System Software

Operating SystemsSchedules computer eventsAllocates computer resourcesMonitor events

Application SoftwareProgramming languagesAssembly languageFORTRAN, BASIC, PL/1PASCAL, C“4th generation “ languages

Users

Language translators Interpreters Compilers

Utility programsRoutine operations (e.g. sort, list, print)Manage data (e.g. create files, merge files

Page 42: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

System Software

• Manages the fundamental operations of the computer, such as

• loading programs and data into memory, executing programs, saving data to disks, displaying information on the monitor, and transmitting data through a port to a peripheral device.

• Three types of system software: operating systems, utilities, device drivers.

Page 43: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Operating System• Collection of computer programs that control the

interaction of the user and the computer hardware.

• Responsible for directing all computer operations and managing all computer resources.

• Controls basic input and output, allocates system resources, manages storage space, maintains security, and detects equipment failure.

• A part of the operating system code is stored in a ROM and the rest of it resides on a disk.

• Loading the operating system into memory is called booting the computer.

Page 44: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Responsibilities of an Operating System

• Communicate with user, receive and execute commands, show error messages.

• Manage allocation of memory, processor time and other resources.

• Collect input from keyboard, mouse, and provide data to running programs.

• Convey program output to screen, printer, or other output device.

• Access data from secondary storage.• Write data to secondary storage.

Page 45: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Utilities• Another category of system software.

• Augments the OS by taking over some of its responsibility for allocating hardware resources.

• Many utilities come with OS.

• Some independent software developers offer utilities for sale separately.

• E.g. Norton Utilities by Symantec.

Page 46: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Device driver

• Each peripheral device requires a device driver.

• Helps the computer communicate with that particular device.

• When we add a device to an existing computer, part of its installation includes adding its device driver to the configuration.

Page 47: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer programming languages

• Programmer uses to write computer instructions.

• The instructions are converted into electrical signals that computer can manipulate and process.

• E.g. Basic, Visual Basic, C, C++, Cobol, etc.

Page 48: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Command-line & Graphical User Interfaces

• Command-line interface systems display a command prompt, then expect the user to type the desired commands.

• These systems include UNIX, MS-DOS and VMS.• Graphical user interfaces (GUI) display pictures (icons),

menus, and text, which the user may point to with a mouse or other pointing device, then click to select the desired function.

• These systems (GUI) include Macintosh OS, Windows 95/98, Windows NT, OS/2 Warp, and Unix with X Windows interface.

Page 49: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Application software

• Developed for a specific task , such as word processing( MS Word/ WordPerfect), accounting (Lotus 1-2-3/ Excel), or database management (Access/ dBASE).

• Most applications are purchased on diskette or CD-ROM.

• They are installed by copying the programs from the diskettes/CD-ROM to the hard disk.

Page 50: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Computer Languages: Machine Language

• Machine language: directly understood by a computer since it is a collection of binary numbers (0 and 1).

• Disadvantages: It is not standardized, different CPU needs different machine languages.

Page 51: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Assembly language

• One step above of machine language.

• More readable.

• Computer operations are represented by mnemonic codes rather than binary numbers.

• Variables can be given names rather than binary memory addresses.

• Disadvantage: CPU- dependent.

Page 52: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

High -level languages

• CPU-independent.

• Combines algebraic expressions and English symbols.

• Disadvantage: computers do not understand.

• It must be translated into the target computer’s machine language before execution- compiler does the job.

Page 53: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Different High Level Languages

Some of the high-level languages available include:

• FORTRAN for scientific programming, • COBOL for business data processing, • LISP for list processing,• C for systems programming, • Prolog for artificial intelligence, • ADA for real-time distributed systems, • Smalltalk for graphical user interfaces and object-

oriented programming, and • C++ for object-oriented programming.

Page 54: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Compiler• Software that translates a high-level

language program into machine language.

• Input to the compiler is a source file (created by word processor or editor) containing the text of a high-level language program.

• If it is syntactically correct, compiler will save in an object file which is a machine language instructions for the same job.

Page 55: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Linker

• All machine instructions are not complete.

• High-level language programs use at least one of the function that reside in other object files available to the system.

• Linker combines several object files, resolving cross references between the files, into one executable file (machine language program).

Page 56: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Loader

• To run an executable file, the loader must copy all the instructions into memory and direct the CPU to begin execution with the first instruction.

• As the program executes, it takes input data from source(s) and sends results to output devices.

Page 57: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Integrated development environment (IDE)

• Most high-level languages now include an Integrated Development Environment (IDE) consisting of a simple word processor, compiler, linker and loader tools for finding errors.

• This software package provides menus from which user can select the next step.

• It leaves all versions of the program in memory. For safety, we need to explicitly save the source file to disk.

Page 58: Introduction to Programming Instructor: Sanchita Mal-Sarkar Course: CIS 260.

Program Execution• Executing a program requires the CPU to examine each

program instruction in memory and send out the command signals required to perform each instruction.

• Although instructions are normally performed consecutively (sequencing), they can be skipped (branching) or repeated (looping) under program control.

• During execution, data can be entered by the operator, or from a saved file.

• After processing, the program output can be displayed or printed as a result.