Session 01 Introduction to Programming

27 374 0
  • Loading ...
1/27 trang

Thông tin tài liệu

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

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 1Introduction to ProgrammingFPT 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 flowchartsLBC/Session 12 Software, Program and CommandSoftwareProgram 2Program 1CommandsCommandsLBC/Session 1Commands3 The beginning of CBPCL – Martin RichardsB – Ken ThompsonC – Dennis RitchieLBC/Session 14 Application areas of C•••••C was initially used for systems programmingA system program forms a portion of theoperating system of the computer or its supportutilitiesOperating Systems, Interpreters, Editors,Assembly programs are usually called systemprogramsThe UNIX operating system was developed usingCThere are C compilers available for almost alltypes of PC’sLBC/Session 15 Middle Level LanguageHigh Level LanguageCAssembly LanguageLBC/Session 16 Structured Language• C allows compartmentalization of code and data• It refers to the ability to section offand hide all information andinstructions, necessary to perform aspecific task, from the rest of theprogram• Code can be compartmentalized in C by using functionsor code blocks.LBC/Session 17 About C••C has 32 keywords•••Rules to be followed for all programs written in C:•These keywords combined with a formal syntax form aC programming languageAll keywords are lowercasedC is case sensitive, do while isdifferent from DO WHILEKeywords cannot be used asa variable or function nameLBC/Session 1main(){/* 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 aprogram, the operating system always passescontrol to the main() when a C program is executed.• The function name is always followed beparentheses.• The parentheses may or not contain parameters.LBC/Session 19 The C Program Structure-2• The function definition is followed by an opencurly brace ({)• The curly brace signals the beginning of thefunction• A closing curly brace (}) after the codes, in thefunction, indicate the end of the functionLBC/Session 110 The C Program Structure-3• A statement in C is terminated with a semicolon• A carriage return, whitespace, or a tab is notunderstood by the C compiler• A statement that does not end in a semicolon istreated as an erroneous line of code in CLBC/Session 111 The C Program Structure-4• Comments are usually written to describe the task of aparticular 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 hereand here*/LBC/Session 112 The C Library• All C compilers come with a standardlibrary of functions• A function written by a programmer canbe placed in the library and used whenrequired• Some compilers allow functions to beadded in the standard library• Some compilers require a separate libraryto be createdLBC/Session 113 Compiling & Running A ProgramLBC/Session 114 The Programming Approach toSolving ProblemsAlgorithm is a set of steps that are performed to solve a problem. Theexample below describes an algorithm:ClassroomLeaving theclassroomHead towardsthe staircaseGo to thebasementThese are the steps followedwhen a student wants to goto the cafeteria from theclassroomHead for thecafeteriaCafeteriaLBC/Session 115 Solving a ProblemIn order to solve a problemUnderstand the problem clearlyGather the relevant informationProcess the informationArrive at the solutionLBC/Session 116 Pseudocode• Is not actual code.• Is a method of algorithm - writing which uses astandard 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 anBEGINDISPLAY ‘Hello World !’ENDLBC/Session 117 FlowchartsIt is a graphical representation of an algorithmSTARTDISPLAY ‘Hello World !’STOPLBC/Session 118 The Flowchart SymbolLBC/Session 119 Flowchart to add two numbersLBC/Session 120 The IF ConstructS TAR TBEGININPUT numr = num MOD 2IF r=0Display “Number is even”END IFENDIN P U T n u mr = n u m M OD 2r =0NoYesD IS P L AY "N u m b e r i s E ve n "S TOPLBC/Session 121 The IF-ELSE ConstructBEGININPUT numr=num MOD 2IF r=0DISPLAY “Even Number”ELSEDISPLAY “Odd Number”END IFENDS TA R TIN P U T n u mr = n um M O D 2Yesr = 0D IS P L AY "N u m b e r i s E ve n "NoD IS PL A Y " N u m b er is O d d "S TOPLBC/Session 122 Multiple criteria using AND/ORBEGININPUT yearsWithUsINPUT bizDoneIF yearsWithUs >= 10 AND bizDone >=5000000DISPLAY “Classified as an MVS”ELSEDISPLAY “A little more effort required!”END IFENDLBC/Session 123 Nested IFs-1BEGININPUT yearsWithUsINPUT bizDoneIF yearsWithUs >= 10IF bizDone >=5000000DISPLAY “Classified as an MVS”ELSEDISPLAY “A little more effort required!”END IFELSEDISPLAY “A little more effort required!”END IFENDLBC/Session 124 Nested IFs-2STARTINPUT YearsWithUsINPUT bizDoneYESYearsWithUs >= 10NODISPLAY “A Little more effort required”bizDone > 5000000NOYESDISPLAY “A Little more effort required”DISPLAY “Classified as an MVS”STOPLBC/Session 125 LoopsS TA R TBEGINcnt=0WHILE (cnt < 1000)DODISPLAY “Scooby”cnt=cnt+1END DOENDcn t=0cn t < 1 0 0 0NoYesD IS PL A Y " Sc o ob y "cn t=c n t+1S TOPLBC/Session 126 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 tosolve a problemA pseudo code is a representation of an algorithm inlanguage that resembles codeA flowchart is a diagrammatic representation of analgorithmThe basic selection construct is an ‘IF’ constructThe iterative or looping constructs is necessary torepeat certain stepsLBC/Session 127 [...]... 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
- Xem thêm -

Xem thêm: Session 01 Introduction to Programming, Session 01 Introduction to Programming, Session 01 Introduction to Programming

Gợi ý tài liệu liên quan cho bạn