# ENGINEERING 1020 Introduction to Computer Programming M A Y 2 6, R E Z A S H A H I D I

Size: px
Start display at page:

Download "ENGINEERING 1020 Introduction to Computer Programming M A Y 2 6, R E Z A S H A H I D I"

## Transcription

1 ENGINEERING 1020 Introduction to Computer Programming M A Y 2 6, R E Z A S H A H I D I

2 Today s class Constants Assignment statement Parameters and calling functions Expressions Mixed precision arithmetic Type casting

3 Assignment statements An assignment statement gives a value to a variable. The left-hand side of an assignment statement must consist of only one variable. This basically means we can t have an implicit assignment, e.g. y+2 = 5; 7*x+3=10 General form of variable assignment is: variable = expression;

4 Assignment statements As we just saw, a general variable assignment is of the form: variable = expression;; This means that we should first evaluate the expression on the right, and then assign it to the variable on the left. The variable on the left of the assignment can appear on the right side of the assignment.

5 Example of variable on both sides of assignment We will see later that having a variable on both sides of an assignment statement is useful in control structures like for and while loops. If we wish to increment the value of a variable x, we have two options: int x=5; int y; y = x+1; We may not want to allocate a new variable just for this. Also may make the code more complicated than needed.

6 Example of variable on both sides of assignment Instead we can do the following: int x=5; x = x+1; In a mathematical context, this would be impossible. x =x + 1; has no solution! However in C++, this is valid. It means use the current value of x, add 1 to it, and then store the value back in the variable x. This updates the value of x with a value based on its current value.

7 Back to the drawer representation of variables For example, x=x+1 would take the value of x out of its drawer, and add 1 to it, and then put it back into its drawer again tmp deg x

8 Parameters as variables The parameters of a function can be thought of as variables. We already saw that functions must be declared before they are used, along with their parameters. These parameters are of a certain type. In order to make calling functions easier for the programmer, we can use different names for the variables that are passed as parameters, or just pass values.

9 Example Calling Functions different ways The parameters of a function are like variables. Consider a function that converts a height in feet and inches to centimetres. The prototype (declaration) of the function could be something like: double convertheight(int feet, int inches);

10 Example And the definition of the function could be: /* convertheight ***************************************** * feet - number of feet in person s >= 0 * inches number of inches in person s 0 * number of centimetres in height. **************************************************** ****/ double convertheight(int feet, int inches) { int numinches; // number of inches in height double numcentimetres; // number of cm. in height numinches = 12*feet+ inches; numcentimetres = numinches*2.54; return numcentimetres; }

11 Example Calling the function We can call the function in different ways Assume that a person s height is 5 feet, 9 inches. Then to convert this height to centimetres, we could call convertheight in at least four different ways: 1. Call with constant values: double numcentimetres; numcentimetres = convertheight(5,9); This works, but may be tricky if we want to code many calls to convertheight.

12 Example Calling the Function 2. call with variable names (same as prototype): Notice here that the variables have the same name as in the definition of the function. int feet = 5; int inches = 9; double numcentimetres; numcentimetres = convertheight(feet,inches);

13 Example Calling the Function 3. Call with variable names (different than prototype): int numfeet = 5; int numinches = 9; double numcentimetres; numcentimetres=convertheight(numfeet,numinches );

14 Example Calling the Function 4. Call with variable names in the wrong order! This is wrong, but this shows a possible error that can happen if the parameters you call the function with are not descriptive: int feet = 5; int inches = 9; double numcentimetres; numcentimetres = convertheight(inches,feet);

15 Symbolic Constants A symbolic constant is a value that does not change and cannot change throughout a program. General form: const type VARIABLENAME = expression; Examples (from Lecture Notes): const int MONTHS = 12; const double PI = 4 * atan(1.0); const char YES = 'Y'; const int LONG_CONSTANT_NAME = 17; Good to use symbolic constants for values that are used many times and do not change during the program.

16 Expressions We have seen in variable declaration statements, where the value of the variable is initialized that the general form of the declaration is: type var = expression; We haven t yet explained what an expression is. They are somewhat similar to math expressions, but more general.

17 Expressions The definition of an expression is (from the Lecture notes): A combination of variables, constants, operators and functions which is progressively evaluated an operation at a time until it is reduced to a final value. An expression is always reduced to a single value (very important). It does not include C++ keywords!

18 Arithmetic Expressions An expression which uses arithmetic operators. There are different operators based on whether we are using integers or doubles. Operators can be either unary or binary. A unary operator only takes one argument. A binary operator takes two arguments. If we are using doubles, then the usual arithmetic operators that you have learned in math are valid. These are: + - * /

19 Arithmetic Expressions The operators we are allowed to use depend on the data type. For arithmetic expressions there are two data types that we consider in this course, int and double. For real numbers, we have the usual operators: + - * / + and can either be unary or binary operators. This is because we can have positive and negative numbers, e.g or -25. The unary + sign is strictly not necessary, however is included for consistency with the sign.

20 Arithmetic Expressions For integers, we have the usual operators, both unary and binary. We also have an extra operator: the % operator. This is the modulus operator. This is like the case for calculating times, e.g. 9 hours after 5 p.m. is 2 a.m. (5+9) % 12 = 2

21 Integer operators / and % Look at example in Lecture Slides on / and % operators. The / and % operators for int data types are like the results of long division: a / b is the quotient of a and b (always an integer) a % b is the remainder when a is divided by b (also always an integer) Remember that there is no double % operator!

22 Computer Arithmetic There are two types of number variables in C++ that we use in this course. These are int and double. The compiler knows how to do either integer arithmetic (only adding, multiplying... integers together), or floating point arithmetic (only adding, multiplying... single or double precision numbers together) If we wish to mix up operations with integers and doubles for example, then the compiler automatically converts from one type to the other.

23 Data type conversions Whenever there is at least one double in an arithmetic expression, all variables in that expression are converted to double precision. Converting from an int to double can be called upcasting, while converting from a double to int can be called downcasting (truncation). Converting from a double to an integer is not rounding! So for example, int x = 5.6; will set the value of x to 5 and not 6.

24 Type casting Sometimes we wish to force the compiler to switch from one type to the other (e.g. when mixing integers and floating points in an expression). This is called type casting. For example, let us say that we wish to automatically truncate the answer of a double precision floating point number. This can be done with the following piece of code, e.g.: int wholepart; float x = 3.6; wholepart = (int) x;

25 Example of automatic type conversion See the quadratic example in the Lecture notes.

26 Composite Assignments Shorthand for assignments like x = x+1; or x =x*9; See Lecture Notes

### 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

### } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.

### ENGI Introduction to Computer Programming M A Y 2 8, R E Z A S H A H I D I

ENGI 1020 - Introduction to Computer Programming M A Y 2 8, 2 0 1 0 R E Z A S H A H I D I Last class Last class we talked about the following topics: Constants Assignment statements Parameters and calling

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Programming in C++ 5. Integral data types

Programming in C++ 5. Integral data types! Introduction! Type int! Integer multiplication & division! Increment & decrement operators! Associativity & precedence of operators! Some common operators! Long

### Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

### 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

### LECTURE 3 C++ Basics Part 2

LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special built-in symbols that have functionality, and work on operands. Operators are actually functions that use

### 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

### Fixed-Point Math and Other Optimizations

Fixed-Point Math and Other Optimizations Embedded Systems 8-1 Fixed Point Math Why and How Floating point is too slow and integers truncate the data Floating point subroutines: slower than native, overhead

### 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

### CS Programming I: Primitives and Expressions

CS 200 - Programming I: Primitives and Expressions Marc Renault Department of Computer Sciences University of Wisconsin Madison Spring 2018 TopHat Sec 3 (AM) Join Code: 427811 TopHat Sec 4 (PM) Join Code:

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

### COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016 More Tutoring Help The Engineering Peer Tutoring Services (EPTS) is hosting free tutoring sessions

### CS102: Variables and Expressions

CS102: Variables and Expressions The topic of variables is one of the most important in C or any other high-level programming language. We will start with a simple example: int x; printf("the value of

### 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

### 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

### Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

### 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

### Operators. Java Primer Operators-1 Scott MacKenzie = 2. (b) (a)

Operators Representing and storing primitive data types is, of course, essential for any computer language. But, so, too, is the ability to perform operations on data. Java supports a comprehensive set

### Expressions and Casting

Expressions and Casting C# Programming Rob Miles Data Manipulation We know that programs use data storage (variables) to hold values and statements to process the data The statements are obeyed in sequence

### Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

### 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.

### ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

### Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

### 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

### Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.

### 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

### Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Operators Overview Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators Operands and Operators Mathematical or logical relationships

### QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

QUIZ 1. Explain the meaning of the angle brackets in the declaration of v below: This is a template, used for generic programming! QUIZ 2. Why is the vector class called a container? 3. Explain how the

### 1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary

Topic 2 1. Variables 2. Arithmetic 3. Input and output 4. Problem solving: first do it by hand 5. Strings 6. Chapter summary Arithmetic Operators C++ has the same arithmetic operators as a calculator:

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

### Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

### CIS133J. Working with Numbers in Java

CIS133J Working with Numbers in Java Contents: Using variables with integral numbers Using variables with floating point numbers How to declare integral variables How to declare floating point variables

### C introduction: part 1

What is C? C is a compiled language that gives the programmer maximum control and efficiency 1. 1 https://computer.howstuffworks.com/c1.htm 2 / 26 3 / 26 Outline Basic file structure Main function Compilation

### Information Science 1

Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

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

### 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

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

### 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

### Values, Variables, Types & Arithmetic Expressions. Agenda

Values, Variables, Types & Arithmetic Expressions Lecture 2 Object-Oriented Programming Agenda Inside of a Computer Value Variable Data Types in Java Literals Identifiers Type conversions Manipulating

### Lesson 3: Arithmetic & Casting. Pic 10A Ricardo Salazar

Lesson 3: Arithmetic & Casting Pic 10A Ricardo Salazar (2.4) Constants Sometimes we want a 'variable' that does not vary!? (OK that does not make sense... but how about a 'house' whose guest is always

### Programming in C++ 6. Floating point data types

Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction

### 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

### Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 Advance mode: Auto

CS 170 Java Programming 1 Expressions Slide 1 CS 170 Java Programming 1 Expressions Duration: 00:00:41 What is an expression? Expression Vocabulary Any combination of operators and operands which, when

### Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

Python Numbers CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17 1 (adapted from Meeden, Evans & Mayberry) 2 Learning Outcomes To become familiar with the basic

### DEPARTMENT OF MATHS, MJ COLLEGE

T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

### ME 461 C review Session Fall 2009 S. Keres

ME 461 C review Session Fall 2009 S. Keres DISCLAIMER: These notes are in no way intended to be a complete reference for the C programming material you will need for the class. They are intended to help

### CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

### Information Science 1

Topics covered Information Science 1 Terms and concepts from Week 8 Simple calculations Documenting programs Simple Calcula,ons Expressions Arithmetic operators and arithmetic operator precedence Mixed-type

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

### SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

SSEA Computer Science: Track A Dr. Cynthia Lee Lecturer in Computer Science Stanford Topics for today Introduce Java programming language Assignment and type casting Expressions Operator precedence Code

### Variables and Operators 2/20/01 Lecture #

Variables and Operators 2/20/01 Lecture #6 16.070 Variables, their characteristics and their uses Operators, their characteristics and their uses Fesq, 2/20/01 1 16.070 Variables Variables enable you to

### 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

### CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso

CMSC 104 -Lecture 6 John Y. Park, adapted by C Grasso 1 Topics #define Arithmetic Operators Assignment Operators Operator Precedence Evaluating Arithmetic Expressions Incremental Programming 2 Preprocessor

### 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

### PIC 10A. Lecture 3: More About Variables, Arithmetic, Casting, Assignment

PIC 10A Lecture 3: More About Variables, Arithmetic, Casting, Assignment Assigning values to variables Our variables last time did not seem very variable. They always had the same value! Variables stores

### C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

### 9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Arithmetic Operators Section 2.15 & 3.2 p 60-63, 81-89 1 Today Arithmetic Operators & Expressions o Computation o Precedence o Associativity o Algebra vs C++ o Exponents 2 Assigning floats to ints int

### Chapter 4: Basic C Operators

Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

### CS Programming In C

CS 24000 - Programming In C Week Two: Basic C Program Organization and Data Types Zhiyuan Li Department of Computer Science Purdue University, USA 2 int main() { } return 0; The Simplest C Program C programs

### CEN 414 Java Programming

CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

### 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.

### 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.

### Operators & Expressions

Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

### 1.3b Type Conversion

1.3b Type Conversion Type Conversion When we write expressions involved data that involves two different data types, such as multiplying an integer and floating point number, we need to perform a type

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### SECTION II: LANGUAGE BASICS

Chapter 5 SECTION II: LANGUAGE BASICS Operators Chapter 04: Basic Fundamentals demonstrated declaring and initializing variables. This chapter depicts how to do something with them, using operators. Operators

### 1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### Scientific Programming in C VI. Common errors

Scientific Programming in C VI. Common errors Susi Lehtola 6 November 2012 Beginner errors If you re a beginning C programmer, you might often make off-by one errors when you use arrays: #i n c l u de

### CS201 Some Important Definitions

CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data

### Programming for Engineers: Operators, Expressions, and Statem

Programming for Engineers: Operators,, and 28 January 2011 31 January 2011 Programming for Engineers: Operators,, and Statem The While Loop A test expression is at top of loop The program repeats loop

### Operators in C. Staff Incharge: S.Sasirekha

Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C

### Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

### 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

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### 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

### Expression Evaluation and Control Flow. Outline

Expression Evaluation and Control Flow In Text: Chapter 6 Outline Notation Operator Evaluation Order Operand Evaluation Order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific

### CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started

CS106X Handout 03 Autumn 2012 September 24 th, 2012 Getting Started Handout written by Julie Zelenski, Mehran Sahami, Robert Plummer, and Jerry Cain. After today s lecture, you should run home and read

### 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

### 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

### Computers Programming Course 5. Iulian Năstac

Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction

### Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

### 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

### Chapter 3. Fundamental Data Types

Chapter 3. Fundamental Data Types Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration

### Pointer Basics. Lecture 13 COP 3014 Spring March 28, 2018

Pointer Basics Lecture 13 COP 3014 Spring 2018 March 28, 2018 What is a Pointer? A pointer is a variable that stores a memory address. Pointers are used to store the addresses of other variables or memory

### A First Program - Greeting.cpp

C++ Basics A First Program - Greeting.cpp Preprocessor directives Function named main() indicates start of program // Program: Display greetings #include using namespace std; int main() { cout

### Programming. C++ Basics

Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

### Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

### Computer Programming CS F111

Computer Programming CS F111 BITS Pilani Dubai Campus NAND KUMAR Basics of C Programming BITS Pilani Dubai Campus Write a program that 1. Asks 5 marks from the user, find the average of the marks and print

### 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

### CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 4: Java Basics (II) A java Program 1-2 Class in file.java class keyword braces {, } delimit a class body main Method // indicates a comment.