84
C Programming For Problem Solving Prepared By Muzammil Dakhani Department of Computer Science Engineering Course Code :18CPS13/23 Semester :I/II CIE Marks :40 SEE Marks : 60

C Programming For Problem Solving

  • Upload
    others

  • View
    13

  • Download
    0

Embed Size (px)

Citation preview

Page 1: C Programming For Problem Solving

C Programming For Problem Solving

Prepared By

Muzammil Dakhani

Department of Computer Science Engineering

Course Code :18CPS13/23 Semester :I/II

CIE Marks :40 SEE Marks : 60

Page 2: C Programming For Problem Solving
Page 3: C Programming For Problem Solving

ZEROETH GENERATION

• Man used his fingers, ropes, beads, bones, pebbles

and other objects for counting.

• Abacus, Pascaline, Difference & Anylitical engines

• Electricity was not yet invented

Page 4: C Programming For Problem Solving

FIRST GENERATION

1951 – 1958: The Vacuum Tube

• The first generation of computers, characterized by vacuum tubes, started in 1951 with the creation of -

UNIVAC (Universal Automatic Computer) – a tabulating machine which won the contest for the fastest machine which could count the US 1890 census.

• The first computers used vacuum tubes for circuitry and

magnetic drums for memory.

• They were often enormous and taking up entire room.

• First generation computers relied on machine language.

Page 5: C Programming For Problem Solving

• They were very expensive to operate and in addition to using a

great deal of electricity, generated a lot of heat, which was often the

cause of malfunctions.

The UNIVAC and ENIAC computers are examples of first-

generation computing devices.

VACUUM TUBES – electronic tubes about the size of light bulbs.

Page 6: C Programming For Problem Solving

Second generation computers

(1956-1963) : The Transistor

The year 1959 marked the invention of transistors, whichcharacterized the second generation of computers.

TRANSISTOR – was a three-legged component which shrunkthe size of the first generation computers. Occupied only1/100th of the space occupied by a vacuum tube More reliable,had greater computational speed, required no warm-up timeand consumed far less electricity.

• Transistors replaced vacuum tubes and ushered in the second

generation of computers.

Page 7: C Programming For Problem Solving

• Second-generation computers moved from

cryptic binary machine language to symbolic.

• High-level programming languages were also being

developed at this time, such as early versions of COBOL

and FORTRAN.

• These were also the first computers that stored their

instructions in their memory.

Page 9: C Programming For Problem Solving

THIRD GENERATION : The Integrated

Circuit (1964-1971)Third generation computers arose in 1964 with the invention of

smaller electronic circuits called integrated circuits (IC’S)

INTEGRATED CIRCUITS – are square silicon chips containing circuitry that can perform the functions of hundreds of transistors.

• The development of the integrated circuit was the hallmark of the third generation of computers.

• Transistors were miniaturized and placed on siliconchips, called semiconductors.

Page 10: C Programming For Problem Solving

• Instead of punched cards and printouts, users interacted with

third generation computers through keyboards

and monitors and interfaced with an operating system.

• Allowed the device to run many different applications at one

time.

Page 11: C Programming For Problem Solving

ADVANTAGES

• RELIABILITY – Unlike vacuum tubes, silicon will not break

down easily. It is very seldom that you will have to replace it.

• LOW COST – Silicon chips are relatively cheap because of

their small size and availability in the market. It also

consumes less electricity.

Page 12: C Programming For Problem Solving
Page 13: C Programming For Problem Solving

Fourth generation computers

(1971-present): The Microprocessor

• The microprocessor brought the fourth generation of

computers, as thousands of integrated circuits were

built onto a single silicon chip.

• The Intel 4004 chip, developed in 1971, located all

the components of the computer.

• From the central processing unit and memory to

input/output controls—on a single chip.

Page 14: C Programming For Problem Solving

• Fourth generation computers also saw the development

of GUIs, the mouse and handheld devices.

• Marked by the use of microprocessor

• MICROPROCESSOR – is a silicon chip that contains the

CPU – part of the computer where all processing takes place.

4004 chip – was the first microprocessor introduced by Intel

Corporation.

Page 15: C Programming For Problem Solving
Page 16: C Programming For Problem Solving

Fifth generation computers

(present and beyond)

• is classified as fourth generation computers.

• faster, more powerful, tremendous data storage and processing capacity

• new brands and models would come out the market almost every other month.

• many clones or imitations of the IBM have become even more powerful and a lot cheaper.

Page 17: C Programming For Problem Solving

• Fifth generation computing devices, based on artificial intelligence.

• Are still in development, though there are some applications, such as voice recognition.

• The use of parallel processing and superconductors is helping to make artificial intelligence a reality.

• The goal of fifth-generation computing is to develop devices that respond to natural language input and are capable of learning and self-organization.

Page 18: C Programming For Problem Solving

• computers became more affordable• computers can now be found in homes, schools, offices

etc.

• there has been a tremendous improvement in software technology.

• different software applications to choose from: word processing, spreadsheets, database management, games and entertainment.

• computer subjects are now being offered not just to college students but even to high school and elementary.

• computers are now used as an aid in teaching math, science etc.

Page 19: C Programming For Problem Solving
Page 20: C Programming For Problem Solving

Types of Computers

• On the basis of configuration that is architecture,

processing, power, size of main memory and other

capabilities, computer can be divided in the

following classes.

• Super Computer

• Mainframe Computer.

• Mini Computer

• Micro Computer.

Page 21: C Programming For Problem Solving

Super Computer

These are the

• Largest.

• Fastest.

• Expensive.

• Can handle over 10,000 users.

• Parallel Processing.

Page 22: C Programming For Problem Solving

USE OF SUPERCOMPUTER• Super computers are used for solving complex application

such as Global Weather Forecasting. Creating graphic images,

engineering design and testing, space exploration and other

problems where it is necessary to process huge quantities of

data quickly.

• Cost:

Several million dollars.

• Speed:

60 billion instructions per second.

• Size:

Automobile Sized.

Page 23: C Programming For Problem Solving

Mainframe Computer

• Mainframe computer is usually slower, less

Powerful and less expensive than super

Computer.

• Mainframe computer can handle over

hundreds of users .

Page 24: C Programming For Problem Solving

USE OF MAINFRAME COMPUTER

• Mainframe Computer are useful for dealing with large

over changing collection of data that are accessed by

many users Simultaneously such as banks, airlines,

railways.

• Cost:

Several hundred thousands dollars.

• Speed:

250 million instructions per second.

• Size:

Refrigerator Sized.

Page 25: C Programming For Problem Solving

Mini Computer

• Mini computers are lower to mainframe computers in

terms of speed and storage capacity. They are also

less expensive than mainframe computers. Some of

the features of mainframes will not be available in

mini computers. Hence, their performance also will

be less than that of mainframes.

Page 26: C Programming For Problem Solving

USE OF MINI COMPUTER

• Tele communications.

• Cost:

25000 Dollars to Over 150,000 Dollars.

• Speed:

150 million instruction per second

• Size:

Filling Cabinet size.

Page 27: C Programming For Problem Solving

Micro Computer

• The invention of microprocessor (single chip CPU)

gave birth to the much cheaper micro computers.

They are further classified into

• Personal Computers

• Laptop Computers

• Handheld Computers(PDAs)

Page 28: C Programming For Problem Solving

Personal Computer

• They are usually easier to use and more affordable.

They are normally intended for individual users for

their word processing and other small application

Requirements.

• Desktop

• Tower

Page 29: C Programming For Problem Solving
Page 30: C Programming For Problem Solving

What is a bit?

• Bit is short for 'binary digit.' It's a single digit in a binary number, and it can be either 1 or 0.Inside a computer, you can think of a bit as being a mechanical switch, which can be either switched on or off.

• Now if you only have one of these switches, you can only store two different states, on or off. This is useful in itself, you can record that something is either true or false...

• But if you have, say, eight of them, you can store 256 different combinations of on and off states between the eight switches.

Page 31: C Programming For Problem Solving

What is a byte?

• A byte is 8 bits. That's the definition. With 8 bits you can store any number between 0 and 255, since there are 256 different combinations of 1 and 0 to choose from.

• Why eight bits? The original intention was that, when storing text, 8 bits would be enough to assign a unique number every possible language character you might want to use in your document. The idea was that each character in a file would take up one byte of memory (in most cases, this is still true).

• Let's see: there are 26 uppercase letters (A-Z), 26 lowercase (a-z), 10 numerical digits(0-9), 32 punctuation characters and other symbols on a US keyboard, the space character That's already 94 different characters. Then there's a few characters for creating newlines, a tab character for indentations, there's even a 'bell' character which programs would output in order to make the user's terminal beep. You can see how it all adds up

Page 32: C Programming For Problem Solving

What is a word?

• You often hear about 32-bit or 64-bit computer architectures. A word is basically the number of bits a particular computer's CPU can deal with in one go.

• It varies depending on the computer architecture you're using. Imagine looking at an imaginary computer's circuitry very closely. On a 32-bit machine, you would see 32 wires running parallel to each other between the computer's memory controller and the CPU, for the purpose of giving the CPU access to one particular word of memory.

• Actually, there would be an additional 32 wires (perhaps less) for the CPU to select a particular memory address to access. If a CPU can access 32 bits of memory in one go, then it turns out that it makes a lot of sense to address the computer's memory using ≤32 bits. (This happens to be why the 32-bit version of Windows can't deal with more than 2GB of RAM, but the 64-bit version can.)

Page 33: C Programming For Problem Solving

Bits ,Bytes and Words

Definitions

• Bit = Binary digit = 0 or 1

• Byte = a sequence of 8 bits = 00000000, 00000001, ..., or 11111111

• Word = a sequence of N bits where N = 16, 32, 64 depending on the computer

There are 2N words of length N. Why?

How many bytes are there?

Page 34: C Programming For Problem Solving

Measuring Amount of Data/Memory Capacity

• 1 kilobyte = 1 KB = 210 bytes = 1024 bytes (appx 103 bytes)

• 1 Megabyte = 1 MB = 220 bytes = 1,048,576 bytes (appx106 bytes)

• 1 Gigabyte = 1 GB = 230 bytes = 1,073,741,824 bytes (appx109 bytes)

Page 35: C Programming For Problem Solving

CPU

Page 36: C Programming For Problem Solving

CPU

• Converts data into information

• Control center

• Set of electronic circuitry that executes stored

program instructions

• Two parts

– Control Unit (CU)

– Arithmetic Logic Unit (ALU)

Page 37: C Programming For Problem Solving

Control Unit

CU

• Part of the hardware that is in-charge

• Directs the computer system to execute stored

program instructions

• Communicates with other parts of the hardware

Page 38: C Programming For Problem Solving

Arithmetic / Logic Unit

ALU

Performs arithmetic operations

Performs logical operations

Page 39: C Programming For Problem Solving

Arithmetic Operations

Addition

Subtraction

Multiplication

Division

Page 40: C Programming For Problem Solving

Logical Operations

• Evaluates conditions

• Makes comparisons

• Can compare

– Numbers

– Letters

– Special characters

Page 41: C Programming For Problem Solving

Registers

Special-purpose

High-speed

Temporary storage

Located inside CPU

Data register

Holds data waiting to be processed

Holds results from processing

Instruction register

Holds instruction currently being executed

Page 42: C Programming For Problem Solving

Primary Storage: Memory

• Primary storage is directly accessible by the processor

• Memory:

– RAM = random access memory

– ROM = read only memory

– PROM/EPROM = programmable ROM

• RAM is volatile (not retained w/o power)

• cache, interrupts, memory, flags…

Page 43: C Programming For Problem Solving

Secondary: Mass Data Storage

• primary storage is directly accessible by the CPU

(RAM, cache memory)

• secondary storage is not directly accessed

• data is transferred to primary memory when needed

by processor

• MDS is non-volatile - record and modify

information (semi-)permanently

Page 44: C Programming For Problem Solving

Types of MDS

1. Punched surfaces

- earliest method; human readable

- punched cards, punched tape

2. Magnetic surfaces

- most widely used

- streaming tape, magnetic disks (floppy, hard, zip…)

3. Optical surfaces

- most durable

- optical disks (CD-ROM, laserdisc, DVD…)

Page 45: C Programming For Problem Solving

Comparisons of MDS typesmedia: size/capacity: advantages: disadvantages:

Floppy 3.5” = 720KB, 1.44MB, 2.885 ¼” = 360, 720KB (old)8” = 180, 360KB (old)

inexpensive;shareable

slow;effected by magnetic fields, dirt, temp; corruptible

Hard ¼, half & full height, 51/4”, 8” = 5MB… 100+GB?

fastest not usually portable;not expandable

Optical CD = 4.5” = 80-650MBdata/74minAudio

Laser = 8”,12”DVD = 3.8 - 17GB

massive capacity,high reliability,portability,data & audio standard

read only

Removable

Clik = 25 - 40MBZip = 100-250MBJaz = 500M - 2GBSuperDisk (3M - Imation) =120MB

faster & more capacity than floppies;read/writeable

slower than hard;more expensive than floppies

Magneto-optical MO

combination of technologies reliable; high capacity

expensive; not as fast

Flash Memory

(newest)

solid state storage;memory sticks; flashcards

no moving parts,rewritable

very expensive;no standard yet

Page 46: C Programming For Problem Solving

What are Ports?

• On computer, a port is generally a specific place for being physically connected to some other device, usually with a socket or plug which we call Connectors

Typical Computer Port found behind a desktop PC

Page 47: C Programming For Problem Solving

What are Connectors?

• A connector is any connector used within computers or to connect computers to networks, printers or

other devices.

Many types of computer connectors

Page 48: C Programming For Problem Solving

The PS/2 Connector

• The PS/2 connector are usefor connecting keyboard andmouse on the modern PCs.The PS2 mouse connectorand port is usually green incolour to distinguish it fromthe PS2 keyboard, which ispurple.

Page 49: C Programming For Problem Solving

The USB Port

• Universal Serial Bus: a protocol for transferring data to and from digital devices. Many digital cameras and memory card readers connect to the USB port on a computer.

Page 50: C Programming For Problem Solving

The Firewire IEEE 1394 Port

• A type of cabling technology for transferring data to and from digital devices at high speed. FireWire are typically faster than those that connect via USB.

Page 51: C Programming For Problem Solving

The RJ45 Ethernet Port

• LAN or (Local Area Network) uses a CAT5 cable and a RJ45 connection. The CAT 5 cable is also called the Ethernet Cable.

• Network connection generally uses a 10/100 Mbps speed. This means it has two different speeds 10 Mbps and 100 Mbps.

Page 52: C Programming For Problem Solving

DB25 Parallel Port

• The printer connects to your computer with a Parallel connector. This connector has 25 pins.

• Parallel means the device is capable of receiving more than one bit at a time (that is, it receives several bits in parallel).

Page 53: C Programming For Problem Solving

53

Exploring Data Communications

Computer ports and connections

Power connection

Mouse port

FireWire port

Network port

Phone line

connection

Speaker and

microphone

connections

USB ports

Monitor port

Audio

connection

Keyboard port

Page 54: C Programming For Problem Solving

Input & output devices

• A computer system needs to communicate with its external environment its user). The Input/output devices provide this capability to a computer system. they are also known as peripheral devices, because they surround a computer's cpu and memory.

Page 55: C Programming For Problem Solving

Input data from

external world

INPUT DEVICE

Input data coded into

internal form

CPU & memory

Processed data in

internal for

OUTPUT DEVICES

Result of processing in human

acceptable form

Input data from

external world

INPUT DEVICE

Input data coded into

internal form

CPU & memory

Processed data in

internal for

OUTPUT DEVICES

Result of processing in human

acceptable form

Page 56: C Programming For Problem Solving

Input Device • Input devices are used to enter data from outside

world into primary storage & output devices supply the result of processing from primary storage to users.

• Input device is any peripheral (piece of computer h/w equipment) used to provide data & control signals to an information processing system. Input/output devices make up the h/w interface between a computer .

• The most common input devices are following.

Keyboard , Mouse, Scanner, Joystick, Trackball

Page 57: C Programming For Problem Solving

Output Device

• An output device is any piece of computer hardware equipment used to communicate the results of data processing carried out by an information processing system (such as a computer) to the outside world.

Page 58: C Programming For Problem Solving

• In computing, input/output, or I/O, refers to the communication between an information processing system (such as a computer), and the outside world.

• Inputs are the signals or data sent to the system, and outputs are the signals or data sent by t

• Examples of output devices:Speaker , Headphones, Screen (Monitor), Printer, Projector etc….

Page 59: C Programming For Problem Solving

Output devices

Page 60: C Programming For Problem Solving

15-60

Networking

• Computer network A collection of computing devices that are connected in various ways in order to communicate and share resources

Usually, the connections between computers in a network are made using physical wires or cables

However, some connections are wireless, using radio waves or infrared signals

Page 61: C Programming For Problem Solving

15-61

Networking

• The generic term node or host refers to any device on a network

• Data transfer rate The speed with which data is moved from one place on a network to another

• Data transfer rate is a key issue in computer networks

Page 62: C Programming For Problem Solving

15-62

Networking

• Computer networks have opened up an entire frontier in the world of computing called the client/server model

Figure 15.1 Client/Server interaction

Page 63: C Programming For Problem Solving

15-63

Networking

• File server A computer that stores and manages files for multiple users on a network

• Web server A computer dedicated to responding to requests (from the browser client) for web pages

Page 64: C Programming For Problem Solving

Bandwidth

• Data rate measured in bits (not bytes) per seconds

• Kbps (Kilobits per seconds)

– 125 chars/sec

• Mbps (Megabits per seconds)

– 1,250 chars/sec

• Gbps (Gigabits per seconds)

– 12,500 chars/sec

Page 65: C Programming For Problem Solving

15-65

Types of Networks

• Local-area network (LAN) A network that connects a relatively small number of machines in a relatively close geographical area

Page 66: C Programming For Problem Solving

15-66

Types of Networks

• Various configurations, called topologies, have been used to administer LANs

– Ring topology A configuration that connects all nodes in a closed loop on which messages travel in one direction

– Star topology A configuration that centers around one node to which all others are connected and through which all messages are sent

– Bus topology All nodes are connected to a single communication line that carries messages in both directions

Page 67: C Programming For Problem Solving

Types of Networks

• A bus technology called Ethernet has become the industry standard for local-area networks

Figure 15.2 Various network topologies

15-10

Page 68: C Programming For Problem Solving

15-68

Types of Networks

• Wide-area network (WAN) A network that connects two or more local-area networks over a potentially large geographic distance

Often one particular node on a LAN is set up to serve as a gateway to handle all communication going between that LAN and other networks

Communication between networks is called internetworking

The Internet, as we know it today, is essentially the ultimate wide-area network, spanning the entire globe

Page 69: C Programming For Problem Solving

15-69

Types of Networks

• Metropolitan-area network (MAN) The communication infrastructures that have been developed in and around large cities

Page 70: C Programming For Problem Solving

Network Hardware

• Hub– An unintelligent network device that

sends one signal to all of the stations connected to it.

– All computers/devices are competing for attention because it takes the data that comes into a port and sends it out all the other ports in the hub.

– Traditionally, hubs are used for star topology networks, but they are often used with other configurations to make it easy to add and remove computers without bringing down the network.

– Resides on Layer 1 of the OSI model

OSI Model Layers

7 Application

6 Presentation

5 Session

4 Transport

3 Network

2 Data Link

1 Physical

Page 71: C Programming For Problem Solving

Network Hardware

• Switch– Split large networks into small

segments, decreasing the number of users sharing the same network resources and bandwidth.

– Understands when two devices want to talk to each other, and gives them a switched connection

– Helps prevent data collisions and reduces network congestion, increasing network performance.

– Most home users get very little, if any, advantage from switches, even when sharing a broadband connection.

– Resides on Layer 2 of the OSI model.

OSI Model Layers

7 Application

6 Presentation

5 Session

4 Transport

3 Network

2 Data Link

1 Physical

Page 72: C Programming For Problem Solving

Network Hardware

• Bridge– Connects two LANs and forwards or

filters data packets between them.

– Creates an extended network in which any two workstations on the linked LANs can share data.

– Transparent to protocols and to higher level devices like routers.

– Forward data depending on the Hardware (MAC) address, not the Network address (IP).

– Resides on Layer 2 of the OSI model.

OSI Model Layers

7 Application

6 Presentation

5 Session

4 Transport

3 Network

2 Data Link

1 Physical

Page 73: C Programming For Problem Solving

Network Hardware

• Repeater

– Used to boost the signal between two cable segments or wireless access points.

– Can not connect different network architecture.

– Does not simply amplify the signal, it regenerates the packets and retimes them.

– Resides on Layer 1 of the OSI model.

OSI Model Layers

7 Application

6 Presentation

5 Session

4 Transport

3 Network

2 Data Link

1 Physical

Page 74: C Programming For Problem Solving

Network Hardware

• Router– A device that connects any number of LANs.

– Uses standardized protocols to move packets efficiently to their destination.

– More sophisticated than bridges, connecting networks of different types (for example, star and token ring)

– Forwards data depending on the Network address (IP), not the Hardware (MAC) address.

– Routers are the only one of these four devices that will allow you to share a single IP address among multiple network clients.

– Resides on Layer 3 of the OSI model.

OSI Model Layers

7 Application

6 Presentation

5 Session

4 Transport

3 Network

2 Data Link

1 Physical

Page 75: C Programming For Problem Solving

Network Hardware

• Additional Network Hardware Devices– Network Interface Cards (NICs)

• Puts the data into packets and transmits packet onto the network.

• May be wired or wireless.

– Gateway

• Connects networks with different protocols like TCP/IP network and IPX/SPX networks.

• Routers and Gateways often refer to the same device.

– Proxy server

• Isolates internal network computers from the internet.

• The user first access the proxy server and the proxy server accesses the internet and retrieves the requested web page or document. The user then gets a copy of that page from the proxy server.

Source: http://www.camas.wednet.edu/chs/tech/computer_tech/info/routers_hubs_bridges.htm

Page 76: C Programming For Problem Solving

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 to carry out its basic operating tasks.

• Application software helps the user carry out a variety of tasks.

Page 77: C Programming For Problem Solving

The major types of software

Application software

Hardware

System software

System Software

Operating SystemsSchedules computer eventsAllocates computer resourcesMonitor events

Application Software

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

Users

Language translators

InterpretersCompilers

Utility programs

Routine operations (e.g. sort, list, print)

Manage data (e.g. create files, merge files

Page 78: C Programming For Problem Solving

Chapter 3: Computer Software 78

Software Categories

Page 79: C Programming For Problem Solving

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.

• System software: operating systems, utilities, device drivers.

Page 80: C Programming For Problem Solving
Page 81: C Programming For Problem Solving

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 82: C Programming For Problem Solving

Chapter 3: Computer Software 82

Application Software

• Productivity software can be defined as any type of application software that has the potential to help people do their work more efficiently

• Groupware is designed to help several people collaborate on a single project using local networks or Internet connections

Page 83: C Programming For Problem Solving

Chapter 3: Computer Software 83

Utility Software

• Utility software (a type of system software) is designed to help you monitor and configure settings for your computer system equipment, the operating system, or application software

• A desktop widget is a specialized utility program that appears on a computer’s screen-based desktop

Page 84: C Programming For Problem Solving

Chapter 3: Computer Software 84

Device Drivers

• A device driver is software that helps a peripheral device establish communication with a computer

• Windows Device Manager