Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Programming Concepts

Similar presentations


Presentation on theme: "Basic Programming Concepts"— Presentation transcript:

1 Basic Programming Concepts
Imran Rashid CTO at ManiWeber Technologies

2 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 Program, Programming & Programming Languages
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 Program, Programming & Programming Languages
Type of Programming Languages

6 Program, Programming & Programming Languages
Language Translation Process (High to Low)

7 Program, Programming & Programming Languages
Type of Language Translators

8 Program, Programming & Programming Languages
Compiler v.s Interpreter

9 Program, Programming & Programming Languages
Type of Errors in Programming

10 Variables, Constants & Data Types

11 Variables, Constants & Data Types
Most important concept for problem solving using computers All temporary results are stored in terms of variables The value of a variable can be changed The 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 Variables, Constants & Data Types

13 Variables, Constants & Data Types

14 Variables, Constants & Data Types

15 Variables, Constants & Data Types
Three common data types used: Integer: can store only whole numbers Examples: 25, -56, 1, 0 Size: 16 bits & 32 bits Floating-point: can store numbers with fractional values Examples: , 5.0, Size: 32 bits & 64 bits Character: can store a character Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’ Size: 8 bits & 16 bits

16 Operators in Programming

17 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 Operators in Programming
Suppose x and y are two integer variables, whose values are 13 and 5 respectively

19 Operators in Programming
Operator Precedence In decreasing order of priority Parentheses: ( ) Unary minus: –5 Multiplication, Division, and Modulus Addition 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 Operators in Programming
Relational Operators Used to compare two quantities

21 Operators in Programming
Logical Operators There are two logical operators (also called logical connectives) && : Logical AND Result is true if both the operands are true || : Logical OR Result is true if at least one of the operands are true

22 Decision Making in Programming

23 Decision Making in Programming
Statements and Blocks An expression followed by a semicolon becomes a statement x = 5; y = x + 3; Braces { and } are used to group declarations and statements together into a compound statement, or block

24 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 Whether TRUE (non-zero) or FALSE (zero) How do we specify the conditions? Using relational operators (<, <=, >, >=, ==, !=) Using logical operators (&&, ||, !)

25 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 Decision Making in Programming
The if-else Statement These statements can be nested

27 Decision Making in Programming
The switch Statement This causes a particular group of statements to be chosen from several available groups Uses “switch” statement and “case” labels

28 Iterations in Programming

29 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 while loop do-while loop for loop

30 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 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 Iterations in Programming
for loop The for loop is the most commonly used looping structure in programming for known iterations expr1 (init) : initialize parameters expr2 (test): test condition, loop continues if satisfied expr3 (update): used to alter the value of the parameters after each iteration

33 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. Store this information in proper data types, variable/constant names & values (use proper naming conventions)? Every teacher starts his/her lecture at certain time & it has an end time (which programming construct is applied in this scenario & how)? A teacher can arrange extra/makeup classes only of the room & class is free (which programming construct is applied in this scenario & how)? 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)? A teacher might be a permanent one or visiting (which programming construct is applied in this scenario & how)?

34 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: How to declare a variable How to declare a constant How to make a decision with if-else-if & switch How to make an unknown and known iteration (for & while/do-while) Q1 (b): Do the above mention activities in the following languages: C++ PHP JavaScript C#

35 Any ?


Download ppt "Basic Programming Concepts"

Similar presentations


Ads by Google