Docsity

Introduction to Computer Hardware and Software: A Comprehensive Guide, Lecture notes of C programming

Toggle sidebar
bg1
VISVESVARAYA TECHNOLOGICAL
UNIVERSITY
Belgaum,
Karnataka
C PROGRAMMING FOR PROBLEM SOLVING
(18CPS13/18CPS23)
COURSE
MATERIAL
I/II Semester
Prepared by
Mr. RAJESH Assistant Professor, CSE, CITECH
Mrs. BHAGYASHREE AMBORE Assistant Professor, CSE, CITECH
Mrs. HARINI Assistant Professor, CSE, CITECH
Department of Computer Science & Engineering
CAMBRIDGE INSTITUTE OF TECHNOLOGY
K.R.Puram, Bangalore
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e

Partial preview of the text

Download Introduction to Computer Hardware and Software: A Comprehensive Guide and more Lecture notes C programming in PDF only on Docsity!

VISVESVARAYA TECHNOLOGICAL

UNIVERSITY

Belgaum, Karnataka

C PROGRAMMING FOR PROBLEM SOLVING

( 18 CPS 1 3/ 18 CPS 23 )

COURSE MATERIAL

I/II Semester

Prepared by Mr. RAJESH (^) Assistant Professor, CSE, CITECH Mrs. BHAGYASHREE AMBORE (^) Assistant Professor, CSE, CITECH Mrs. HARINI (^) Assistant Professor, CSE, CITECH

Department of Computer Science & Engineering

CAMBRIDGE INSTITUTE OF TECHNOLOGY

K.R.Puram, Bangalore

C PROGRAMMING FOR PROBLEM SOLVING (Effective from the academic year 2 018 - 20 19) SEMESTER – I/II Subject Code 18 CPS 13 / 23 CIE Marks 40 Number of Contact Hours/Week (^) 2 : 2 : 0 SEE Marks 60 Total Number of Contact Hours (^) 40 Exam Hours 3 Hrs CREDITS- 3 Module (^1) Contact Hours Introduction to computer Hardware and software: Computer generations, computer types, bits, bytes and words, CPU, Primary memory, Secondary memory, ports and connections, input devices, output devices, Computers in a network, Network hardware, Software basics, software types. Overview of C: Basic structure of C program, executing a C program. Constant, variable and data types, Operators and expressions, Reference 1: Chapter 1, Chapter 2 ( 2 .2, 2.3) Text book 1: Ch 1, 2 and 3 08 Module 2 Managing Input and output operations. Conditional Branching and Loops. Example programs, Finding roots of a quadratic equation, computation of binomial coefficients, plotting of Pascals triangle. Text book 1: 4, 5 and 6 08 Module 3 Arrays: Arrays ( 1 - D, 2-D), Character arrays and Strings, Basic Algorithms: Searching and Sorting Algorithms (Linear search, Binary search, Bubble sort and Selection sort). Text book 1: Ch 5, 6, 7 ( 7. 1 to 7.6) and 8 ( 8 .1 to 8 .8) 08 Module 4 User Defined Functions and Recursion. Example programs, Finding Factorial of a positive integers and Fibonacci series. Text book 1: Ch 9 (9. 1 to 9.18) 08 Module 5 Structure and Pointers, Preprocessor Directives Text book 1: Ch 10 (10.1 to 10.9) and 11(11.1 to 11. 6 and 11 .16) 08 Course Outcomes: The student will be able to : Illustrate simple algorithms from the different domains such as mathematics, physics, etc. Construct a programming solution to the given problem using C. Identify and correct the syntax and logical errors in C programs. Modularize the given problem using functions and structures. Question Paper Pattern: · The question paper will have ten questions. Each full Question consisting of 20 marks

MODULE 1

Introduction to computer Hardware and software: Computer generations, computer types, bits, bytes and words, CPU, Primary memory, Secondary memory, ports and connections, input devices, output devices, Computers in a network, Network hardware, Software basics, software types. Overview of C: Basic structure of C program, executing a C program. Constant, variable and data types, Operators and expressions. CHAPTER 1: Introduction to computer hardware and software 1 Computer Generations:- Computers are such an integral part of our everyday life now most people take them and what they have added to life totally for granted. Even more so the generation who have grown from infancy within the global desktop and laptop revolution since the 1980s. The history of the computer goes back several decades however and there are five definable generations of computers. Each generation is defined by a significant technological development that changes fundamentally how computers operate – leading to more compact, less expensive, but more powerful, efficient and robust machines. 1940 – 1956: First Generation – Vacuum Tubes These early computers used vacuum tubes as circuitry and magnetic drums for memory. As a result they were enormous, literally taking up entire rooms and costing a fortune to run. These were inefficient materials which generated a lot of heat, sucked huge electricity and subsequently generated a lot of heat which caused ongoing breakdowns. These first generation computers relied on ‗machine language‘ (which is the most basic programming language that can be understood by computers). These computers were limited to solving one problem at a time. Input was based on punched cards and paper tape. Output came out on print-outs. The two notable machines of this era were the UNIVAC and ENIAC machines

  • the UNIVAC is the first every commercial computer which was purchased in 1951 by a business – the US Census Bureau.

Fig 1.1: Vacuum tubes 1956 – 1963: Second Generation – Transistors The replacement of vacuum tubes by transistors saw the advent of the second generation of computing. Although first invented in 19 47, transistors weren‘t used significantly in computers until the end of the 1950s. They were a big improvement over the vacuum tube, despite still subjecting computers to damaging levels of heat. However they were hugely superior to the vacuum tubes, making computers smaller, faster, cheaper and less heavy on electricity use. They still relied on punched card for input/printouts. The language evolved from cryptic binary language to symbolic (‗assembly‘) languages. This meant programmers could create instructions in words. About the same time high level programming languages were being developed (early versions of COBOL and FORTRAN). Transistor-driven machines were the first computers to store instructions into their memories – moving from magnetic drum to magnetic core ‗technology‘. The early versions of these machines were developed for the atomic energy industry.

The increased power of these small computers meant they could be linked, creating networks. Which ultimately led to the development, birth and rapid evolution of the Internet. Other major advances during this period have been the Graphical user interface (GUI), the mouse and more recently the astounding advances in lap-top capability and hand-held devices. Fig. 1.4: Microprocessors 2010 - : Fifth Generation – Artificial Intelligence Computer devices with artificial intelligence are still in development, but some of these technologies are beginning to emerge and be used such as voice recognition. AI is a reality made possible by using parallel processing and superconductors. Leaning to the future, computers will be radically transformed again by quantum computation, molecular and nano technology. The essence of fifth generation will be using these technologies to ultimately create machines which can process and respond to natural language, and have capability to learn and organize themselves.

Fig. 1.5: Artificial Intelligence 2 Computer Types:- Since the advent of the first computer different types and sizes of computers are offering different services. Computers can be as big as occupying a large building and as small as a laptop or a microcontroller in mobile & embedded systems. The four basic types of computers are as under:

  1. Supercomputer
  2. Mainframe Computer
  3. Minicomputer
  4. Microcomputer Supercomputer The most powerful computers in terms of performance and data processing are the Supercomputers. These are specialized and task specific computers used by large organizations. These computers are used for research and exploration purposes, like NASA uses supercomputers for launching space shuttles, controlling them and for space exploration purpose. The supercomputers are very expensive and very large in size. It can be accommodated in large air-conditioned rooms; some super computers can span an entire building. Fig. 1.6: Supercomputers

Fig. 1.8: Minicomputer Micro Computer Desktop computers, laptops, personal digital assistant (PDA), tablets & smartphones are all types of microcomputers. The micro-computers are widely used & the fastest growing computers. These computers are the cheapest among the other three types of computers. The Micro-computers are specially designed for general usage like entertainment, education and work purposes. Well known manufacturers of Micro-computer are Dell, Apple, Samsung, Sony& Toshiba. Desktop computers, Gaming consoles, Sound & Navigation system of a car, Netbooks, Notebooks, PDA‘s, Tablet PC‘s, Smartphones, Calculators are all type of Microcomputers. Fig. 1.9: Microcomputer

a. Bits, bytes and words A bit is a BInarydigiT. So a bit is a zero or a one. Bits can be implemented in computer hardware using switches. If the switch is on then the bit is one and if the switch is off then the bit is zero. A bit is limited to representing two values. Since the alphabet contains more than two letters, a letter cannot be represented by a bit. A byte is a sequence of bits. Since the mid 1960 's a byte has been 8 bits in length. 01000001 is an example of a byte. Since there are 8 bits in a byte there are 2 8 different possible sequences for one byte, ranging from 00000000 to 11111111. This means that a byte can be used to represent any type of value with no more than 28 = 256 possible values. Since the number of things that you can enter on a computer keyboard is smaller than 256 (including all keystoke pairs, like shift or control plus another key), a code for a keystoke is represented with a code within a byte. Since characters (letters, decimal digits and special characters such as punctuation marks, etc) can be represented with bytes, a standard is needed to insure that the code that's used on your computer is the same as the code that is used on mine. There are two standard codes that use one byte to represent a character, ASCII and EBCDIC. ASCII, the American Standard Code for Information Interchange, is the code that is most commonly used today. EBCDIC, Extended Binary Coded Decimal Interchange Code, was used by IBM on its large mainframe computers in the past. Wikipedia has more than you want to know about ASCII and EBCDIC. Since these codes are limited to 256 possible combinations, certain character sets, such as Chinese, Arabic, Japanese, Klingon and others, cannot be represented using these codes. This problem is solved by using another code, Unicode , which uses 2 bytes for each character. This extension allows 216 different symbols to be represented, a total of 65,536. The use of Unicode gives more flexibility in the representation of data. The drawback of using Unicode is that it takes twice as much space to store the same number of characters. A word is the number of bits that are manipulated as a unit by the particular CPU of the computer. Today most CPUs have a word size of 32 or 64 bits. For example, the notebook computer that I bought in May 2008 contains a core 2 duo 64 bit processor. Data is fetched from memory to the processor in word size chunks and manipulated by the ALU in word size chunks.

Fig. 1.10: CPU c. Primary Memory Primary storage (also known as main memory or internal memory), often referred to simply as memory, is the only one directly accessible to the CPU. The CPU continuously reads instructions stored there and executes them as required. Any data actively operated on is also stored there in uniform manner. Historically, early computers used delay lines, Williams tubes, or rotating magnetic drums as primary storage. By 1954, those unreliable methods were mostly replaced by magnetic core memory. Core memory remained dominant until the 1970s, when advances in integrated circuit technology allowed semiconductor memory to become economically competitive. This led to modern random-access memory (RAM). It is small-sized, light, but quite expensive at the same time. (The particular types of RAM used for primary storage are also volatile, i.e. they lose the information when not powered). Main memory is directly or indirectly connected to the central processing unit via a memory bus. It is actually two buses (not on the diagram): an address bus and a data bus. The CPU firstly sends a number through an address bus, a number called memory address, that indicates the desired location of data. Then it reads or writes the data in the memory cells using the data bus. Additionally, a memory management unit (MMU) is a small device between CPU

and RAM recalculating the actual memory address, for example to provide an abstraction of virtual memory or other tasks. As the RAM types used for primary storage are volatile (uninitialized at start up), a computer containing only such storage would not have a source to read instructions from, in order to start the computer. Hence, non-volatile primary storage containing a small startup program (BIOS) is used to bootstrap the computer, that is, to read a larger program from non- volatile secondary storage to RAM and start to execute it. Fig. 1.11: Primary Memory d. Secondary Memory Secondary storage (also known as external memory or auxiliary storage ), differs from primary storage in that it is not directly accessible by the CPU. The computer usually uses its input/output channels to access secondary storage and transfers the desired data using intermediate area in primary storage. Secondary storage does not lose the data when the device is powered down—it is non-volatile. Per unit, it is typically also two orders of magnitude less expensive than primary storage. Modern computer systems typically have two orders of magnitude more secondary storage than primary storage and data are kept for a longer time there. In modern computers, hard disk drives are usually used as secondary storage. The time taken to access a given byte of information stored on a hard disk is typically a few thousandths of a second, or milliseconds. By contrast, the time taken to access a given byte of information

A computer port is also called as a Communication Port as it is responsible for communication between the computer and its peripheral device. Generally, the female end of the connector is referred to as a port and it usually sits on the motherboard. In Computers, communication ports can be divided into two types based on the type or protocol used for communication. They are Serial Ports and Parallel Ports. A serial port is an interface through which peripherals can be connected using a serial protocol which involves the transmission of data one bit at a time over a single communication line. The most common type of serial port is a D-Subminiature or a D-sub connector that carry RS-232 signals. A parallel port, on the other hand, is an interface through which the communication between a computer and its peripheral device is in a parallel manner i.e. data is transferred in or out in parallel using more than one communication line or wire. Printer port is an example of parallel port. PS/ PS/2 connector is developed by IBM for connecting mouse and keyboard. It was introduced with IBM‘s Personal Systems/ 2 series of computers and hence the name PS/ connector. PS/2 connectors are color coded as purple for keyboard and green for mouse. Serial Port Even though the communication in PS/2 and USB is serial, technically, the term Serial Port is used to refer the interface that is compliant to RS-232 standard. Parallel Port Parallel port is an interface between computer and peripheral devices like printers with parallel communication. The Centronics port is a 36 pin port that was developed as an interface for printers and scanners and hence a parallel port is also called as a Centronics port. Before the wide use of USB ports, parallel ports are very common in printers. The Centronics port was later replaced by DB-25 port with parallel interface.

Audio Ports Audio ports are used to connect speakers or other audio output devices with the computer. The audio signals can be either analogue or digital and depending on that the port and its corresponding connector differ. VGA Port VGA port is found in many computers, projectors, video cards and High Definition TVs. It is a D-sub connector consisting of 15 pins in 3 rows. The connector is called as DE-15. VGA port is the main interface between computers and older CRT monitors. Even the modern LCD and LED monitors support VGA ports but the picture quality is reduced. VGA carries analogue video signals up to a resolution of 648X480. Digital Video Interface (DVI) DVI is a high speed digital interface between a display controller like a computer and a display device like a monitor. It was developed with an aim of transmitting lossless digital video signals and replace the analogue VGA technology. Display Port Display Port is a digital display interface with optional multiple channel audio and other forms of data. Display Port is developed with an aim of replacing VGA and DVI ports as the main interface between a computer and monitor. HDMI HDMI is an abbreviation of High Definition Media Interface. HDMI is a digital interface to connect High Definition and Ultra High Definition devices like Computer monitors, HDTVs, Blu-Ray players, gaming consoles, High Definition Cameras etc.HDMI can be used to carry uncompressed video and compressed or uncompressed audio signals. USB Universal Serial Bus (USB) replaced serial ports, parallel ports, PS/2 connectors, game ports and power chargers for portable devices.

Output devices allow computers to communicate with users and with other devices. This can include peripherals, which may be used for input/output (I/O) purposes, like network interface cards (NICs), modems, IR ports, RFID systems and wireless networking devices, as well as mechanical output devices, like solenoids, motors and other electromechanical devices. Fig. 1.14: Output Devices Some of the most common output devices that people are familiar with include monitors, which produce video output; speakers, which produce audio output; and printers, which produce text or graphical output. h. Computers in a network The Network allows computers to connect and communicate with different computers via any medium. LAN, MAN and WAN are the three major types of the network designed to operate over the area they cover. There are some similarities and dissimilarities between them. One of the major differences is the geographical area they cover, i.e. LAN covers the smallest area; MAN covers an area larger than LAN and WAN comprises the largest of all. Local Area Network (LAN): LAN or Local Area Network connects network devices in such a way that personal computer and workstations can share data, tools and programs. The group of computers and devices are connected together by a switch, or stack of switches, using a private addressing scheme as defined by the TCP/IP protocol. Private addresses are unique in relation to

other computers on the local network. Routers are found at the boundary of a LAN, connecting them to the larger WAN. Fig. 1.15: Local Area Network Metropolitan Area Network (MAN): MAN or Metropolitan area Network covers a larger area than that of a LAN and smaller area as compared to WAN. It connects two or more computers that are apart but resides in the same or different cities. It covers a large geographical area and may serve as an ISP (Internet Service Provider). MAN is designed for customers who need a high- speed connectivity. Speeds of MAN ranges in terms of Mbps. It‘s hard to design and maintain a Metropolitan Area Network. The fault tolerance of a MAN is less and also there is more congestion in the network. It is costly and may or may not be owned by a single organization. The data transfer rate and the propagation delay of MAN is moderate. Devices used for transmission of data through MAN are: Modem and Wire/Cable. Examples of a MAN are the part of the telephone company network that can provide a high-speed DSL line to the customer or the cable TV network in a city.