Example: dental hygienist

Basic Programming Concepts - Indian Institute of ...

Basic Programming ConceptsBasic Programming ConceptsCS10001:CS10001: Programming & Data StructuresProgramming & Data StructuresDept. of CSE, IIT KGPP allab DasguptaPallab DasguptaProfessor, Dept. of Computer Sc. & Engg.,Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology KharagpurIndian Institute of Technology KharagpurSome TerminologiesSome Terminologies Algorithm / FlowchartAlgorithm / Flowchart A stepA step--byby--step procedure for solving a particular procedure for solving a particular problem. Independent of the Programming of the Programming language. ProgramProgramDept. of CSE, IIT KGP ProgramProgram A translation of the algorithm/flowchart into a form that can be A translation of the algorithm/flowchart into a form that can be processed by a by a computer. Typically written in a highTypically written in a high--level language like C, C++, Java, language like C, C++, Java, and ConstantsVariables and Constants Most important concept for problem solving using computersMost important concept for problem solving using computers All temporary results are stored in terms of variablesAll temporary results are stored in terms of variables The value of a variable can be value of a variable can be changed.

Basic Programming Concepts CS10001: Programming ... –– Typically written in a highTypically written in a high--level language like C, level language like C ...

Tags:

  Programming, Basics, Concept, Basic programming concepts

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Basic Programming Concepts - Indian Institute of ...

1 Basic Programming ConceptsBasic Programming ConceptsCS10001:CS10001: Programming & Data StructuresProgramming & Data StructuresDept. of CSE, IIT KGPP allab DasguptaPallab DasguptaProfessor, Dept. of Computer Sc. & Engg.,Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology KharagpurIndian Institute of Technology KharagpurSome TerminologiesSome Terminologies Algorithm / FlowchartAlgorithm / Flowchart A stepA step--byby--step procedure for solving a particular procedure for solving a particular problem. Independent of the Programming of the Programming language. ProgramProgramDept. of CSE, IIT KGP ProgramProgram A translation of the algorithm/flowchart into a form that can be A translation of the algorithm/flowchart into a form that can be processed by a by a computer. Typically written in a highTypically written in a high--level language like C, C++, Java, language like C, C++, Java, and ConstantsVariables and Constants Most important concept for problem solving using computersMost important concept for problem solving using computers All temporary results are stored in terms of variablesAll temporary results are stored in terms of variables The value of a variable can be value of a variable can be changed.

2 The value of a constant do not value of a constant do not of CSE, IIT KGP Where are they stored?Where are they stored? In main main How does memory look like (logically)?How does memory look like (logically)? As a list of storage locations, each having a unique a list of storage locations, each having a unique address. Variables and constants are stored in these storage and constants are stored in these storage locations. A variable is like a A variable is like a binbinDept. of CSE, IIT KGP A variable is like a A variable is like a binbin The contents of the The contents of the binbinis the is the valuevalueof the variableof the variable The variable name is used to refer to the value of the variableThe variable name is used to refer to the value of the variable A variable is mapped to a A variable is mapped to a location location of the memory, called its of the memory, called its addressaddressMemory mapMemory mapAddress 0 Address 1 Address 2 Address 3 Address 4 Address 5 Every variable is mapped to a particular Dept.

3 Of CSE, IIT KGPA ddress 5 Address 6 Address N-1mapped to a particular memory addressVariables in MemoryVariables in MemoryVariable XX = 1010 Instruction executedTDept. of CSE, IIT KGPX = 20X = X + 1X = X * 5 Time2021105 Variables in Memory (contd.)Variables in Memory (contd.)VariableX Y X = 20 Instruction executed20?TDept. of CSE, IIT KGPY = 15X = Y + 3Y = X / 6 Time20151815183 Data TypesData Types Three common data types used:Three common data types used: IntegerInteger:: can store only whole numbers:: can store only whole numbers Examples: 25, Examples: 25, --56, 1, 056, 1, 0 Dept. of CSE, IIT KGP FloatingFloating--pointpoint:: can store numbers with fractional values.:: can store numbers with fractional values. Examples: , , Examples: , , CharacterCharacter:: can store a character:: can store a character Examples: A , a , * , 3 , , + Examples: A , a , * , 3 , , + Data Types (contd.)

4 Data Types (contd.) How are they stored in memory?How are they stored in memory? Integer :: Integer :: 16 bits16 bits 32 bits32 bits Float :: Float :: 32 bits32 bitsActual number of bits vary from one computer to anotherDept. of CSE, IIT KGP 32 bits32 bits 64 bits64 bits Char ::Char :: 8 bits (ASCII code)8 bits (ASCII code) 16 bits (UNICODE, used in Java)16 bits (UNICODE, used in Java)Problem solvingProblem solving Step 1:Step 1: Clearly specify the problem to be specify the problem to be solved. Step 2:Step 2: Draw flowchart or write flowchart or write algorithm. Step 3:Step 3:Dept. of CSE, IIT KGP Convert flowchart (algorithm) into program flowchart (algorithm) into program code. Step 4:Step 4: Compile the program into object the program into object code. Step 5:Step 5: Execute the the : Basic symbolsFlowchart: Basic symbolsComputationInput / OutputDept. of CSE, IIT KGPI nput / OutputDecision BoxStart / of controlDept.

5 Of CSE, IIT KGPC onnectorExample 1: Example 1: Adding three numbersAdding three numbersREAD A, B, CREAD A, B, CSTARTSTARTDept. of CSE, IIT KGPS = A + B + CS = A + B + COUTPUT SOUTPUT SSTOPSTOPE xample 2: Example 2: Larger of two numbersLarger of two numbersSTARTSTARTREAD X, YREAD X, YYESYESNONODept. of CSE, IIT KGPSTOPSTOPOUTPUT YOUTPUT YISISX>Y?X>Y?OUTPUT XOUTPUT XSTOPSTOPYESYESNONOE xample 3: Example 3: Largest of three numbersLargest of three numbersSTARTSTARTREAD X, Y, ZREAD X, Y, ZISISX > Y?X > Y?YESYESNONODept. of CSE, IIT KGPISISMax > Z?Max > Z?X > Y?X > Y?Max = XMax = XMax = YMax = YOUTPUT MaxOUTPUT MaxOUTPUT ZOUTPUT ZSTOPSTOPSTOPSTOPYESYESNONOE xample 4: Example 4: Sum of first N natural numbersSum of first N natural numbersSTARTREAD NSUM = 0 COUNT = 1 Dept. of CSE, IIT KGPSUM = SUM + COUNTCOUNT = COUNT + 1 ISCOUNT > N?OUTPUT SUMSTOPYESNOE xample 5: Example 5: SUM = 1 SUM = 122+ 2+ 222+ 3+ 322+ N+ N22 STARTREAD NSUM = 0 COUNT = 1 Dept.

6 Of CSE, IIT KGPSUM = SUM + COUNT COUNTCOUNT = COUNT + 1 ISCOUNT > N?OUTPUT SUMSTOPYESNOE xample 6: Example 6: SUM = + + + to N termsSUM = + + + to N termsSTARTREAD NSUM = 0 COUNT = 1 Dept. of CSE, IIT KGPSUM = SUM + COUNT (COUNT + 1)COUNT = COUNT + 1 ISCOUNT > N?OUTPUT SUMSTOPYESNOE xample 7: Example 7: Computing FactorialComputing FactorialSTARTSTARTREAD NREAD NPROD = 1 PROD = 1 COUNT = 1 COUNT = 1 Dept. of CSE, IIT KGPPROD = PROD * COUNTPROD = PROD * COUNTCOUNT = COUNT + 1 COUNT = COUNT + 1 ISISCOUNT > N?COUNT > N?OUTPUT PRODOUTPUT PRODSTOPSTOPYESYESNONOE xample 8: Example 8: Computing eComputing exxseries up to N termsseries up to N termsSTARTREAD X,NTERM = 1 SUM = 0 COUNT = 1 Dept. of CSE, IIT KGPSUM = SUM + TERMTERM = TERM * X / COUNTCOUNT = COUNT + 1 ISCOUNT > N?OUTPUT SUMSTOPYESNOE xample 8: Example 8: Computing eComputing exxseries up to 4 decimal placesseries up to 4 decimal placesSTARTREAD X,NTERM = 1 SUM = 0 COUNT = 1 Dept.

7 Of CSE, IIT KGPSUM = SUM + TERMTERM = TERM * X / COUNTCOUNT = COUNT + 1 ISTERM < SUMSTOPYESNOE xample 10: Example 10: Roots of a quadratic equationRoots of a quadratic equationax2+ bx + c = 0 Dept. of CSE, IIT KGPTRY YOURSELFE xample 11: Example 11: Grade computationGrade computationMARKS MARKS 90 90 ExEx89 89 MARKS MARKS 80 80 AA79 79 MARKS MARKS 70 70 BB69 69 MARKS MARKS 60 60 CC59 59 MARKS MARKS 50 50 DD49 49 MARKS MARKS 35 35 PPDept. of CSE, IIT KGP49 49 MARKS MARKS 35 35 PP34 34 MARKS MARKS FFGrade Computation (contd.)Grade Computation (contd.)STARTREAD MARKSMARKS 90?MARKS 80?MARKS 70?ANONONODept. of CSE, IIT KGPOUTPUT Ex MARKS 90?MARKS 80?MARKS 70?OUTPUT A OUTPUT B STOPSTOPSTOPAYESYESYESMARKS 60?

8 OUTPUT C AMARKS 50?MARKS 35?OUTPUT D OUTPUT P OUTPUT F YESYESYESNONONODept. of CSE, IIT KGPSTOPSTOPSTOPSTOP


Related search queries