Session 01 Introduction to Programming

27 469 0
Session 01 Introduction to Programming

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Differentiate between Command, Program and SoftwareExplain the beginning of CExplain when and why is C usedDiscuss the C program structureDiscuss algorithmsDraw flowchartsList the symbols used in flowcharts

LBC, Session 1 Introduction to Programming FPT APTECH COMPUTER EDUCATION HANOI Objectives • Differentiate between Command, Program and Software • Explain the beginning of C • Explain when and why is C used • Discuss the C program structure • Discuss algorithms • Draw flowcharts • List the symbols used in flowcharts LBC/Session 1 2 Software, Program and Command Software Program 2 Program 1 Commands Commands LBC/Session 1 Commands 3 The beginning of C BPCL – Martin Richards B – Ken Thompson C – Dennis Ritchie LBC/Session 1 4 Application areas of C • • • • • C was initially used for systems programming A system program forms a portion of the operating system of the computer or its support utilities Operating Systems, Interpreters, Editors, Assembly programs are usually called system programs The UNIX operating system was developed using C There are C compilers available for almost all types of PC’s LBC/Session 1 5 Middle Level Language High Level Language C Assembly Language LBC/Session 1 6 Structured Language • C allows compartmentalization of code and data • It refers to the ability to section off and hide all information and instructions, necessary to perform a specific task, from the rest of the program • Code can be compartmentalized in C by using functions or code blocks. LBC/Session 1 7 About C • • C has 32 keywords • • • Rules to be followed for all programs written in C: • These keywords combined with a formal syntax form a C programming language All keywords are lowercased C is case sensitive, do while is different from DO WHILE Keywords cannot be used as a variable or function name LBC/Session 1 main() { /* This is a sample Program*/ int i,j; i=100; j=200; : } 8 The C Program Structure-1 • C programs are divided into units called functions • Irrespective of the number of functions in a program, the operating system always passes control to the main() when a C program is executed. • The function name is always followed be parentheses. • The parentheses may or not contain parameters. LBC/Session 1 9 The C Program Structure-2 • The function definition is followed by an open curly brace ({) • The curly brace signals the beginning of the function • A closing curly brace (}) after the codes, in the function, indicate the end of the function LBC/Session 1 10 The C Program Structure-3 • A statement in C is terminated with a semicolon • A carriage return, whitespace, or a tab is not understood by the C compiler • A statement that does not end in a semicolon is treated as an erroneous line of code in C LBC/Session 1 11 The C Program Structure-4 • Comments are usually written to describe the task of a particular command, function or an entire program • The compiler ignores comments. • There are two way to insert comments: • Single line: //Comments go here • Multiline: /* Comments go here and here */ LBC/Session 1 12 The C Library • All C compilers come with a standard library of functions • A function written by a programmer can be placed in the library and used when required • Some compilers allow functions to be added in the standard library • Some compilers require a separate library to be created LBC/Session 1 13 Compiling & Running A Program LBC/Session 1 14 The Programming Approach to Solving Problems Algorithm is a set of steps that are performed to solve a problem. The example below describes an algorithm: Classroom Leaving the classroom Head towards the staircase Go to the basement These are the steps followed when a student wants to go to the cafeteria from the classroom Head for the cafeteria Cafeteria LBC/Session 1 15 Solving a Problem In order to solve a problem Understand the problem clearly Gather the relevant information Process the information Arrive at the solution LBC/Session 1 16 Pseudocode • Is not actual code. • Is a method of algorithm - writing which uses a standard set of words which makes it resemble code • Each pseudocode starts with a BEGIN • To show some value , the word DISPLAY is used • The pseudocode finishes with an BEGIN DISPLAY ‘Hello World !’ END LBC/Session 1 17 Flowcharts It is a graphical representation of an algorithm START DISPLAY ‘Hello World !’ STOP LBC/Session 1 18 The Flowchart Symbol LBC/Session 1 19 Flowchart to add two numbers LBC/Session 1 20 The IF Construct S TAR T BEGIN INPUT num r = num MOD 2 IF r=0 Display “Number is even” END IF END IN P U T n u m r = n u m M OD 2 r =0 No Yes D IS P L AY "N u m b e r i s E ve n " S TOP LBC/Session 1 21 The IF-ELSE Construct BEGIN INPUT num r=num MOD 2 IF r=0 DISPLAY “Even Number” ELSE DISPLAY “Odd Number” END IF END S TA R T IN P U T n u m r = n um M O D 2 Yes r = 0 D IS P L AY "N u m b e r i s E ve n " No D IS PL A Y " N u m b er is O d d " S TOP LBC/Session 1 22 Multiple criteria using AND/OR BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 AND bizDone >=5000000 DISPLAY “Classified as an MVS” ELSE DISPLAY “A little more effort required!” END IF END LBC/Session 1 23 Nested IFs-1 BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 IF bizDone >=5000000 DISPLAY “Classified as an MVS” ELSE DISPLAY “A little more effort required!” END IF ELSE DISPLAY “A little more effort required!” END IF END LBC/Session 1 24 Nested IFs-2 START INPUT YearsWithUs INPUT bizDone YES YearsWithUs >= 10 NO DISPLAY “A Little more effort required” bizDone > 5000000 NO YES DISPLAY “A Little more effort required” DISPLAY “Classified as an MVS” STOP LBC/Session 1 25 Loops S TA R T BEGIN cnt=0 WHILE (cnt < 1000) DO DISPLAY “Scooby” cnt=cnt+1 END DO END cn t=0 cn t < 1 0 0 0 No Yes D IS PL A Y " Sc o ob y " cn t=c n t+1 S TOP LBC/Session 1 26 Summary • • • • • • • • Software is a set of programs. A Program is a set of instructions. Code blocks, form a base of any C program. An Algorithm is a logical and concise list of steps to solve a problem A pseudo code is a representation of an algorithm in language that resembles code A flowchart is a diagrammatic representation of an algorithm The basic selection construct is an ‘IF’ construct The iterative or looping constructs is necessary to repeat certain steps LBC/Session 1 27 [...]... LBC /Session 1 12 The C Library • All C compilers come with a standard library of functions • A function written by a programmer can be placed in the library and used when required • Some compilers allow functions to be added in the standard library • Some compilers require a separate library to be created LBC /Session 1 13 Compiling & Running A Program LBC /Session 1 14 The Programming Approach to Solving... Algorithm is a set of steps that are performed to solve a problem The example below describes an algorithm: Classroom Leaving the classroom Head towards the staircase Go to the basement These are the steps followed when a student wants to go to the cafeteria from the classroom Head for the cafeteria Cafeteria LBC /Session 1 15 Solving a Problem In order to solve a problem Understand the problem clearly... representation of an algorithm START DISPLAY ‘Hello World !’ STOP LBC /Session 1 18 The Flowchart Symbol LBC /Session 1 19 Flowchart to add two numbers LBC /Session 1 20 The IF Construct S TAR T BEGIN INPUT num r = num MOD 2 IF r=0 Display “Number is even” END IF END IN P U T n u m r = n u m M OD 2 r =0 No Yes D IS P L AY "N u m b e r i s E ve n " S TOP LBC /Session 1 21 The IF-ELSE Construct BEGIN INPUT num r=num... return, whitespace, or a tab is not understood by the C compiler • A statement that does not end in a semicolon is treated as an erroneous line of code in C LBC /Session 1 11 The C Program Structure-4 • Comments are usually written to describe the task of a particular command, function or an entire program • The compiler ignores comments • There are two way to insert comments: • Single line: //Comments... Process the information Arrive at the solution LBC /Session 1 16 Pseudocode • Is not actual code • Is a method of algorithm - writing which uses a standard set of words which makes it resemble code • Each pseudocode starts with a BEGIN • To show some value , the word DISPLAY is used • The pseudocode finishes with an BEGIN DISPLAY ‘Hello World !’ END LBC /Session 1 17 Flowcharts It is a graphical representation... Yes r = 0 D IS P L AY "N u m b e r i s E ve n " No D IS PL A Y " N u m b er is O d d " S TOP LBC /Session 1 22 Multiple criteria using AND/OR BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 AND bizDone >=5000000 DISPLAY “Classified as an MVS” ELSE DISPLAY “A little more effort required!” END IF END LBC /Session 1 23 Nested IFs-1 BEGIN INPUT yearsWithUs INPUT bizDone IF yearsWithUs >= 10 IF... effort required!” END IF ELSE DISPLAY “A little more effort required!” END IF END LBC /Session 1 24 Nested IFs-2 START INPUT YearsWithUs INPUT bizDone YES YearsWithUs >= 10 NO DISPLAY “A Little more effort required” bizDone > 5000000 NO YES DISPLAY “A Little more effort required” DISPLAY “Classified as an MVS” STOP LBC /Session 1 25 Loops S TA R T BEGIN cnt=0 WHILE (cnt < 1000) DO DISPLAY “Scooby” cnt=cnt+1... “Scooby” cnt=cnt+1 END DO END cn t=0 cn t < 1 0 0 0 No Yes D IS PL A Y " Sc o ob y " cn t=c n t+1 S TOP LBC /Session 1 26 Summary • • • • • • • • Software is a set of programs A Program is a set of instructions Code blocks, form a base of any C program An Algorithm is a logical and concise list of steps to solve a problem A pseudo code is a representation of an algorithm in language that resembles code... language that resembles code A flowchart is a diagrammatic representation of an algorithm The basic selection construct is an ‘IF’ construct The iterative or looping constructs is necessary to repeat certain steps LBC /Session 1 27 ... LBC /Session 17 Flowcharts It is a graphical representation of an algorithm START DISPLAY ‘Hello World !’ STOP LBC /Session 18 The Flowchart Symbol LBC /Session 19 Flowchart to add two numbers LBC /Session. .. LBC /Session Software, Program and Command Software Program Program Commands Commands LBC /Session Commands The beginning of C BPCL – Martin Richards B – Ken Thompson C – Dennis Ritchie LBC /Session. .. standard library • Some compilers require a separate library to be created LBC /Session 13 Compiling & Running A Program LBC /Session 14 The Programming Approach to Solving Problems Algorithm is a set

Ngày đăng: 08/10/2015, 22:23

Từ khóa liên quan

Mục lục

  • LBC, Session 1

  • Objectives

  • Software, Program and Command

  • PowerPoint Presentation

  • Slide 5

  • Slide 6

  • Slide 7

  • Slide 8

  • Slide 9

  • Slide 10

  • Slide 11

  • Slide 12

  • Slide 13

  • Slide 14

  • The Programming Approach to Solving Problems

  • Solving a Problem

  • Pseudocode

  • Flowcharts

  • The Flowchart Symbol

  • Flowchart to add two numbers

  • The IF Construct

  • The IF-ELSE Construct

  • Multiple criteria using AND/OR

  • Nested IFs-1

  • Nested IFs-2

  • Loops

  • Summary

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan