BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

Size: px
Start display at page:

Download "BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2"

Transcription

1 1 BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER Chapter 2

2 2 3 Types of Problems that can be solved on computers : Computational problems involving some kind of mathematical processing Logical Problems involving relational or logical processing Repetitive Problems involving repeating a set of mathematical and/or logical instructions.

3 Fundamental Concepts 3 The building blocks of equations and expressions Constants Variables Operators Functions Expressions equations

4 Constants 4 A value a specific alphabetical and/or numeric value Does not change during the processing of all the instructions in a solution Can be of any data type Numeric, alphabetical or special symbols Examples 3, 5, 10, Sara, +, -, /

5 5 Constants In some programming languages, constants can be named Provides protection to the constant value and other areas of the program. Cannot be changed once given initial value Example SalesTaxRate = 6 Commission_Rate = 6 Note: no spaces within variable names

6 Variables 6 May change during processing In many programming languages, variables are called identifiers. The variable name should be consistent with what the value of the variable represents A name is assigned to each variable used in a solution. The name references the memory area where the value is stored.

7 Variables 7 The computer uses the name as a reference to help it find that value in its memory. May be of any data type Examples Age, LastName, Address, PayRate

8 Difference between name of a variable and value of a variable 8 The rule for naming variable differ from language to language. there will be no character- length limitations for variable. The computer uses the variable name to find the location; it uses the value found at the memory location to do the processing.

9 Rules for Naming Variables 9 1- name variable according to what it represents Hours for hours worked. x H for hours worked (correct but not recommended because it is not clear enough). PayRate for rate of pay. x P for rate of pay (correct but not recommended because it is not clear enough). Create as short a name as possible, but one that clearly represents the variable.

10 2- Do not use spaces HoursWorked for hours worked (correct). x Hours Worked Incorrect because the space. StudentName for student name (correct). x Student Name Incorrect because the space.

11 3 - Start a variable name with a letter. Hours for hours worked (correct). x 2hours Incorrect because starting by number 2. Student for student name (correct). x 8Student Incorrect because starting by number 8

12 4- Do not use a dash ( or any other symbol that is used as mathematical operator). For example: StudentName for student name (correct). x Student-Name Incorrect because using a dash symbol.

13 Be consistent when using upper-and lower case characters. HOURS is different variable name than Hours For example: Age and AGE are two variables (not the same variable).

14 5 - Exact variable name must be used in all places where the data item is used. For example: If the data item hours worked has the variable name of Hours, Hours must be used consistently. Hours hours worked x Hrs or HoursWorked (Incorrect, it is a new variable).

15 6 - Use the naming convention specified by the company where you work. The naming convention is uppercase for the first character in each of the words in the name, with no spaces between words in the name. Variable Names PayRate Rate HoursWorked Amount Tempreature StudentName Constant Name PI KCONATANT MULTIPLIER

16 Data type 16 Data unorganized facts. They go into the computer as input. Information The output of processing of input. Is printed in the form of reports.

17 17 Processing Data How a computer Balances a Checkbook Data Input Data Processed into Information Output Report Checks Deposits Bank Charge Calculates the Balance Balance Sheet

18 18 Data Types Data can come with different type :(Most common types) Numeric Character Logical Computer should know the data type of each variable or constant. Most languages include other data types Date User-defined

19 Numeric Types 19 Include all types of numbers. The only data type that can be used in numeric calculation. Integers 3, 5, -5, 0, -1 and 32,767 Real numbers (floating point numbers) Are whole numbers plus decimal parts (3.1459, -5745) Scientific Notation 2.3E5 or 5.4E-3, where E stands for the Power of 10 Can be Positive or Negative. Numeric data are used for value ( salary, rate of pay)

20 Data Types & Data Sets 20 Each data type has a data set A data set is the set of value that are allowed in a particular data type.

21 Data Types & Data Sets Data Type Data Set Examples Numeric :Integer All whole numbers Numeric :Real All real numbers (whole + decimal) Character (uses quotation marks) All letters, numbers, and special symbols A, a, 1, 5, +, % String (uses quotation marks) Combinations of more than one character Mulder Scully Logical True or False True False 21

22 Character Types 22 Alphanumeric data set Consists of all single-digit numbers, letters, and special characters available to the computer contained within quotation marks An upper case letter is considered a different character from a lower case letter.

23 Table of ASCII Characters 23 Char Dec Char Dec A 65 a 97 B 66 b 98 C 67 c 99 D 68 d 100 E 69 e

24 24 String Data Type Made up of one or more characters. Contained within quotation marks Cannot be used within calculations Items that would not have mathematical computations performed on them should be designed string data type. some languages do not differentiate between characters and strings.

25 Strings - Caution is not the same thing as 123 The first one is a string The second one is a number Becomes important when deciding when a piece of data is a string or a number Ex. Social Security Numbers The first one contains 11 characters and is left aligned whereas the second contains 9 numbers and is right aligned

26 Comparing Characters & Strings 26 The computer s particular coding scheme (ASCII, Unicode, or EBCDIC) converts the character to its associated ordinal number The computer gives each character a number. The number representation is necessary because the computer work only with numbers. example: A 65 a 97

27 Comparing Characters & Strings 27 Note: Uppercase letters have a smaller ordinal values than lowercase letters A = 65 whereas a = 97 (ASCII 8-bit) Once converted, each character, one at a time, can be compared. Example: Banana is larger than Apple because B has larger number representing it than A COP1006 McManus

28 Comparing Characters & Strings 28 Concatenation could be used to join a first name with a last name or to join pieces of data together. Characters and String data can be compared and arranged in alphabetical order (as ascending order).

29 Concatenation 29 Joins character data or string data together with the + operator. Example : James + + T. + + Kirk = James T. Kirk = 1003 not 103

30 Logical (Boolean) Data Type 30 Consists of two value in the data set : True and False Some languages accept yes, T, and Y for true. no, F, and N c for False. Example : Check someone s credit record ; true means credit is ok. False means it s not ok. For example, the variable Warm might be declared as a logical data type to describe if temperature values are warm or not.

31 Other Data Types 31 date data type and user defined data type Date data type is a number for the date that is the number of days from a certain date. Is a numeric data type because you can perform mathematical calculation on any date.

32 32 User-Defined Data Types User-defined Data types Defined by the user as a new data type Example( kind of cars ) Car_Type End GMC Ford Toyota

33 Rules for Data Types 33 Programmer chooses the data type during the programming process. The data that define the value of a variable or a constant will be one of three data type : numeric, character or logical. Data types can not be mixed, Once a constant or a variable has been given a data type it cannot change. All data to be used in calculations must be declared as a numeric data type.

34 Rules for Data Types 34 Each data type uses a data set or domain Numeric uses the set of all base 10 numbers, the plus sign(+), and the negative sign(-). Characters all characters included in the computer. Logical the words true and false

35 Examples of Data Types Data The price of item 4.25 Account number Room numbers 112 Name of company Apple Macintosh Check status Pass/Fail True or False Date 12/3/2011 Data Type Numeric Real String Numeric Integer String Logical Date or String

36 36 How the Computer Stores Data Data Storage Each variable name is given a memory location Each memory location can hold one and only one value at a time. This memories are temporary storage, when a user enters a new value the old one is destroyed Example: COP1006 McManus

37 Functions 37 Small sets of instructions that perform specific tasks and return values. FunctionName(data) Are used as parts of instructions in a solution. Two types: Pre-defined each language has a set of functions within it. User-defined Programmers write their own functions.

38 Functions 38 The name of function may vary from language to language Benefits Reduces the amount of code that needs to be written, thus reducing errors of repetition.

39 Function Parameters 39 the data which is listed as part of the function and are called parameters. In Sqrt(n), the n represents the parameter, in this case a number In Value(s), the s represents a string Not all function need parameters In Random, no data are needed Parameter can be a constant, a variable, or an expression

40 Function Types Mathematical 2. String Used in science and business, Calculate such things as square root, absolute value Manipulate string variable 3. Conversion Convert data from one data type to another 4. Statistical 5. Utility Important in business programming

41 Mathematical Functions 41 Function Form Example Result Square Root Sqrt(n) Sqrt(4) 2 Absolute Abs(n) Abs(-3), Abs(3) 3 Rounding Round(n,n1) Round (3.7259,2) 3.73 Integer Integer(n) Integer(5.7269) 5 Random Random Random Sign of a number Sign(n) Sign(7.39) 1

42 String Functions 42 Function Form Example Result Middle String Mid(s, n1, n2) Mid(S,3,2) where S = "Thomas" "om" Left String Left(s, n) Left(S,3) where S = "Thomas" "Tho" Right String Right(s, n) Right(S, 3) where S = "Thomas" "mas" Length(S) where S Length String Length(s) = "Thomas" 6

43 Conversion Functions 43 Function Form Example Result Valued Conversion Value(s) Value("-12.34") String Conversion String(n) String(-12.34) "-12.34" For example, since character string can not be used in calculations, one of these functions would convert a string value to a numeric value

44 Statistical Functions 44 Function Form Example Result Average Average(list) Average(5, 3, 8, 6) 5.5 Maximum Max(list) Max(5, 3, 8, 6) 8 Minimum Min(list) Min(5, 3, 8, 6) 3 Summation Sum(list) Sum (5, 3, 8, 6) 22

45 Utility Functions 45 Functio Definition Exampl Result n e Date Time Error Returns the current date from the system. The date may be in various forms: mm/dd/yy, day only, month only, year only, or Julian calendar Returns the current time from the system. The time may be in various forms: hh:mm:ss, seconds from midnight, or minutes from midnight Returns control to the program when a systems error occurs. Date Time 09/15/08 9:22:34

46 Operators 46 The data connectors within expressions and equations. thy tell the computer how to process the data. They also tell the computer what type of the processing( mathematical, logical, or..) needs to done.

47 The operand are the data that the operator connect and processes ( constants or variable). The data type of the operands of an operator must be the same. The resultant is the answer that results when the operation is completed. The data type of operands and the resultant depends on the operator. Ex : 5 + 7

48 Operator Types Mathematical The data types of operands and resultants of mathematical operators are always numeric +, -, *, / \, Mod ( used in business ) ^ functions

49 Two Special Math Operators 49 Integer Division (\) If given a Floating Point number, the number is rounded first before division occurs. Modulo Division (Mod) or Modulus The remainder part of the answer is returned.

50 Mathematical Operators Operator Compute r Symbol Operation Resultant Addition Subtraction Multiplication * 8.0 * Division / 9.0/ Integer division \ 9\4 2 Modulo division MOD 9 MOD 4 1 Power ^ 3^2 9

51 51 Relational Operators Relational operators Perform comparisons the use of relational operators is the only way for the computer to make decisions. The resultant of relational operation is logical data type. The operand s can be numeric or character

52 Relational operatores Operator Computer Symbol Operation Resultant Equal to = 5 = 7 False Less than < 5 < 7 True Greater than > 5 > 7 False Less than or equal to < = 5 < = 7 True Greater than or equal to > = 5 > = 7 False Not < > 5 < > 7 True

53 Logical Operators 53 AND, OR, NOT used to connect relational expressions. a = b AND c < d Perform operations on logical data. They are defined by using Truth Tables

54 Logical opeartores Operator Compute r Symbol Operation Resultant Not NOT NOT True False And AND True AND True True Or OR True OR False True

55 The AND Operator 55 Significance: The only time the result is True is if both A and B are True. A B A AND B True True True True False False False True False False False False

56 The OR Operator 56 Significance: The only time the result is False is if both A and B are False. A B A OR B True True True True False True False True True False False False

57 57 The NOT Operator Also called the logical complement or logical negation Significance: Whatever the value of A is, NOT A will be the opposite. A True False NOT A False True

58 58 Hierarchy of Operations Data and Operators are combined to form expressions and equations To evaluate these in the proper order, a hierarchy of operations, or Order of Precedence, is used. The processing of the operands always starts with functions then the innermost parentheses and works outward, and processes from left to right Note: Whenever you want to clarify an equation, use the parentheses!

59 The Order of Precedence 59 Order of Operations Operand Data Type Resultant Data Type ( ) reorders the hierarchy; all operations are completed within the parentheses using the same hierarchy Power ^ \, MOD *, / +, _ =, <, >, < =, > =, < > NOT AND OR Numeric Numeric Numeric Numeric Numeric or string or character Logical Logical Logical Numeric Numeric Numeric Numeric Logical Logical Logical Logical

60 Example 60 Evaluate the following: A = True, B = False, C = True, D = False A or B or C and D and A and B and (not C) or (not D) To do this, we create what s called an Evaluation Tree

61 61 A or B or C and D and A and B and (not C) or (not D) True False False True False False False True True

62 62 Expressions & Equations Expressions Process the data and the operands, through the use of the operators Does not store the resultant (answer) Examples : to find the number of square feet in a room : Length * Width

63 Equations 63 Same as an expression, except the equation stores the resultant (answer) in a memory location takes on the value of not equals Examples Area = Length * Width Often called Assignment Statements

64 Expressions A+B A and B are numeric. The resultant is numeric and is not stored A < B A and B are numeric, character, or string. The resultant is logical and is not stored. A OR B A and B are logical. The resultant is logical and is not stored Equations C= A + B C,A and B are numeric. The resultant is stored in C. C = A < B A and B are numeric, character, or string. The resultant is stored in C ; C is logical. C = A OR B C,A and B are logical. The resultant is stored in C.

65 Example : evaluating a mathematical expression. 5 * ( X + Y ) 4 * Y / ( Z + 6 ) uses the following values to evaluate the expression : X = 2 Y = 3 Z = 6 Operation resultant 1. X + Y 5 2. Z * resultant of * Y Resultant of 4 / resultant of Resultant of 3 resultant of 5 24

66 Example : evaluating a relational expression. A 2 B uses the following values to evaluate the expression : A = 6 b= 8 Operation resultant 1. A Resultant of 1 B false

67 Example : evaluating a logical expression. A AND B OR C AND A uses the following values to evaluate the expression : A = true B = false C = true Operation resultant 1. A AND B false 2. C AND A true 3. Resultant of 1 OR resultant of 2 true

68 Straight-Line Form 68 Algebraic Expressions cannot be represented in the computer. They must be converted to a form the computer will recognize. Thus, Straight Line Form Y ( X ( X ( X Y ) = (X Y) / ( (X + Y)^2 / (X Y )^2 ) Y ) Y ) 2 2 straight line form

69 Attachment: ASCII Coding 69 COP1006 McManus

Problem Solving. Problem Solving Concept for Computer Science

Problem Solving. Problem Solving Concept for Computer Science Problem Solving Problem Solving Concept for Computer Science by Noor Azida Binti Sahabudin Faculty of Computer Systems & Software Engineering azida@ump.edu.my OER Problem Solving by Noor Azida Binti Sahabudin

More information

Outline. Data and Operations. Data Types. Integral Types

Outline. Data and Operations. Data Types. Integral Types Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

More information

CHAPTER 3: CORE PROGRAMMING ELEMENTS

CHAPTER 3: CORE PROGRAMMING ELEMENTS Variables CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby A variable is a single datum or an accumulation of data attached to a name The datum is (or data are) stored in

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review

StudyHub+ 1. StudyHub: AP Java. Semester One Final Review StudyHub+ 1 StudyHub: AP Java Semester One Final Review StudyHub+ 2 Terminology: Primitive Data Type: Most basic data types in the Java language. The eight primitive data types are: Char: A single character

More information

Chapter 2 Working with Data Types and Operators

Chapter 2 Working with Data Types and Operators JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

More information

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual: Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Midterms Save the Dates!

Midterms Save the Dates! University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Primitive Data Types Arithmetic Operators Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch 4.1-4.2.

More information

Building Java Programs. Chapter 2: Primitive Data and Definite Loops

Building Java Programs. Chapter 2: Primitive Data and Definite Loops Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Chapter 2.4: Common facilities of procedural languages

Chapter 2.4: Common facilities of procedural languages Chapter 2.4: Common facilities of procedural languages 2.4 (a) Understand and use assignment statements. Assignment An assignment is an instruction in a program that places a value into a specified variable.

More information

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program 1 By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program variables. Apply C++ syntax rules to declare variables, initialize

More information

3.1. Chapter 3: The cin Object. Expressions and Interactivity

3.1. Chapter 3: The cin Object. Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-1 The cin Object Standard input stream object, normally the keyboard,

More information

Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz

Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT Faculty of Management and Commerce South Eastern University of Sri Lanka Variables

More information

3. Types of Algorithmic and Program Instructions

3. Types of Algorithmic and Program Instructions 3. Types of Algorithmic and Program Instructions Objectives 1. Introduce programming language concepts of variables, constants and their data types 2. Introduce types of algorithmic and program instructions

More information

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Chapter Two PROGRAMMING WITH NUMBERS AND STRINGS

Chapter Two PROGRAMMING WITH NUMBERS AND STRINGS Chapter Two PROGRAMMING WITH NUMBERS AND STRINGS Introduction Numbers and character strings are important data types in any Python program These are the fundamental building blocks we use to build more

More information

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14

Chapter 3: Expressions and Interactivity. Copyright 2012 Pearson Education, Inc. Thursday, October 9, 14 Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

More information

Expressions and Variables

Expressions and Variables Expressions and Variables Expressions print(expression) An expression is evaluated to give a value. For example: 2 + 9-6 Evaluates to: 5 Data Types Integers 1, 2, 3, 42, 100, -5 Floating points 2.5, 7.0,

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

Lesson 02 Working with Data Types. MIT 31043: VISUAL PROGRAMMING By: S. Sabraz Nawaz Senior Lecturer in MIT

Lesson 02 Working with Data Types. MIT 31043: VISUAL PROGRAMMING By: S. Sabraz Nawaz Senior Lecturer in MIT Lesson 02 Working with Data Types MIT 31043: VISUAL PROGRAMMING Senior Lecturer in MIT Variables A variable is a storage location in memory that is represented by a name. A variable stores data, which

More information

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object

3.1. Chapter 3: The cin Object in Program 3-1. Displaying a Prompt 8/23/2014. The cin Object Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object The cin Object in Program 3-1 Standard input object Like cout, requires iostream file Used to read input from keyboard Information

More information

Chapter 3: Expressions and Interactivity

Chapter 3: Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Information retrieved from cin with >>

More information

Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17. Fundamental Concepts Expressed in JavaScript Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements

What we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements Topic 4 Variables Once a programmer has understood the use of variables, he has understood the essence of programming -Edsger Dijkstra What we will do today Explain and look at examples of primitive data

More information

DATA AND ABSTRACTION. Today you will learn : How to work with variables How to break a program down Good program design

DATA AND ABSTRACTION. Today you will learn : How to work with variables How to break a program down Good program design DATA AND ABSTRACTION Today you will learn : How to work with variables How to break a program down Good program design VARIABLES Variables are a named memory location Before you use a variable you must

More information

Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1

Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1 CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity

More information

Constants and Variables

Constants and Variables DATA STORAGE Constants and Variables In many introductory courses you will come across characteristics or elements such as rates, outputs, income, etc., measured by numerical values. Some of these will

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

More information

Ex: If you use a program to record sales, you will want to remember data:

Ex: If you use a program to record sales, you will want to remember data: Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Reserved Words and Identifiers

Reserved Words and Identifiers 1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

More information

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma. REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

More information

KNOWLEDGE OF NUMBER SENSE, CONCEPTS, AND OPERATIONS

KNOWLEDGE OF NUMBER SENSE, CONCEPTS, AND OPERATIONS DOMAIN I. COMPETENCY 1.0 MATHEMATICS KNOWLEDGE OF NUMBER SENSE, CONCEPTS, AND OPERATIONS Skill 1.1 Compare the relative value of real numbers (e.g., integers, fractions, decimals, percents, irrational

More information

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C

2/5/2018. Expressions are Used to Perform Calculations. ECE 220: Computer Systems & Programming. Our Class Focuses on Four Types of Operator in C University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 220: Computer Systems & Programming Expressions and Operators in C (Partially a Review) Expressions are Used

More information

Operators and Expressions:

Operators and Expressions: Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

More information

ITP 342 Mobile App Dev. Code

ITP 342 Mobile App Dev. Code ITP 342 Mobile App Dev Code Comments Variables Arithmetic operators Format specifiers if - else Relational operators Logical operators Constants Outline 2 Comments For a single line comment, use // The

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Basic Operations jgrasp debugger Writing Programs & Checkstyle Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent

More information

Python Programming Exercises 1

Python Programming Exercises 1 Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them

More information

1-3 Variables and Algebraic Expressions. Warm Up Problem of the Day Lesson Presentation Lesson Quizzes

1-3 Variables and Algebraic Expressions. Warm Up Problem of the Day Lesson Presentation Lesson Quizzes Warm Up Problem of the Day Lesson Presentation Lesson Quizzes Warm Up Evaluate. 1. 5(7) 1 2. 7(18 11) 3. 22 + 17 8 + 3 4. 36 + 15(40 35) 5. 3 3 + 7(12 4) Problem of the Day If charged per cut, how much

More information

Types and Expressions. Chapter 3

Types and Expressions. Chapter 3 Types and Expressions Chapter 3 Chapter Contents 3.1 Introductory Example: Einstein's Equation 3.2 Primitive Types and Reference Types 3.3 Numeric Types and Expressions 3.4 Assignment Expressions 3.5 Java's

More information

Arithmetic Operations

Arithmetic Operations 232 Chapter 4 Variables and Arithmetic Operations Arithmetic Operations The ability to perform arithmetic operations on numeric data is fundamental to computer programs. Many programs require arithmetic

More information

2.Simplification & Approximation

2.Simplification & Approximation 2.Simplification & Approximation As we all know that simplification is most widely asked topic in almost every banking exam. So let us try to understand what is actually meant by word Simplification. Simplification

More information

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT LESSON VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT PROF. JOHN P. BAUGH PROFJPBAUGH@GMAIL.COM PROFJPBAUGH.COM CONTENTS INTRODUCTION... Assumptions.... Variables and Data Types..... Numeric Data Types:

More information

Introduction to Computer Use II

Introduction to Computer Use II Winter 2005 (Section M) Topic B: Variables, Data Types and Expressions Wednesday, January 18 2006 COSC 1530, Winter 2006, Overview (1): Before We Begin Some administrative details Some questions to consider

More information

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators JAVA Standard Edition Java - Basic Operators Java provides a rich set of operators to manipulate variables.

More information

VARIABLES & ASSIGNMENTS

VARIABLES & ASSIGNMENTS Fall 2018 CS150 - Intro to CS I 1 VARIABLES & ASSIGNMENTS Sections 2.1, 2.2, 2.3, 2.4 Fall 2018 CS150 - Intro to CS I 2 Variables Named storage location for holding data named piece of memory You need

More information

Topic 4 Expressions and variables

Topic 4 Expressions and variables Topic 4 Expressions and variables "Once a person has understood the way variables are used in programming, he has understood the quintessence of programming." -Professor Edsger W. Dijkstra Based on slides

More information

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110. Lecture 2 Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

More information

Chapter 3: Operators, Expressions and Type Conversion

Chapter 3: Operators, Expressions and Type Conversion 101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

More information

Lecture 3 Tao Wang 1

Lecture 3 Tao Wang 1 Lecture 3 Tao Wang 1 Objectives In this chapter, you will learn about: Arithmetic operations Variables and declaration statements Program input using the cin object Common programming errors C++ for Engineers

More information

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

Chapter 2. Data Representation in Computer Systems

Chapter 2. Data Representation in Computer Systems Chapter 2 Data Representation in Computer Systems Chapter 2 Objectives Understand the fundamentals of numerical data representation and manipulation in digital computers. Master the skill of converting

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

More information

Scheme of work Elementary 1, the maths pathway

Scheme of work Elementary 1, the maths pathway Objective Code Objective Exemplification Links to prior objectives Resources, enrichment, notes E1.1 Multiply and divide numbers by 10, 100 and 1000 including decimals. 6 x 10, 6.5 x 10, 0.65 10 3 x 100,

More information

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel Introduction: PHP (Hypertext Preprocessor) was invented by Rasmus Lerdorf in 1994. First it was known as Personal Home Page. Later

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

More information

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

More information

Basic data types. Building blocks of computation

Basic data types. Building blocks of computation Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators 1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with

More information

Bits, Words, and Integers

Bits, Words, and Integers Computer Science 52 Bits, Words, and Integers Spring Semester, 2017 In this document, we look at how bits are organized into meaningful data. In particular, we will see the details of how integers are

More information

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd

19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd 19 Much that I bound, I could not free; Much that I freed returned to me. Lee Wilson Dodd Will you walk a little faster? said a whiting to a snail, There s a porpoise close behind us, and he s treading

More information

On a 64-bit CPU. Size/Range vary by CPU model and Word size.

On a 64-bit CPU. Size/Range vary by CPU model and Word size. On a 64-bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Unit 1. Word Definition Picture. The number s distance from 0 on the number line. The symbol that means a number is greater than the second number.

Unit 1. Word Definition Picture. The number s distance from 0 on the number line. The symbol that means a number is greater than the second number. Unit 1 Word Definition Picture Absolute Value The number s distance from 0 on the number line. -3 =3 Greater Than The symbol that means a number is greater than the second number. > Greatest to Least To

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu

More information

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example

Admin. CS 112 Introduction to Programming. Recap: Java Static Methods. Recap: Decomposition Example. Recap: Static Method Example Admin CS 112 Introduction to Programming q Programming assignment 2 to be posted tonight Java Primitive Data Types; Arithmetic Expressions Yang (Richard) Yang Computer Science Department Yale University

More information

Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left

Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left Multiply Decimals Multiply # s, Ignore Decimals, Count # of Decimals, Place in Product from right counting in to left Dividing Decimals Quotient (answer to prob), Dividend (the # being subdivided) & Divisor

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Introduction to Computer Programming

Introduction to Computer Programming Introduction to Computer Programming Lecture 2- Primitive Data and Stepwise Refinement Data Types Type - A category or set of data values. Constrains the operations that can be performed on data Many languages

More information

Variable A variable is a value that can change during the execution of a program.

Variable A variable is a value that can change during the execution of a program. Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

Department of Computer Science

Department of Computer Science Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and

More information

2.2 Order of Operations

2.2 Order of Operations 2.2 Order of Operations Learning Objectives Evaluate algebraic expressions with grouping symbols. Evaluate algebraic expressions with fraction bars. Evaluate algebraic expressions using a graphing calculator.

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long

Primitive Types. Four integer types: Two floating-point types: One character type: One boolean type: byte short int (most common) long Primitive Types Four integer types: byte short int (most common) long Two floating-point types: float double (most common) One character type: char One boolean type: boolean 1 2 Primitive Types, cont.

More information

Introduction to TURING

Introduction to TURING Introduction to TURING Comments Some code is difficult to understand, even if you understand the language it is written in. To that end, the designers of programming languages have allowed us to comment

More information

LCSL Reference Manual

LCSL Reference Manual LCSL Reference Manual Sachin Nene, Chaue Shen, Bogdan Caprita, Julian Maller 1.1 Lexical Conventions 1.1.1 Comments Comments begin with (* and end with *) 1.1.2 Variables Variables consist solely of alphanumeric

More information

California Standard Study Island Topic Common Core Standard

California Standard Study Island Topic Common Core Standard State: CA Subject: Math Grade Level: 4 California Standard Study Island Topic Standard NUMBER SENSE 1.0: Students understand the place value of whole numbers and decimals to two decimal places and how

More information

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions Variable is a letter or symbol that represents a number. Variable (algebraic)

More information

L-System Fractal Generator: Language Reference Manual

L-System Fractal Generator: Language Reference Manual L-System Fractal Generator: Language Reference Manual Michael Eng, Jervis Muindi, Timothy Sun Contents 1 Program Definition 3 2 Lexical Conventions 3 2.1 Comments...............................................

More information

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types

9/2/2016. Expressions are Used to Perform Calculations. ECE 120: Introduction to Computing. Five Arithmetic Operators on Numeric Types University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Expressions are Used to Perform Calculations Let s talk in more detail starting

More information