Basic Programming Concepts Imran Rashid Basic Programming Concepts Imran Rashid CTO at ManiWeber Technologies
Basic Programming Concepts Imran Rashid Outline Program, Programming & Programming Languages Variables, Constants & Data Types Operators in Programming Decision Making in Programming Iterations in Programming
Program, Programming & Programming Languages
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Program A computer program, or just a program, is a sequence of instructions, written to perform a specified task on a computer Programming Computer programming is the process of writing or editing source code A person who practices this skill is referred to as a computer programmer, software developer, and sometimes coder Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Type of Programming Languages
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Language Translation Process (High to Low)
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Type of Language Translators
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Compiler v.s Interpreter
Basic Programming Concepts Imran Rashid Program, Programming & Programming Languages Type of Errors in Programming
Variables, Constants & Data Types
Basic Programming Concepts Imran Rashid Variables, Constants & Data Types Variables & Constants Most important concept for problem solving using computers All temporary results are stored in terms of variables oThe value of a variable can be changed oThe value of a constant do not change Where are they stored? In main memory How does memory look like (logically)? As a list of storage locations, each having a unique address Variables and constants are stored in these storages
Basic Programming Concepts Imran Rashid Variables, Constants & Data Types
Basic Programming Concepts Imran Rashid Variables, Constants & Data Types
Basic Programming Concepts Imran Rashid Variables, Constants & Data Types
Basic Programming Concepts Imran Rashid Variables, Constants & Data Types Data Types Three common data types used: oInteger: can store only whole numbers – Examples: 25, -56, 1, 0 – Size: 16 bits & 32 bits oFloating-point: can store numbers with fractional values – Examples: 3.14159, 5.0, -12345.345 – Size: 32 bits & 64 bits oCharacter: can store a character – Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’ – Size: 8 bits & 16 bits
Operators in Programming
Basic Programming Concepts Imran Rashid Operators in Programming Arithmetic Operators Addition (+) Subtraction (-) Division (/) Multiplication (*) Modulus (%) Examples distance = rate * time; netIncome = income - tax; speed = distance / time; area = PI * radius * radius;
Basic Programming Concepts Imran Rashid Operators in Programming Suppose x and y are two integer variables, whose values are 13 and 5 respectively
Basic Programming Concepts Imran Rashid Operators in Programming Operator Precedence In decreasing order of priority oParentheses: ( ) oUnary minus: –5 oMultiplication, Division, and Modulus oAddition and Subtraction For operators of the same priority, evaluation is from left to right as they appear Parenthesis may be used to change the precedence of operator evaluation
Basic Programming Concepts Imran Rashid Operators in Programming Relational Operators Used to compare two quantities
Basic Programming Concepts Imran Rashid Operators in Programming Logical Operators There are two logical operators (also called logical connectives) o&& : Logical AND – Result is true if both the operands are true o|| : Logical OR – Result is true if at least one of the operands are true
Decision Making in Programming
Basic Programming Concepts Imran Rashid Decision Making in Programming Statements and Blocks An expression followed by a semicolon becomes a statement ox = 5; oy = x + 3; Braces { and } are used to group declarations and statements together into a compound statement, or block
Basic Programming Concepts Imran Rashid Decision Making in Programming Control Statements: What do they do? Allow different sets of instructions to be executed depending on the outcome of a logical test oWhether TRUE (non-zero) or FALSE (zero) How do we specify the conditions? Using relational operators (<, <=, >, >=, ==, !=) Using logical operators (&&, ||, !)
Basic Programming Concepts Imran Rashid Decision Making in Programming The if Statement The condition to be tested is any expression enclosed in parentheses The expression is evaluated, and if its value is non-zero, the statement is executed
Basic Programming Concepts Imran Rashid Decision Making in Programming The if-else Statement These statements can be nested
Basic Programming Concepts Imran Rashid Decision Making in Programming The switch Statement This causes a particular group of statements to be chosen from several available groups oUses “switch” statement and “case” labels
Iterations in Programming
Basic Programming Concepts Imran Rashid Iterations in Programming Loop Group of instructions that are executed repeatedly while some condition remains true Loops can be nested as well There are 3 main types of loops owhile loop odo-while loop ofor loop
Basic Programming Concepts Imran Rashid Iterations in Programming while loop The while loop is used to carry out looping operations, in which a group of statements is executed repeatedly, as long as some condition remains satisfied
Basic Programming Concepts Imran Rashid Iterations in Programming do-while loop A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block
Basic Programming Concepts Imran Rashid Iterations in Programming for loop The for loop is the most commonly used looping structure in programming for known iterations oexpr1 (init) : initialize parameters oexpr2 (test): test condition, loop continues if satisfied oexpr3 (update): used to alter the value of the parameters after each iteration
Basic Programming Concepts Imran Rashid LAB Total Marks: [2 + 2 + 2 + 2 + 2 = 10] Q: In GIMS there are 500 students, 12 class rooms, 2 labs, 4 departments, 20 admin staff, 32 teachers, 6 degree programs (e.g. BSCS/BSIT), & 3 busses. 1. Store this information in proper data types, variable/constant names & values (use proper naming conventions)? 2. Every teacher starts his/her lecture at certain time & it has an end time (which programming construct is applied in this scenario & how)? 3. A teacher can arrange extra/makeup classes only of the room & class is free (which programming construct is applied in this scenario & how)? 4. Bus 1, 2 & 3 has fixed root (e.g. bus 1 move students from Kharian to Gujrat) (which programming construct is applied in this scenario & how)? 5. A teacher might be a permanent one or visiting (which programming construct is applied in this scenario & how)?
Basic Programming Concepts Imran Rashid ASSIGNMENT Submission Date 22/10/2018 & in written form [10] Q1 (a): Do some R&D on the internet and write down the syntaxes of the following things: 1. How to declare a variable 2. How to declare a constant 3. How to make a decision with if-else-if & switch 4. How to make an unknown and known iteration (for & while/do-while) Q1 (b): Do the above mention activities in the following languages: 1. C++ 2. PHP 3. JavaScript 4. C#
Any ?

Basic of Programming (Introduction to Programming)

  • 1.
    Basic Programming ConceptsImran Rashid Basic Programming Concepts Imran Rashid CTO at ManiWeber Technologies
  • 2.
    Basic Programming ConceptsImran Rashid Outline Program, Programming & Programming Languages Variables, Constants & Data Types Operators in Programming Decision Making in Programming Iterations in Programming
  • 3.
    Program, Programming &Programming Languages
  • 4.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Program A computer program, or just a program, is a sequence of instructions, written to perform a specified task on a computer Programming Computer programming is the process of writing or editing source code A person who practices this skill is referred to as a computer programmer, software developer, and sometimes coder Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine
  • 5.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Type of Programming Languages
  • 6.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Language Translation Process (High to Low)
  • 7.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Type of Language Translators
  • 8.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Compiler v.s Interpreter
  • 9.
    Basic Programming ConceptsImran Rashid Program, Programming & Programming Languages Type of Errors in Programming
  • 10.
  • 11.
    Basic Programming ConceptsImran Rashid Variables, Constants & Data Types Variables & Constants Most important concept for problem solving using computers All temporary results are stored in terms of variables oThe value of a variable can be changed oThe value of a constant do not change Where are they stored? In main memory How does memory look like (logically)? As a list of storage locations, each having a unique address Variables and constants are stored in these storages
  • 12.
    Basic Programming ConceptsImran Rashid Variables, Constants & Data Types
  • 13.
    Basic Programming ConceptsImran Rashid Variables, Constants & Data Types
  • 14.
    Basic Programming ConceptsImran Rashid Variables, Constants & Data Types
  • 15.
    Basic Programming ConceptsImran Rashid Variables, Constants & Data Types Data Types Three common data types used: oInteger: can store only whole numbers – Examples: 25, -56, 1, 0 – Size: 16 bits & 32 bits oFloating-point: can store numbers with fractional values – Examples: 3.14159, 5.0, -12345.345 – Size: 32 bits & 64 bits oCharacter: can store a character – Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’ – Size: 8 bits & 16 bits
  • 16.
  • 17.
    Basic Programming ConceptsImran Rashid Operators in Programming Arithmetic Operators Addition (+) Subtraction (-) Division (/) Multiplication (*) Modulus (%) Examples distance = rate * time; netIncome = income - tax; speed = distance / time; area = PI * radius * radius;
  • 18.
    Basic Programming ConceptsImran Rashid Operators in Programming Suppose x and y are two integer variables, whose values are 13 and 5 respectively
  • 19.
    Basic Programming ConceptsImran Rashid Operators in Programming Operator Precedence In decreasing order of priority oParentheses: ( ) oUnary minus: –5 oMultiplication, Division, and Modulus oAddition and Subtraction For operators of the same priority, evaluation is from left to right as they appear Parenthesis may be used to change the precedence of operator evaluation
  • 20.
    Basic Programming ConceptsImran Rashid Operators in Programming Relational Operators Used to compare two quantities
  • 21.
    Basic Programming ConceptsImran Rashid Operators in Programming Logical Operators There are two logical operators (also called logical connectives) o&& : Logical AND – Result is true if both the operands are true o|| : Logical OR – Result is true if at least one of the operands are true
  • 22.
    Decision Making inProgramming
  • 23.
    Basic Programming ConceptsImran Rashid Decision Making in Programming Statements and Blocks An expression followed by a semicolon becomes a statement ox = 5; oy = x + 3; Braces { and } are used to group declarations and statements together into a compound statement, or block
  • 24.
    Basic Programming ConceptsImran Rashid Decision Making in Programming Control Statements: What do they do? Allow different sets of instructions to be executed depending on the outcome of a logical test oWhether TRUE (non-zero) or FALSE (zero) How do we specify the conditions? Using relational operators (<, <=, >, >=, ==, !=) Using logical operators (&&, ||, !)
  • 25.
    Basic Programming ConceptsImran Rashid Decision Making in Programming The if Statement The condition to be tested is any expression enclosed in parentheses The expression is evaluated, and if its value is non-zero, the statement is executed
  • 26.
    Basic Programming ConceptsImran Rashid Decision Making in Programming The if-else Statement These statements can be nested
  • 27.
    Basic Programming ConceptsImran Rashid Decision Making in Programming The switch Statement This causes a particular group of statements to be chosen from several available groups oUses “switch” statement and “case” labels
  • 28.
  • 29.
    Basic Programming ConceptsImran Rashid Iterations in Programming Loop Group of instructions that are executed repeatedly while some condition remains true Loops can be nested as well There are 3 main types of loops owhile loop odo-while loop ofor loop
  • 30.
    Basic Programming ConceptsImran Rashid Iterations in Programming while loop The while loop is used to carry out looping operations, in which a group of statements is executed repeatedly, as long as some condition remains satisfied
  • 31.
    Basic Programming ConceptsImran Rashid Iterations in Programming do-while loop A do while loop is a control flow statement that executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block
  • 32.
    Basic Programming ConceptsImran Rashid Iterations in Programming for loop The for loop is the most commonly used looping structure in programming for known iterations oexpr1 (init) : initialize parameters oexpr2 (test): test condition, loop continues if satisfied oexpr3 (update): used to alter the value of the parameters after each iteration
  • 33.
    Basic Programming ConceptsImran Rashid LAB Total Marks: [2 + 2 + 2 + 2 + 2 = 10] Q: In GIMS there are 500 students, 12 class rooms, 2 labs, 4 departments, 20 admin staff, 32 teachers, 6 degree programs (e.g. BSCS/BSIT), & 3 busses. 1. Store this information in proper data types, variable/constant names & values (use proper naming conventions)? 2. Every teacher starts his/her lecture at certain time & it has an end time (which programming construct is applied in this scenario & how)? 3. A teacher can arrange extra/makeup classes only of the room & class is free (which programming construct is applied in this scenario & how)? 4. Bus 1, 2 & 3 has fixed root (e.g. bus 1 move students from Kharian to Gujrat) (which programming construct is applied in this scenario & how)? 5. A teacher might be a permanent one or visiting (which programming construct is applied in this scenario & how)?
  • 34.
    Basic Programming ConceptsImran Rashid ASSIGNMENT Submission Date 22/10/2018 & in written form [10] Q1 (a): Do some R&D on the internet and write down the syntaxes of the following things: 1. How to declare a variable 2. How to declare a constant 3. How to make a decision with if-else-if & switch 4. How to make an unknown and known iteration (for & while/do-while) Q1 (b): Do the above mention activities in the following languages: 1. C++ 2. PHP 3. JavaScript 4. C#
  • 35.