UNIT-1_INTRODUCTION TO PROGRAMMING.pdf
Document Details
Uploaded by CapableDalmatianJasper
Tags
Full Transcript
UNIT-1 Introduction to Programming Topics Basics of Computers: Overview of computer systems, hardware, and software. Introduction to Programming Languages: Types of programming languages, language translators (compilers,...
UNIT-1 Introduction to Programming Topics Basics of Computers: Overview of computer systems, hardware, and software. Introduction to Programming Languages: Types of programming languages, language translators (compilers, interpreters). Flowcharts and Algorithms Basics of creating flowcharts and writing algorithms for problem-solving. What is Computer? The word computer comes from the word “compute”, which means, “to calculate”. A computer is an electronic device that can perform arithmetic operations at high speed and it can process data, pictures, sound and graphics. It can solve highly complicated problems quickly and accurately. Advantages of Computer Speed – It can calculate millions of expression within a fraction of second. Storage – It can store large amount of data using various storage devices. Accuracy – It can perform the computations at very high speed without any mistake. Reliability – The information stored in computer is available after years in same form. It works 24 hours without any problem as it does not feel tiredness. Automation – Once the task is created in computer, it can be repeatedly performed again by a single click whenever we want. Multitasking – It can perform more than one tasks/operations simultaneously. Disadvantages of Computer Lake of intelligence – It can not think while doing work. – It does not have natural intelligence. – It can not think about properness, correctness or effect of work it is doing. Unable to correct mistake – It can not correct mistake by itself. – So if we provide wrong or incorrect data then it produces wrong result or perform wrong calculations. Block Diagram of Computer High Level Language We can write programs in an English-like manner and it is more convenient to use. Programmers can perform complex tasks by using high-level languages with fewer efforts. It is similar to natural language and mathematical notation. Example: C++, Java, etc. ADVANTAGES of High Level Language: 1. Easier to learn. 2. Requires less time to write. 3. Provides better documentation. 4. Easier to maintain. 5. It is portable. DISADVANTAGES: 1. It requires compiler or interpreter to convert higher level language to machine language. 2. Programmers need to learn the structure of high level language. 3. It is a bit slow compared to low level and medium level language. C is often called a middle-level computer language. Middle-level does not mean C is less powerful, harder to use, or less developed than high level languages such as BASIC or Pascal; nor is C similar to a low-level language such as assembly language. It contains many of the low-level and high-level capabilities. Using C user can access the hardware directly and at the same time the user can write instructions in English like language. C is a language that can be used to develop both user applications and operating systems. Flowchart and Algorithm Flowchart and Algorithm Programming Task can be divided into two phases (i) Problem Solving Phase (ii) Implementation Phase Steps in Problem Solving First produce a general algorithm (one can use pseudocode) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English. Pseudocode & Algorithm Write a Pseudocode and Algorithm to add two numbers. Pseudocode Input 2 numbers Calculate their sum Algorithm Step-1 : Start Step-2 : Input X,Y Step-3 : Sum -> X + Y Step-4 : End Pseudocode & Algorithm Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks. Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS” Pseudocode & Algorithm Algorithm Pseudocode: Step 1: Input M1,M2,M3,M4 Input a set of 4 marks Calculate their average by Step 2: GRADE ← (M1+M2+M3+M4)/4 summing and dividing by 4 Step 3: if (GRADE < 50) then if average is below 50 Print “FAIL” Print “FAIL” else else Print “PASS” Print “PASS” endif Flowcharts Flowcharts is a graph used to depict or show a step by step solution using symbols which represent a task. The symbols used consist of geometrical shapes that are connected by flow lines. It is an alternative to pseudo coding; whereas a pseudocode description is verbal, a flowchart is graphical in nature. The Flowchart A Flowchart – shows logic of an algorithm – emphasizes individual steps and their interconnections – e.g. control flow from one action to the next Flowchart Symbols Terminal symbol - indicates the beginning and end points of an algorithm. Process symbol - shows an instruction other than input, output or selection. Input-output symbol - shows an input or an output operation. Disk storage I/O symbol - indicates input from or output to disk storage. Printer output symbol - shows hardcopy printer output. Flowchart Symbols cont… Selection symbol - shows a selection process for two-way selection. Off-page connector - provides continuation of a logical path on another page. On-page connector - provides continuation of logical path at another point in the same page. Flow lines - indicate the logical sequence of execution steps in the algorithm. Flowchart – sequence control structure Statement 1 Statement 2 Statement 3 : Flowchart – selection control structure No Yes Condition else- then- statement(s) statement(s) Example-1 START Step 1: Input M1,M2,M3,M4 Step 2: GRADE ← (M1+M2+M3+M4)/4 Input Step 3: if (GRADE