🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

INTRODUCTION TO COMPUTER SCIENCE History of C: Developed at Bell Laboratories in the early seventies by Dennis Ritchie. Born out of two other languages – BCPL (Basic Control Programming Language) and B. C introduced such things as character types, floating...

INTRODUCTION TO COMPUTER SCIENCE History of C: Developed at Bell Laboratories in the early seventies by Dennis Ritchie. Born out of two other languages – BCPL (Basic Control Programming Language) and B. C introduced such things as character types, floating point arithmetic, structures, union, and the preprocessor. The principle objective was to devise a language that was easy enough to understand to be “high-level” – i.e. understood by general programmers, but low-level enough to be applicable to the writing of system-level software. The language should abstract the details of how the computer achieves its tasks in such a way as to ensure that C could be portable across different types of computers, thus allowing the UNIX operating system to be compiled on other computers with a minimum of re-writing. C as a language was in use by 1973, although extra functionality, such as new types, was introduced up until 1980. In 1978, Brain Kernighan and Dennis M.Ritchie wrote the seminal work. A formal ANSI standard for C was produced in 1989. In 1986, a descendant of C, called C++ was developed by Bjarne Stroustrup. Using C language scientific, business and system-level applications can be developed easily. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 1 Programming Using C History of Computer – 1st Computer: Abacus Name: Abacus 1st computer was invented around 4,000 years ago It was a wooden rack which has metal rods with beads mounted on them. Arithmetic calculations Still used in some countries like China, Russia, and Japan CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 2 Programming Using C 2nd Computer: Name: Napier's Bones Invented: John Napier (Merchiston, Scotland), in 1617. Mode-of-Operation: Manually Calculations: Addition, subtraction, Multiplication, Division, log() operations. Publication: "John Napier" (1617). "Rabdologiæ" (in Latin). Edinburgh, Scotland Link: https://en.wikipedia.org/wiki/Napier%27s_bones#cite_note-rabdologiae-1 Video Link: 1. https://www.youtube.com/watch?v=Ds21S3fCfYM 2. https://www.youtube.com/watch?v=NhZ9a6-3ig8 1550–1617 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 3 Programming Using C 3rd Computer: Name: Pascaline Invented: Blaise Pascal (France), in 1642. Mode-of-Operation: Mechanical Calculator Calculations: Addition, subtraction, Multiplication, and Division operations. Initially introduced carry mechanism in a Machine. Publication: Falk, Jim (November 14, 2014). "Blaise Pascal's Pascaline". Things that Count. Retrieved January 31, 2016. Links: https://en.wikipedia.org/wiki/Pascal%27s_calculator#cite_note-3 Video Links: 1. https://www.youtube.com/watch?v=3h71HAJWnVU 2. https://www.youtube.com/watch?v=Tu1xNSEemuc CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 4 Programming Using C 4th Computer: Name: Stepped Reckoner or Leibnitz wheel Invented: Gottfried Wilhelm Leibniz around 1672 and completed in 1694. Mode-of-Operation: Mechanical Calculator Calculations: Addition, subtraction, Multiplication, and Division operations. Publication: Kidwell, Peggy Aldritch; Williams, Michael R. (1992). The Calculating Machines: Their history and development. MIT Press., pp. 38–42, translated and edited from Martin, Ernst (1925). Die Rechenmaschinen und ihre Entwicklungsgeschichte. Germany: Pappenheim. Links: https://en.wikipedia.org/wiki/Stepped_reckoner#cite_note-Meyer1925- 1 Video Links: 1. Die Vierspezies-Rechenmaschine von Gottfried Wilhelm Leibniz - YouTube 2. https://www.youtube.com/watch?v=8qYQMce9y4o CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 5 Programming Using C 5th Computer: Name: Difference Engine Invented: Charles Babbage in the early 1822s. Mode-of-Operation: Mechanical Calculator. Steam-driven calculating machine. Calculations: Addition, subtraction, Multiplication, Division operations, Logarithmic and Trigonometric functions. Publication: Dasgupta, Subrata (2014). It Began with Babbage: The Genesis of Computer Science. Oxford University Press. p. 22. ISBN 978-0-19-930943-6. Links: https://en.wikipedia.org/wiki/Difference_engine#cite_note-4 Video Links: 1. https://www.youtube.com/watch?v=nmwSmwNF9XY 2. https://www.youtube.com/watch?v=py4S4JKnmZc&list=RDLVpy4S 4JKnmZc&start_radio=1&rv=py4S4JKnmZc&t=24 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 6 Programming Using C 5th Computer (Cont): Babbage's Difference Engine No. 1, https://www.youtube.com/watch?v=0anIyVGeWOI Babbage's Difference Engine No. 2, Part 1: The method of finite differences https://www.youtube.com/watch?v=PFMBU17eo_4&list=PLSOxgHhh6-o8ZuhRpL9ds8wM 4doxauru- Babbage's Difference Engine No. 2, Part 2: The Calculation Section https://www.youtube.com/watch?v=vdra5Ms__9s&list=PLSOxgHhh6-o8ZuhRpL9ds8wM4 doxauru-&index=2 Babbage's Difference Engine No. 2, Part 3: Interlocks https://www.youtube.com/watch?v=sklp9WutBhs&list=PLSOxgHhh6-o8ZuhRpL9ds8wM4 doxauru-&index=3 Babbage's Difference Engine No. 2, Part 4: The Control Section https://www.youtube.com/watch?v=9wId_ZePJVs&list=PLSOxgHhh6-o8ZuhRpL9ds8wM4 doxauru-&index=4 Babbage's Difference Engine No. 2, Part 5: Initialization https://www.youtube.com/watch?v=vgPLEhqFifg&list=PLSOxgHhh6-o8ZuhRpL9ds8wM4d oxauru-&index=5 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 7 Programming Using C 6th Computer: Name: Analytical Engine Invented: Charles Babbage in the early 1837s. Mode-of-Operation: Mechanical Calculator. It uses punch-cards inputs. It stores information in permanent memory. Calculations: Addition, subtraction, Multiplication, Division operations, Logarithmic and Trigonometric functions. It contains an arithmetic logic unit, control flow in the form of conditional branching and loops, and integrated memory It is the first design for a general-purpose computer Links: https://en.wikipedia.org/wiki/Analytical_Engine Video Links: 1. https://www.youtube.com/watch?v=_fyUtU6LVNY 2. https://www.youtube.com/watch?v=5rtKoKFGFSM CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 8 Programming Using C 7th Computer: Name: Tabulating Machine Invented: Herman Hollerith (American statistician) in the 1890s. Mode-of-Operation: Electromechanical tabulator Calculations: Designed to assist in summarizing information stored on punched cards. World's First Data Storage & Processing System. Links: https://en.wikipedia.org/wiki/Tabulating_machine Video Links: 1. https://www.youtube.com/watch?v=rxFvNaQ6YhY 2. https://www.youtube.com/watch?v=DGRSblPsBuM 3. THIS DAY IN TECH HISTORY- HOLLERITH TABULATING MACHINE - YouTube CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 9 Programming Using C 7th Computer: Name: Tabulating Machine Invented: Herman Hollerith (American statistician) in the 1890s. Mode-of-Operation: Electromechanical tabulator Calculations: Designed to assist in summarizing information stored on punched cards. World's First Data Storage & Processing System. Links: https://en.wikipedia.org/wiki/Tabulating_machine Video Links: 1. https://www.youtube.com/watch?v=rxFvNaQ6YhY 2. https://www.youtube.com/watch?v=DGRSblPsBuM 3. THIS DAY IN TECH HISTORY- HOLLERITH TABULATING MACHINE - YouTube CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 10 Programming Using C 8th Computer: Name: Differential Analyzer (1st electronic computer) Invented: Vannevar Bush in 1930s. Mode-of-Operation: Mechanical analog computer Calculations: Designed to solve differential equations by integration, using wheel-and-disc mechanisms to perform the integration. Applications: Fire-control system, Tide-predicting machine Links: https://en.wikipedia.org/wiki/Differential_analyser Video Links: 1. https://www.youtube.com/watch?v=fIsPFWSYf3c CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 11 Programming Using C Generations of Computers In 1946, electronic circuits are used in computers in place of gears, wheels, and other mechanical parts for various operations. From theirs onwards, the generation of computers is used to refer to the specific improvements in computer technology.. There are five generations of computers. In each new generation, the circuits became smaller and more advanced than the previous generation circuits. This miniaturization increases the speed & power of computers. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 12 Programming Using C 1st Generation of the Computer Basic component: Vacuum tubes. In these computers, vacuum tubes are used in the development of CPU and Memory. Period: 1946-1959 Speed: Very slow Size: Huge Name: ENIAC (Electronic Numerical Integrator And Computer). Cost: Expensive Invented: J. Presper Eckert and John Mauchly at the Operating System: Batch OS University of Pennsylvania (1946). I/O Devices: Punch card, Magnetic Tape, Paper Tape Occupancy: 1,800 s.f, # Vacuum tubes: 17,468 Weight: 50 tons Electricity: 200 KW Cost: $500,000. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 13 Programming Using C 1st Generation of the Computer 1. ENIAC ( Electronic Numerical Integrator and Computer) 2. EDVAC ( Electronic Discrete Variable Automatic Computer). This is the 1st computer that stores a program in binary. 3. UNIVAC ( Universal Automatic Computer) 4. IBM-701 5. IBM-702 6. IBM-650 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 14 Programming Using C 2nd Generation of the Computer Basic component: Transistor. In these computers, Transistors are used in the development of CPU and Memory. Period: 1959-1965 Some of the popular 2nd generation computers are: Speed: faster than Vacuum tubes 1. IBM 1620 2. IBM 7094 Size: Less than Vacuum tubes 3. CDC 1604 Cost: Less expensive than Vacuum tubes 4. CDC 3600 Operating System: Batch OS 5. UNIVAC 1108 Memory: Magnetic cores were used as the primary memory. Magnetic disc and tapes were used as the secondary storage. I/O Devices: Magnetic disc and tapes Assembly language and programming languages like COBOL and FORTRAN, and Batch processing and multiprogramming operating systems were used in these computers. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 15 Programming Using C 3rd Generation of the Computer Basic component: Integrated circuits (ICs). A single IC can pack huge number of transistors which increased the power of a computer and reduced the cost. The computers also became more reliable, efficient and smaller in size. Some of the popular third generation computers are The OS in these computers has remote processing, 1. IBM-360 series time-sharing, multi programming features. 2. Honeywell-6000 series The high-level programming languages like FORTRON-II TO IV, 3. PDP(Personal Data Processor) COBOL, PASCAL PL/1, ALGOL-68 were used in this generation 4. IBM-370/168 5. TDC-316 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 16 Programming Using C 4th Generation of the Computer Basic component: Very Large Scale Integrated (VLSI) circuits. A chip containing millions of transistors and other circuit elements. Some of the popular 4th generation computers are: Period: 1971-1980 1. DEC 10 2. STAR 1000 These chips made this generation computers more compact, powerful, fast and affordable. 3. PDP 11 4. CRAY-1(Super Computer) Operating System: Real time, Time sharing and Distributed 5. CRAY-X-MP(Super Computer) The programming languages like C, C++, DBASE were also used in this generation. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 17 Programming Using C 5th Generation of the Computer Basic component: The VLSI technology was replaced with ULSI (Ultra Large Scale Integration). Period: 1980 – till date Some of the popular fifth generation computers are: It made possible the production of microprocessor chips with ten 1. Desktop million electronic components 2. Laptop This generation computers used parallel processing hardware 3. NoteBook and AI (Artificial Intelligence) software. 4. UltraBook 5. ChromeBook The programming languages used in this generation were C, C++, Java,.Net, etc. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 18 Programming Using C Types of computer We can categorize computers in two ways: on the basis of data handling capabilities and size. On the basis of data handling capabilities, the computer is of three types: Analogue Computer Digital Computer Hybrid Computer 1) Analogue Computer Analogue computers are designed to process analogue data. Analogue data is continuous data that changes continuously and cannot have discrete values. We can say that analogue computers are used where we don't need exact values always such as speed, temperature, pressure and current. Analogue computers directly accept the data from the measuring device without first converting it into numbers and codes. They measure the continuous changes in physical quantity and generally render output as a reading on a dial or scale. Speedometers and mercury thermometers are examples of analogue computers CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 19 Programming Using C Advantages: It allows real-time operations and computation at the same time and continuous representation of all data within the range of the analogue machine. In some applications, it allows performing calculations without taking the help of transducers for converting the inputs or outputs to digital electronic form and vice versa. The programmer can scale the problem for the dynamic range of the analogue computer. It provides insight into the problem and helps understand the errors and their effects. Types of analogue computers: Slide Rules: It is one of the simplest types of mechanical analogue computers. It was developed to perform basic mathematical calculations. It is made of two rods. To perform the calculation, the hashed rod is slid to line up with the markings on another rod. Differential Analysers: It was developed to perform differential calculations. It performs integration using wheel-and-disc mechanisms to solve differential calculations. Castle Clock: It was invented by Al-Jarazi. It was able to save programming instructions. Its height was around 11 feet and it was provided with a display of time, the zodiac, and the solar and lunar orbits. This device also could allow users to set the length of the day as per the current season. Electronic Analogue Computer: In this type of analogue computer, electrical signals flow through capacitors and resistors to simulate physical phenomena. Here, the mechanical interaction of components does not take place. The voltage of the electrical signal generates the appropriate displays. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 20 Programming Using C 2) Digital Computer The digital computer is designed to perform calculations and logical operations at high speed. It accepts the raw data as input in the form of digits or binary numbers (0 and 1) and processes it with programs stored in its memory to produce the output. All modern computers like laptops, desktops including smartphones that we use at home or in the office are digital computers. Advantages of digital computers: It allows you to store a large amount of information and retrieve it easily whenever you need it. You can easily add new features to digital systems. Different applications can be used in digital systems just by changing the program without making any changes in the hardware The cost of hardware is less due to the advancement in IC technology. It offers high speed as the data is processed digitally. It is highly reliable as it uses error correction codes. Reproducibility of results is higher as the output is not affected by noise, temperature, humidity, and other properties of its components. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 21 Programming Using C 3) Hybrid Computer The Hybrid computer has features of both analogue and digital computers. It is fast like an analogue computer and has memory and accuracy like digital computers. It can process both continuous and discrete data. It accepts analogue signals and converts them into digital form before processing. So, it is widely used in specialized applications where both analogue and digital data is processed. For example, a processor is used in petrol pumps that converts the measurements of fuel flow into quantity and price. Similarly, they are used in airplanes, hospitals, and scientific applications. Advantages: Its computing speed is very high due to the all-parallel configuration of the analogue subsystem. It produces precise and quick results that are more accurate and useful. It has the ability to solve and manage big equations in real-time. It helps in online data processing. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 22 Programming Using C On the basis of size the computers are 1. Super Computer: A supercomputer is the most expensive and fastest type of computer that performs at or near the currently highest operational rate for computers. Example: Cray supercomputer These are employed for specialized applications that require immense amounts of mathematical calculations such as weather forecasting, nuclear energy research, mineral and petroleum exploration etc. 2. Mainframe computer: A mainframe computer supports a vast number of users to work simultaneously and remotely. Apart from providing a multi-user facility, it can process large amounts of data at very high speeds and support many input, output, and auxiliary storage devices. These computers are very large in size and expensive. The main difference between a supercomputer and a mainframe is that a supercomputer can execute a single program faster than a mainframe, whereas a mainframe uses its power to execute many programs concurrently. Example: IBM 370 and IBM 3090 3. Minicomputer: A minicomputer is powerful enough to be used by multiple users (between 10 to 100) but is smaller in size and memory capacity and cheaper than mainframes. Example: Digital Equipment Corporation VAX and the IBM AS/400 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 23 Programming Using C 4. Microcomputer: The microcomputer has been intended to meet the personal computing needs of an individual. It typically consists of a microprocessor chip, a memory system, interface units and various I/O ports, typically resident in a motherboard. 5. Desktop computer: A microcomputer sufficient to fit on a desk. 6. Laptop computer: A portable microcomputer with an integrated screen and keyboard. 7. Palmtop computer/Digital diary/Notebook/PDAs: A hand-sized microcomputer having no keyboard. The screen serves both as an input and output device CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 24 Programming Using C The Software Development Method: Programming is a problem-solving activity. Software Development Method 1. Specify the problem requirements. 2. Analyze the problem. 3. Design the algorithm to solve the problem. 4. Implement the algorithm. 5. Test and verify the completed program. 6. Maintain and update the program. 1. Problem: Specifying the problem requirements forces you to state the problem clearly and unambiguously and to gain a clear understanding of what is required for its solution. 2. Analysis: Analyzing the problem involves identifying the problem (a) The inputs, that is, the data you have to work with; (b) The outputs, that is, the desired results; and (c) any additional requirements or constraints on the solution. If steps 1 and 2 are not done properly, you will solve the wrong problem. Read the problem statement carefully, first, to obtain a clear idea of the problem, and second, to determine the inputs and outputs. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 25 Programming Using C Example: Compute and display the total cost of apples given the number of pounds of apples purchased and the cost per pound of apples. Problem Inputs quantity of apples purchased (in pounds) cost per pound of apples (in dollars per pound) Problem Output total cost of apples (in dollars) Total cost Unit cost Number of units Total cost of apples Cost per pound Pounds of apples Abstraction is the process of modeling a problem by extracting the essential variables and their relationships. 3. Design: A list of steps for solving a problem is called Algorithm. The top-down design is breaking a problem into its major subproblems and then solving the subproblems. Most computer algorithms consist of at least the following subproblems. The algorithm for a programming problem is as follows 1. Get the data. 2. Perform the computations. 3. Display the results. Stepwise refinement is the development of a detailed list of steps to solve a particular step in the original algorithm. Desk checking is the step-by-step simulation of the computer execution of an algorithm. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 26 Programming Using C 4. Implementation: Implementing the algorithm (step 4 in the software development method) involves writing it as a program. You must convert each algorithm step into one or more statements in a programming language. 5. Testing: Testing and verifying the program requires testing the completed program to verify that it works as desired. Run the program several times using different sets of data to make sure that it works correctly for every situation provided for in the algorithm. 6. Maintenance: Maintaining and updating the program involves modifying a program to remove previously undetected errors and to keep it up-to-date as government regulations or company policies change. Example: Converting miles to kilometers 1. Problem: Study some maps that give distances in kilometers and some that use miles. 2. Analysis: Consider the problem input is the distance in miles and the problem output is the distance in kilometers. Then know the relationship between miles and kilometers. Consulting a metric table shows that one mile equals 1.609 kilometers. Data requirement : Problem Input miles Problem Output kms Relevant Formula 1 mile = 1.609 kilometers CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 27 Programming Using C 3. Design: Next, formulate the algorithm that solves the problem. Begin by listing the three major steps, or subproblems, of the algorithm. Algorithm: 1. Get the distance in miles. 2. Convert the distance to kilometers. 3. Display the distance in kilometers. Algorithm with refinements: 1. Get the distance in miles. 2. Convert the distance to kilometers. 2.1 The distance in kilometers is 1.609 times the distance in miles. 3. Display the distance in kilometers. 4. Implementation: To implement the solution, write the algorithm as a C program. 5. Testing: In this run, a distance of 10.0 miles is converted to 16.09 kilometers, as it should be. To verify that the program works properly, enter a few more test values of miles. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 28 Programming Using C Electronic computers now and then : The first electronic computer was built in the late 1930s by Dr.John Atanasoff and Clifford Berry at lowa State University. The first large-scale, general-purpose electronic digital computer, called the ENIAC, was completed in 1946 at the University of Pennsylvania with funding from the U.S. Army. Weighing 30 tons and occupying a 30-by-50-foot space. Today’s technology use the entire circuitry of a computer processor can be packaged in a single electronic component called a computer or microprocessor chip, which is less than one-fourth the size of a standard postage stamp. The Intel Atom processor chip contains the full circuitry of a central processing unit in an integrated circuit whose small size and low power requirements make it suitable for use in mobile internet devices A computer chip (microprocessor chip) a silicon chip containing the circuitry for a computer processor CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 29 Programming Using C Today’s some of the common computers are a a. Desktop Computer, iMac. b. Hewlett Packard Laptop. c. iPad d. Android phone Modern computers are categorized according to their size and performance. Personal computers are used by a single person at a time. Large real-time transaction processing systems, such as ATMs and other banking networks, and corporate reservations systems for hotels, airlines, and rental cars use mainframes , very powerful and reliable computers. The largest capacity and fastest computers are called supercomputers used in research and weather forecasting. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 30 Programming Using C Computer: A computer is a programmable electronic machine designed to take input, perform prescribed arithmetic and logical operations at fast speeds, and provide the output of these operations. COMPUTER is an acronym for “Common Operating Machine Purposely Used for Technological and Education Research”. Elements of a Computer: 1. Hardware: The equipment used to perform the necessary computations and includes the central processing unit (CPU), monitor, keyboard, mouse, printer, and speakers. 2. Software: It consists of the programs that enable us to solve problems with a computer by providing it with lists of instructions to perform. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 31 Programming Using C Computer Hardware: Other than cost, size, and capabilities, modern computers resemble the following components Main memory Secondary memory – hard disks, CDs, DVDs, and flash drives. Central processing unit Input devices – keyboards, mouses, touch pads, scanners, joysticks, Output devices – monitors, printers, and speakers. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 32 Programming Using C 1. Memory: Computer memory is the storage space in the computer, where data is to be processed and instructions required for processing are stored. The memory is divided into a large number of small parts called cells. Each location or cell has a unique address, which varies from zero to memory size minus one. The computer memory consists of 1000 memory cells with addresses 0 through 999. The information is stored in a memory cell, either a program instruction or data called the contents of a memory cell. The computer’s ability to store program instructions in the main memory for execution is called the stored program concepts. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 33 Programming Using C Bits and Bytes: At the smallest scale in the computer, information is stored as bits and bytes. Bit: A bit is the smallest possible unit of data that a computer can recognize or use. The computer usually uses bits in groups. Everything in a computer is 0's and 1's. A "bit" is atomic: the smallest unit of storage A bit stores just a 0 or 1 "In the computer, it's all 0's and 1's"... bits Byte: The group of eight bits is called a byte. Half a byte is called a nibble. One byte = collection of 8 bits e.g. 0 1 0 1 1 0 1 0 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 34 Programming Using C The following table shows the conversion of Bits and Bytes Byte Value Bit Value 1 Byte 8 Bits 1024 Bytes 1 Kilobyte 1024 Kilobytes 1 Megabyte 1024 Megabytes 1 Gigabyte 1024 Gigabytes 1 Terabyte 1024 Terabytes 1 Petabyte 1024 Petabytes 1 Exabyte 1024 Exabytes 1 Zettabyte 1024 Zettabytes 1 Yottabyte 1024 Yottabytes 1 Brontobyte 1024 Brontobytes 1 Geopbytes CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 35 Programming Using C Storage and Retrieval of Information in Memory: Data storage is the setting of the individual bits of a memory cell to 0 or 1, destroying its previous contents. Data retrieval is the copying of the contents of a particular memory cell to another storage area. Main Memory: The main memory is the fundamental storage unit in a computer system that stores programs, data, and results. 1. Random access memory (RAM) is RAM ROM the part of the main memory that It is volatile memory. It is non-volatile memory. temporarily stores programs, The contents are temporary; data is The contents are permanent; data data, and results. lost when electricity supply is lost. is not lost even when power is switched off. 2. Read-only memory (ROM) is the Available in small storage capacity. Available in high storage capacity. part of main memory that permanently stores programs Processing speed is high. Processing speed is low. or data. User-defined programs can be Generally, operating system stored. supporting programs can be stored. Cost is very high. Cost effective. It is of two types, SRAM and DRAM. It comes in different types such as PROM, EPROM, EEPROM and flash memory. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 36 Programming Using C Secondary Storage Devices: This type of memory is also known as external memory or non-volatile. It is slower than the main memory. These are used for storing data/information permanently. CPU directly does not access these memories, instead they are accessed via input-output routines. The contents of secondary memories are first transferred to the main memory, and then the CPU can access it. For example, disk, CD-ROM, DVD, etc. 1. Hard disk: thin platter of metal or plastic on which data are represented by magnetized spots arranged in tracks. 2. Optical drive: These devices that use a laser to access or store data on a CD (compact disks) or DVD (digital versatile disks). 3. Flash drive device that plugs into a USB port and stores data bits as trapped electrons. Information stored on a disk is organized into separate collections called files. A list of the names of files stored on a disk is a directory. A list of the names of files that relate to a particular topic is a subdirectory. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 37 Programming Using C 2. Central Processing Unit: CPU consists of the following features CPU is considered the brain of the computer. CPU performs all types of data processing operations. It stores data, intermediate results, and instructions (program). It controls the operation of all parts of the computer. It coordinates all computer operations and performs arithmetic and logical operations on data. Fetching an instruction is retrieving an instruction from the main memory. A CPU’s current instruction and data values are stored temporarily inside the CPU in special high-speed memory locations called registers. Some computers have multiple CPUs ( multiprocessors ) or a multi-core CPU. These computers are capable of faster speeds because they can process different sets of instructions at the same time. CPU itself has the following three components. Memory or Storage Unit Control Unit ALU(Arithmetic Logic Unit) CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 38 Programming Using C CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 39 Programming Using C Control Unit: This unit controls the operations of all parts of the computer but does not carry out any actual data processing operations. The functions of this unit are − It is responsible for controlling the transfer of data and instructions among other units of a computer. It manages and coordinates all the units of the computer. It obtains the instructions from the memory, interprets them, and directs the operation of the computer. It communicates with Input/Output devices for the transfer of data or results from storage. It does not process or store data. ALU (Arithmetic Logic Unit): This unit consists of two subsections namely, Arithmetic Section – The function of the arithmetic section is to perform arithmetic operations like addition, subtraction, multiplication, and division. All complex operations are done by making repetitive use of the above operations. Logic Section – The function of the logic section is to perform logic operations such as comparing, selecting, matching, and merging data. Program Counter: A program counter (PC) is a CPU register in the computer processor which has the address of the next instruction to be executed from memory. It is a digital counter needed for faster execution of tasks as well as for tracking the current execution point.. A program counter is also known as an instruction counter, instruction pointer, instruction address register or sequence control register. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 40 Programming Using C Types of CPU: Some of the basic types of CPUs are described below: Single Core CPU: Single Core is the oldest type of computer CPU, which was used in the 1970s. It has only one core to process different operations. It can start only one operation at a time; the CPU switches back and forth between different sets of data streams when more than one program runs. So, it is not suitable for multitasking as the performance will be reduced if more than one application runs. The performance of these CPUs is mainly dependent on the clock speed. It is still used in various devices, such as smartphones. Dual Core CPU: As the name suggests, Dual Core CPU contains two cores in a single Integrated Circuit (IC). Although each core has its own controller and cache, they are linked together to work as a single unit and thus can perform faster than the single-core processors and can handle multitasking more efficiently than Single Core processors. Quad Core CPU: This type of CPU comes with two dual-core processors in one integrated circuit (IC) or chip. So, a quad-core processor is a chip that contains four independent units called cores. These cores read and execute the instructions of the CPU. The cores can run multiple instructions simultaneously, thereby increasing the overall speed for programs that are compatible with parallel processing. Quad Core CPU uses a technology that allows four independent processing units (cores) to run in parallel on a single chip. Thus by integrating multiple cores in a single CPU, higher performance can be generated without boosting the clock speed. However, the performance increases only when the computer's software supports multiprocessing. The software which supports multiprocessing divides the processing load between multiple processors instead of using one processor at a time. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 41 Programming Using C 3. Input/Output Devices : Keyboard: It is an input device.. When you press a letter or digit key on a keyboard, that character is sent to main memory and is also displayed on the monitor at the position of the cursor, a moving place marker (often a blinking line or rectangle). A computer keyboard has keys for letters, numbers, and punctuation marks plus some extra keys for performing special functions. The twelve function keys along the top row of the keyboard are labeled F1 through F12. Mouse: It is an input device that moves its cursor on the computer screen to select an operation. select an operation by moving the mouse cursor to a word or icon (picture) that represents the computer operation you wish to perform and then pressing a mouse button to activate the operation selected. Monitor: It is an output device and provides a temporary display of the information that appears on its screen. Printer: : It is an output device. The hard copy (a printed version) of some information can be collected by using the printer. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 42 Programming Using C 4. Computer Networks: A computer network is a system in which multiple computers are connected to each other to share information and resources. Characteristics of a Computer Network are as follows Share resources from one computer to another. Create files and store them in one computer and access those files from the other computer(s) connected over the network. Connect a printer, scanner, or fax machine to one computer within the network and let other computers of the network use the machines available over the network. Local area network (LAN) computers, printers, scanners, and storage devices are connected by cables for intercommunication. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 43 Programming Using C A computer that controls access to a secondary storage device such as a large hard disk is called a file server. A network that links many individual computers and local area networks over a large geographic area is called a wide area network (WAN). The most widely used aspect of the Internet is the World Wide Web (WWW), the universe of Internet-accessible resources that are navigable through the use of a graphical user interface (GUI). A modem ( modulator/ demodulator) converts binary computer data into audio tones that can be transmitted to another computer over a normal telephone circuit. DSL connection (digital subscriber line) is a high-speed Internet connection that uses a telephone line and does not interfere with simultaneous voice communication on the same line. Cable Internet access is the two-way highspeed transmission of Internet data through two of the hundreds of channels available over the coaxial cable that carries cable television signals CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 44 Programming Using C CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 45 Programming Using C Computer Software: Software is a set of programs, which is designed to perform a well-defined function. A program is a sequence of instructions written to solve a particular problem. 1. Operating Systems: The collection of computer programs that control the interaction of the user and the computer hardware is called the operating system (OS). Loading the operating system into memory is called booting the computer. Some of the operating system’s many responsibilities: 1. Communicating with the computer user: receiving commands and carrying them out or rejecting them with an error message. 2. Managing allocation of memory, processor time, and of other resources for various tasks. 3. Collecting input from the keyboard, mouse, and other input devices, and providing this data to the currently running program. 4. Conveying program output to the screen, printer, or other output devices. 5. Accessing data from secondary storage. 6. Writing data to secondary storage. 7. The operating system of a computer with multiple users must verify each individual’s right to use the computer and must ensure that each user can access only data for which he or she has proper authorization. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 46 Programming Using C Widely used operating system families categorized by user interface type are as follows Command-Line Interface Graphical User Interface UNIX Macintosh OS MS-DOS Windows VMS OS/2 Warp UNIX + X Window System OS that uses a command-line interface displays a brief message, called a prompt, that indicates its readiness to receive input, and the user then types a command at the keyboard. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 47 Programming Using C Operating systems with a graphical user interface provide the user with a system of icons and menus. To issue commands, the user moves the mouse or touch pad cursor to point to the appropriate icon or menu selection and pushes a button once or twice. Accessing Secondary Storage Devices through Windows. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 48 Programming Using C 2. Application Software: Application programs are developed to assist a computer user in accomplishing specific tasks. Example: Word-processing application such as Microsoft Word or OpenOffice.org Spreadsheet application such as Microsoft Office Excel Database management application such as Microsoft Office Access or dBASE Install software make an application available on a computer by copying it to the computer’s hard drive. 3. Computer languages: There are mainly three different languages with the help of which we can develop computer programs. Two Basic Types of Computer Language Low-Level Languages: A language that corresponds directly to a specific machine High-Level Languages: Any language that is independent of the machine Low-Level Languages: These languages are either machine codes or are very close to them. A computer cannot understand instructions given to it in high-level languages or in English. It can only understand and execute instructions given in the form of machine language, i.e. binary. There are two types of low-level languages: Machine Language Assembly Language CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 49 Programming Using C Machine Language: It is the binary number codes understood by a specific CPU. Machine language is difficult for human beings to understand as it comprises combination of 0’s and 1’s. Collection of binary numbers is also called machine language. Each CPU has its own specific machine language. The processor reads and handles instructions, which tell the CPU to perform a simple task. Instructions are comprised of a certain number of bits. If instructions for a particular processor are 8 bits, for example, the first 4 bits part (the opcode) tells the computer what to do and the second 4 bits (the operand) tells the computer what data to use. 01001000 01100101 01101100 01101100 01101111 00100001 Advantages: Machine language makes fast and efficient use of the computer. It requires no translator to translate the code. It is directly understood by the computer. Disadvantages: All operation codes have to be remembered All memory addresses have to be remembered. It is hard to amend or find errors in a program written in the machine language. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 50 Programming Using C Assembly Language: Assembly language was developed to overcome some of the many inconveniences of machine language. This is another low-level but very important language in which operation codes and operands are given in the form of alphanumeric symbols instead of 0’s and l’s. These alphanumeric symbols are known as mnemonic codes and can combine in a maximum of five-letter combinations, e.g. ADD for addition, SUB for subtraction, START, LABEL etc. Because of this feature, assembly language is also known as ‘Symbolic Programming Language.’ Advantages: Assembly language is easier to understand and use as compared to machine language. It is easy to locate and correct errors. It is easily modified. Disadvantages: Like machine language, it is also machine dependent/specific. Since it is machine dependent, the programmer also needs to understand the hardware. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 51 Programming Using C High-level languages: These are machine-independent programming language that combines algebraic expressions and English symbols. High-level languages are basically symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes. Each instruction in the high-level language is translated into many machine language instructions that the computer can understand. Advantages: High-level languages are user-friendly. They are similar to English and use English vocabulary and well-known symbols. They are easier to learn. They are easier to maintain. They are problem-oriented rather than 'machine'-based. A program written in a high-level language can be translated into many machine languages and can run on any computer for which there exists an appropriate translator. The language is independent of the machine on which it is used i.e. programs developed in a high-level language can be run on any computer text. Disadvantages: A high-level language has to be translated into the machine language by a translator, which takes up time. The object code generated by a translator might be inefficient compared to an equivalent assembly language program. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 52 Programming Using C CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 53 Programming Using C The software that translates a high-level language program into machine language is called a compiler. Both the input to and the output from the compiler (when it is successful) are programs. The input to the compiler is a source file containing the text of a high-level language program. The grammar rules of a programming language are called syntax. Object file is the file of machine language instructions that is the output of a compiler. Linker is the software that combines object files and resolves crossreferences to create an executable machine language program. Example: Source file : myprog.c Object file: myprog. obj Linker: myprog.exe Integrated development environment (IDE) is the software package combining a word processor, compiler, linker, loader, and tools for finding errors. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 54 Programming Using C CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 55 Programming Using C Executing a program: Special program instructions are used for entering or scanning a program’s data (called input data ) into memory. After the input data have been processed, instructions for displaying or printing values in memory can be executed to display the program results. The lines displayed by a program are called the program output. The flow of Information During Program Execution is as follows Example: Executing a water bill program stored in memory The first step of the program scans into memory data that describe the amount of water used. In step 2, the program manipulates the data and stores the results of the computations in memory. In the final step, the computational results are displayed as a water bill. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 56 Programming Using C INTRODUCTION TO COMPUTER SCIENCE Algorithm Computer scientist Niklaus Wirth stated that Program = Algorithms + Data An algorithm is an effective procedure for solving a problem in a finite number of steps. Algorithms may be represented in various ways and are as follows 1. Step-form 2. Pseudo-code 3. Flowchart 4. Nassi-Schneiderman Step-form: The procedure of solving a problem is stated with written statements. Each statement solves a part of the problem and these together complete the solution. The step form uses just normal language to define each procedure. Every statement, that defines an action, is logically related to the preceding statement. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 57 Programming Using C Pseudo-code : It is a written form representation of the algorithm. The pseudo-code, which is in human language, tends toward more precision by using a limited vocabulary. Flowchart and Nassi-Schneiderman : These are graphically oriented representation forms. They use symbols and language to represent a sequence, decision, and repetition of actions Key Features of an Algorithm and the Step-form: An algorithm can be stated using three basic constructs as follows 1. Sequence (also known as a process): Sequence means that each step or process in the algorithm is executed in the specified order. 2. The decision constructs— if... then, if... then... else... (Decision (also known as selection)) In algorithms the outcome of a decision is either true or false; there is no state in between. The outcome of the decision is based on some condition that can only result in a true or false value. if today is Friday then collect pay is a decision and the decision takes the general form: if proposition then process CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 58 Programming Using C The decision can also be stated as: if proposition then process1 else process2 This is the if … then … else … form of the decision. This means that if the proposition is true then execute process1, else, or otherwise, execute process2. The first form of the decision if proposition then process has a null else, that is, there is no else. 3. The repetition constructs— repeat and while (Repetition (also known as iteration or looping)) Repetition can be implemented using constructs like the repeat loop, while loop, and if.. then.. goto.. loop. The Repeat loop is used to iterate or repeat a process or sequence of processes until some condition becomes true. It has the general form: Repeat Process1 Process2.............. ……….. ProcessN Until proposition CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 59 Programming Using C If the condition is false, the process or the sequence of processes is not executed. The general form of while loop is: while proposition begin Process 1 Process 2 ……….. ………... Process N end The if.. then goto.. is also used to repeat a process or a sequence of processes until the given proposition is false. The general form of if.. then goto.. is: Process1 Process2 ………. ………. ProcessN if proposition then goto Process1 CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 60 Programming Using C 4. Termination: Termination means the action of closing. A well-designed algorithm has a termination. 5. Correctness: Correctness of the algorithm means how easily its logic can be argued to meet the algorithm’s primary goal. Variable: Data is a symbolic representation of value. A variable, which has a name, is a container for a value that may vary during the execution of the program. Almost every algorithm contains data and usually, the data is ‘contained’ in what is called a variable. The variable is a container for a value that may vary during the execution of the program. Variables and data types: The data used in algorithms can be of different types. The simplest types of data that an algorithm might use are numeric data, e.g., 12, 11.45, 901, etc. alphabetic or character data such as ‘A’, ‘Z’, or ‘This is alphabetic’ Logical data, that is, propositions with true/false values. The naming of variables: Choose meaningful names for variables in algorithms to improve the readability of the algorithm or program. There are no hard and fast rules about how variables should be named but there are many conventions. It is a good idea to adopt a conventional way of naming variables. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 61 Programming Using C Subroutines: A subroutine is a logical collection of instructions that is invoked from within a larger program to perform a specific task. The subroutine is relatively independent of the remaining statements of the program that invokes it. A subroutine can be invoked several times from several places during a single execution of the invoking program. After completing the specific task, a subroutine returns to the point of invocation in the larger program. Some examples of developing algorithms using step-form 1. Each algorithm will be logically enclosed by two statements START and STOP. 2. To accept data from the user, the INPUT or READ statements are to be used. 3. To display any user message or the content in a variable, a PRINT statement will be used. Note that the message will be enclosed within quotes. 4. There are several steps in an algorithm. Each step results in an action. The steps are to be acted upon sequentially in the order they are arranged or directed. 5. The arithmetic operators that will be used in the expressions are i. ‘←’ ….Assignment (the left-hand side of ‘←’ should always be a single variable) Example: The expression x ← 6 means that a value 6 is assigned to the variable x. In terms of memory storage, it means a value of 6 is stored at a location in memory which is allocated to the variable x. CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 62 Programming Using C ii. ‘+’….. Addition Example: The expression z ← x + y means the value contained in variable x and the value contained in variable y is added and the resulting value obtained is assigned to the variable z. iii. ‘–’….. Subtraction Example: The expression z ← x – y means the value contained in variable y is subtracted from the value contained in variable x and the resulting value obtained is assigned to the variable z. iv. ‘*’….. Multiplication Example: Consider the following expressions written in sequence: x←5 y←6 z←x*y The result of the multiplication between x and y is 30. This value is therefore assigned to z. v. ‘/’….. Division Example: The following expressions written in sequence illustrate the meaning of the division operator: x ← 10 y ←6 z ← x/y CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 63 Programming Using C The quotient of the division between x and y is 1 and the remainder is 4. When such an operator is used the quotient is taken as the result whereas the remainder is rejected. So here the result obtained from the expression x/y is 1 and this is assigned to z. 6. In propositions, the commonly used relational operators will include i. ‘>’ ….. Greater than ii. ‘= B AND B >= C NUMBERS” 5. R ←N – Q * 2 THEN PRINT A 3. INPUT A, B 6. IF R = 0 THEN PRINT “N IS 5. IF B >= C AND C >= A 4. IF A > B THEN PRINT “A IS EVEN” THEN PRINT B GREATER THAN B” 7. IF R != 0 THEN PRINT “N IS ELSE 5. IF B > A THEN PRINT “B IS ODD” PRINT C GREATER THAN A” 8. STOP 6. STOP 6. IF A = B THEN PRINT “BOTH ARE EQUAL” 7. STOP CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 65 Programming Using C Algorithm uses a variable MAX to Algorithm uses a nested if Take three sides of a triangle as input and check store the largest number construct. whether the triangle can be drawn or not. 1. START 1. START 1. START 2. PRINT “ENTER THREE 2. PRINT “ENTER THREE 2. PRINT “ENTER LENGTH OF THREE SIDES NUMBERS” NUMBERS” OF A TRIANGLE” 3. INPUT A, B, C 3. INPUT A, B, C 3. INPUT A, B, C 4. MAX ← A 4. IF A > B THEN 4. IF A + B > C AND B + C > A AND A + C > B 5. IF B > MAX THEN MAX ← B IF A > C THEN THEN 6. IF C > MAX THEN MAX ← C PRINT A PRINT “TRIANGLE CAN BE DRAWN” 7. PRINT MAX ELSE ELSE 8. STOP PRINT C PRINT “TRIANGLE CANNOT ELSE IF B > C THEN BE DRAWN”: GO TO 5 PRINT B 5. STOP ELSE PRINT C 5. STOP CSE 108/ CSC 108 - Introduction to Computer Science and 22-01-2023 66 Programming Using C Algorithm for incrementing the value Algorithm for the addition of N given of a variable that starts with an initial numbers. value of 1 and stops when the value 1. START becomes 5. 2. PRINT “HOW MANY NUMBERS?” 1. START 3. INPUT N 2. C ← 1 4. S← 0 1. START 3. WHILE C 0 AND N

Use Quizgecko on...
Browser
Browser