Computer Programming Unit-1 PDF
Document Details
Uploaded by ChasteLouisville
Marwadi University
Tags
Related
- Computer Fundamentals Lecture Notes PDF
- Computer Science Textbook for Class XI (PDF)
- Chapter 1: Introduction to Computers and Programming PDF
- Lecture 1: Introduction to C++ Programming and Computer Science PDF
- Chapter 1: Introduction to Computers and Programming PDF
- Computer Programming Fundamentals PDF
Summary
This document is an introduction to computer programming, focusing on the different types of hardware and software components, and covering concepts such as binary and decimal conversions. It delves into various aspects of computer science principles. The document includes an overview of computer components, their functions, and types of programming languages.
Full Transcript
01CE1101 Computer Programming Unit – 1 Introduction Highlights Basic organization of a Computer Low-level & high-level Languages Binary & Decimal conversion Flowchart, Algorithm Problem solving using flowchart and algorithm...
01CE1101 Computer Programming Unit – 1 Introduction Highlights Basic organization of a Computer Low-level & high-level Languages Binary & Decimal conversion Flowchart, Algorithm Problem solving using flowchart and algorithm 2 Introduction of Computer Computer is an electronic device used for storing, processing, and retrieving the information. Computer has mainly two components: Hardware: Software: 3 Hardware: Hardware refers to the physical parts of a computer. The term hardware also refers to mechanical device that makes up computer. User can see and touch the hardware components. Examples of hardware are CPU, keyboard, mouse, hard disk, etc... 4 Software : A set of instruction in a logical order to perform a meaningful task is called program and a set of program is called software. It tell the hardware how to perform a task. Types of software System software It is designed to operate the computer hardware efficiently. Provides and maintains a platform for running application software. Examples: Windows, Linux, Unix etc. Application software It is designed to help the user to perform general task such as word processing, web browser etc. Examples: Microsoft Word, Excel, PowerPoint etc 5 Advantages of Computer Multitasking Speed Cost/ Stores huge Accuracy Communication Reduces workload Reliability 6 Disadvantages of computer Virus and hacking attacks Online Cyber Crimes Reduction in employed opportunity High Cost Increases waste and impacts the environment Health Problems 7 Block Diagram of Computer Central Processing Unit Control Unit (CU) Input Section Output Section (Keyboard, Arithmetic (Monitor, Printer, Mouse, Scanner, Logic Unit etc.) etc.) (ALU) Primary Memory (RAM, ROM, etc.) Secondary Memory (Hard disk, Pen drive, etc.) 8 Central Processing Unit (CPU) Central Processing Unit is the brain of the computer. It is also known as a processor. The main purpose of the CPU is to execute the programs and stored in the memory. It consists main three parts: ALU, Main memory, C.U ALU (Arithmetic Logical Unit) MU (Memory Unit) C.U (Control Unit) 9 ALU (Arithmetic Logical Unit) ALU (Arithmetic Logical Unit): It Performs Arithmetical Operations like addition, subtraction, multiplication, division and also performs logical operations like AND, OR, NOT operations. 10 C.U (Control Unit) C.U (Control Unit): It controls all activities of C.P.U and other connected devices. Its main job is to fetch instructions from main memory and execute it over C.P.U. It has main two parts: IR (Instruction Register): It contains instructions which are in execution. PC (Program Counter): It contains the address of next instruction for execution. 11 MU (Memory Unit) Main memory: It is also known as primary memory or internal memory. It is used to store instructions and other information in Binary form (0 or 1). This memory is also known as semiconductor memory because it is made by semiconductor material like silicon. It is divided into various types: RAM (Random Access Memory) ROM (Read Only Memory) PROM ( Programmable Read Only Memory) EPROM (Erasable Programmable Read Only Memory) EEPROM (Electrically Erasable Programmable Read Only Memory) 12 RAM RAM stands for random access memory, and it's one of the most fundamental elements of computing. RAM is a temporary memory bank where your computer stores data it needs to retrieve quickly. RAM is essentially short term memory where data is stored as the processor needs it. This isn't to be confused with long-term data that's stored on your hard drive, which stays there even when your computer is turned off. 13 ROM ROM (read-only memory) is a non-volatile memory type. It's used to store the start-up instructions for a computer, also known as the firmware. This means it receives data and permanently writes it on a chip, and it lasts even after you turn off your computer. The data is coded to not be overwritten, so it's used for things like your printer software or your startup programs. 14 Difference between RAM and ROM 15 Input Section Input section of a computer consists of the devices which are used to enter the information into the computer from outside world. The devices used to enter the input the computer are called input devices. Example: Keyboard, Mouse, touch screen etc... 16 Output Section Output section of a computer consists of devices used to send the information to the outside world. The devices used for output are known as output devices. Example: Monitor, Printer, LCD, Speakers etc... 17 Secondary Storage Devices It is also known as Auxiliary memory or external memory. This is permanent memory. User can stored data permanently on this memory. It can be modified. Example: hard disk, floppy disk, CD, DVD, pen drive, etc... 18 Hardware and Software Hardware Software Physical Component Logical component Can see and touch Cannot see and touch It is divided into three parts : It is divided into two categories: microprocessor , motherboard System Software & Application & Other peripherals. Software. It is electronics components, so It is the collection of programs, it is designed by the electronics so it is designed by computer engineer. engineer. For maintenance, screw driver, For maintenance, all types of tester, brush is required. software testing is required. For design, it requires special For design, it requires system software (chip designing software. software) 19 Types of Computer Languages Low level language Assembly language Higher level language 20 Low level language Machine level language OR Low level language It is language of 0’s and 1's. Computer directly understand this language. Computers are made of many tiny switches that can be either on or off. When a switch is on, it is represented by a 1. When it is off, it is represented by a 0. These 1s and 0s are called bits. Bits are the fundamental language of nearly all computers and every program must be translated into bits before it can be executed by the computer. 21 Assembly language It uses short descriptive words (MNEMONIC) to represent each of the machine language instructions. It requires a translator known as assembler to convert assembly language into machine language so that it can be understood by the computer. Examples: 8085 Instruction set 22 Higher level language It is a machine independent language. We can write programs in English like manner and therefore easier to learn and use. Examples: C, C++, JAVA etc... 23 Translator The translator translates high level language into low level language. There are three types of translator: Assembler Compiler Interpreter 24 Assembler: Assembler converts assembly language into machine level language. Compiler: Compiler converts high level language into low level language. First Compiler accept high level program as input. After it checks the program for any errors. If there is no error in the program then compiler convert High level program into low level language. If there is any errors then compiler display list of errors. 25 Interpreter: Interpreter converts high level language into low level language. First Interpreter accept high level program as input. After it checks the first statement of the program for error, if there is not any error in the first statement then interpreter convert the statement into low level language. If there is any error then it displays that error. This process is repeated until all the statement in the program is checked. 26 Compiler and Interpreter Compiler Interpreter It checks the whole program at a It checks the program line by line time and then display the list of and stops checking whenever error errors. occurs. It converts whole source code into It converts source code into object object code. code line by line. After completion, source code is not For, every execution of line, source required. code is required. The object code of program It generates the object code for generated when the program is each line immediately if that line is error free. error free. The execution process of program is The execution process of program is faster. faster. 27 Common Number Systems System Base Symbols Used by Used in Humans? Computers ? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 No Yes Octal 8 0, 1, … 7 No No Hexa- 16 0, 1, … 9, No No decimal A, B, … F Conversion among Bases Possibilities Decimal Octal Binary Hexadecimal Example 2510 = 110012 = 318 = Base 19 Decimal to Binary Decimal Binary Technique Divide by two, keep track of the remainder First remainder is bit 0 (LSB, least-significant bit) Second remainder is bit 1 and so on Example (Decimal to Binary) 12510 = ?2 2 12 1 2 5 62 0 2 31 1 2 15 1 2 7 1 2 3 1 2 1 1 0 12510 1111101 = 2 Example (Decimal to Binary) 0.687510 = ?2 integ fractio er n 0.6875 x 1.375 1 + 0.375 2= 0.3750 x 0 0.750 0 0 + 0.750 2= 0.7500 x 0 1.500 0 1 + 0.500 2= 0.5000 x 0 1.000 0 1 + 0.000 2= 0 0 0.687510 0.10112 = Exercise (32)10 = (100000 )2 (555)10 = (1000101011 )2 (12999)10 = (11001011000111 )2 (157.63)10 = (10011101.1010000101 )2 (64.125)10 = (1000000.001 )2 (157.63)10 To convert decimal number 157.63, we convert its integer and fraction part individually and then add them to get the equivalent binary number, as below: To convert integer 157 to binary, follow these steps: Divide 157 by 2 keeping notice of the quotient and the remainder. Continue dividing the quotient by 2 until you get a quotient of zero. Then just write out the remainders in the reverse order to get the equivalent binary number. Continue.. 157 / 2 = 78 with remainder 1 78 / 2 = 39 with remainder 0 39 / 2 = 19 with remainder 1 19 / 2 = 9 with remainder 1 9 / 2 = 4 with remainder 1 4 / 2 = 2 with remainder 0 2 / 2 = 1 with remainder 0 1 / 2 = 0 with remainder 1 Here is the answer to 157 decimal to binary number: 10011101 Continue… For converting decimal fraction 0.63 to binary number, follow these steps: Multiply 0.63 by 2 keeping notice of the resulting integer and fractional part. Continue multiplying by 2 until you get a resulting fractional part equal to zero (we calculate up to ten digits). Then just write out the integer parts from the results of each multiplication to get equivalent binary number. Continue.. 0.63 × 2 = 1 + 0.26 0.26 × 2 = 0 + 0.52 0.52 × 2 = 1 + 0.04 0.04 × 2 = 0 + 0.08 0.08 × 2 = 0 + 0.16 0.16 × 2 = 0 + 0.32 0.32 × 2 = 0 + 0.64 0.64 × 2 = 1 + 0.28 0.28 × 2 = 0 + 0.56 0.56 × 2 = 1 + 0.12 Here is the answer to 0.63 decimal to binary number: 0.1010000101 Therefore, decimal number 157.63 converted to binary is equal: 10011101.1010000101 Binary to Decimal Binary Decimal Technique Multiply each bit by 2n, where n is the “weight” of the bit The weight is the position of the bit, starting from 0 on the right Add the results Example (Binary to Decimal) 1 0 1 0 1 1 1x + 0x + 1x + 0x + 1x + 1x 25 32 + 204 + 2 83 + 202 + 221 + 210 4310 101011 4310 2= Example (Binary to Decimal) 1 1. 1 1 1x + 1x + 1 x 2- + 1 x 2- 221 + 210 1 + 0.5 2 + 0.25 3.75 10 11.112 3.751 = 0 Exercise (11011)2 = ( )10 (101101)2 = ( )10 (11101111)2 = ( )10 (110.011)2 = ( )10 (1001.0010)2 = ( )10 Algorithm An Algorithm is a finite sequence of well defined steps for solving a problem in systematic manner. It is written in the natural languages like English. Advantages Easy to write. Human readable techniques to understand logic. Algorithms for big problems can be written with moderate efforts. Disadvantages Difficult to debug. Difficult to show branching and looping. Jumping (goto) makes it hard to trace some problems 42 Example of Algorithm Write an algorithm to find whether given number is even or odd. Step 1 : Input no. Step 2 : If no mod 2=0, goto 4. Step 3 : Print given no is odd, goto 5. Step 4 : Print given no is even. Step 5 : Stop. 43 Flowchart Flowchart is a pictorial or graphical representation of a process. Each step in the process is represented by a different symbol and contains a short description of the process step. The flowchart symbols are linked together with arrows showing the process flow direction. This pictorial representation can give step-by-step solution of the given problem. 44 Advantages Easy to draw Easy to understand logic Easy to identify mistakes by non computer person Easy to show branching and looping Disadvantages Time consuming Difficult to modify Very difficult to draw flowchart for big or complex problems 45 Flowchart Symbols Start / Stop Input / Output Process Decision Making Subroutine Arrows 46 Example of Flowchart Draw a flowchart to find whether given number is even or odd. Start Read no Is no Yes No mod 2 = 0? Print Print no is no is even odd Stop 47 Write an algorithm to enter number still user wants and at the end it should display count of total number of positive, negative and zero entered. 1. Initialize pos=0, neg=0, zero=0 2. Read no 3. If no Greater than 0, pos = pos + 1, goto 6 4. If no Less than 0, neg = neg + 1, goto 6 5. zero=zero+1 6. Print “Do you want to enter more number?” 7. Read ans 8. If ans = “y”, goto 2 9. Print pos, neg, zero 10. Stop 48 Start pos =0, neg=0, zero=0 Read no Yes no> No 0? Yes no< No 0? pos = neg = zero = pos + 1 neg + 1 zero + 1 Do you Yes want to enter more number? No Print pos, neg, zero Stop 49