Basic Programming Concepts

Slides:



Advertisements
Similar presentations
Intermediate Code Generation
Advertisements

Programming Languages and Paradigms The C Programming Language.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
CSE 452: Programming Languages Expressions and Control Flow.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Chapter 2 Data Types, Declarations, and Displays
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
DAT602 Database Application Development Lecture 5 JAVA Review.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection)
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 4: Control Structures I (Selection)
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 5.
CPS120: Introduction to Computer Science Decision Making in Programs.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 4: Control Structures I (Selection)
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Selection Relational Expressions A condition or logical expression is an expression that can only take the values true or false. A.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Loops cause a section of a program to be repeated a certain number of times. The repetition continues while a condition remains true. When a condition.
1 Expressions. 2 Variables and constants linked with operators  Arithmetic expressions Uses arithmetic operators Can evaluate to any value  Logical.
Java Programming Fifth Edition Chapter 5 Making Decisions.
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational and logical operators.
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Chapter 4: Control Structures I (Selection). Objectives In this chapter, you will: – Learn about control structures – Examine relational operators – Discover.
Bill Tucker Austin Community College COSC 1315
Chapter 7 JavaScript: Control Statements, Part 1
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Chapter 4: Control Structures I (Selection)
Chapter 10 Programming Fundamentals with JavaScript
Java Programming Fifth Edition
Chapter 4 – C Program Control
CNG 140 C Programming (Lecture set 3)
BASIC ELEMENTS OF A COMPUTER PROGRAM
ITEC113 Algorithms and Programming Techniques
EGR 2261 Unit 4 Control Structures I: Selection
Test Review Computer Science History
Revision Lecture
JavaScript: Control Statements I
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
JavaScript: Control Statements.
Expressions and Assignment Statements
Arrays, For loop While loop Do while loop
Chapter 10 Programming Fundamentals with JavaScript
Chapter 4: Control Structures I (Selection)
Introduction to C++ Programming
Chapter 8 JavaScript: Control Statements, Part 2
Chapter 4 Selection.
Expression and Asignment Statements
Chapter 4: Control Structures I (Selection)
elementary programming
Chapter 2 Programming Basics.
Using C++ Arithmetic Operators and Control Structures
Flow of Control.
Operator King Saud University
Expressions and Assignment Statements
Programming Fundamental-1
Presentation transcript:

Basic Programming Concepts Imran Rashid CTO at ManiWeber Technologies

Outline Program, Programming & Programming Languages Variables, Constants & Data Types Operators in Programming Decision Making in Programming Iterations in Programming

Program, Programming & Programming Languages

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

Program, Programming & Programming Languages Type of Programming Languages

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

Program, Programming & Programming Languages Type of Language Translators

Program, Programming & Programming Languages Compiler v.s Interpreter

Program, Programming & Programming Languages Type of Errors in Programming

Variables, Constants & Data Types

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

Variables, Constants & Data Types

Variables, Constants & Data Types

Variables, Constants & Data Types

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: 3.14159, 5.0, -12345.345 Size: 32 bits & 64 bits Character: can store a character Examples: ‘A’, ‘a’, ‘*’, ‘3’, ‘ ’, ‘+’ Size: 8 bits & 16 bits

Operators in Programming

Operators in Programming Arithmetic Operators Addition (+) Subtraction (-) Division (/) Multiplication (*) Modulus (%) Examples distance = rate * time; netIncome = income - tax; speed = distance / time; area = PI * radius * radius;

Operators in Programming Suppose x and y are two integer variables, whose values are 13 and 5 respectively

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

Operators in Programming Relational Operators Used to compare two quantities

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

Decision Making in Programming

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

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 (&&, ||, !)

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

Decision Making in Programming The if-else Statement These statements can be nested

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

Iterations in Programming

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

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

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

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

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)?

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#

Any ?