Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment.

Slides:



Advertisements
Similar presentations
Chapter 5 Implementing a simple class. This chapter discusses n Implementing class definitions. n How to store data in an object and how to write method.
Advertisements

© 2007 Lawrenceville Press Slide 1 Assignment Statement An assignment statement gives a value to a variable. Assignment can take several forms: x = 5;
Types and Arithmetic Operators
Lecture 2 Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
True or false A variable of type char can hold the value 301. ( F )
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 Lecture 5: Input/Output (I) Introduction to Computer Science Spring 2006.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
Introduction to C Programming
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Basic Elements of C++ Chapter 2.
Copyright © 2003 Pearson Education, Inc. Slide 2-1 Problem Solving with Java™ Second Edition Elliot Koffman and Ursula Wolz Copyright © 2003 Pearson Education,
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Numeric Types, Expressions, and Output ROBERT REAVES.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Mathematical Calculations in Java Mrs. G. Chapman.
CP104 Introduction to Programming Overview of C Lecture 4__ 1 Assignment Statements An assignment statement is to store a value in a variable variable.
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
LOOP & Type Conversion. do – while Loop In the while loop, the test expression is evaluated at the beginning of the loop. If the test condition is false.
Data Types Declarations Expressions Data storage C++ Basics.
1 12/4/1435 h Lecture 2 Programs and Programming Languages.
Mathematical Calculations in Java Mrs. C. Furman.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 14: Pointers.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Chapter 4 Making Decision Csc 125 C++ programming language Fall 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
A Sample Program #include using namespace std; int main(void) { cout
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Arithmetic Instructions. Integer and Float Conversions.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 7: Expressions and Assignment Statements
BASIC ELEMENTS OF A COMPUTER PROGRAM
Java Primer 1: Types, Classes and Operators
Basic Elements of C++.
Chapter 7: Expressions and Assignment Statements
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic operations & assignment statement
Multiple variables can be created in one declaration
Basic Elements of C++ Chapter 2.
Arithmetic Operator Operation Example + addition x + y
Conversions of the type of the value of an expression
Lecture 3 Expressions Richard Gesick.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 2: Basic Elements of Java
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Data Types and Expressions
Introduction to C Programming
Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a language-specific syntactical token.
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

Executable Statements 1. Def. Executable statements are instructions to the computer to perform specific tasks. 2. Two examples: method calls and assignment statements 3. What are two classifications of methods? (void and value returning) 4. Syntax for calling a method: objectName.methodName()

5. Note: a method called from within the class in which it is defined (or a subclass) can be made without the objectName and without a dot. 6. Void method calls are statements themselves, but value returning methods must be in assignment statements. aPiece.readSqMeter(); objectNamemethodNameno arguments val = getDouble();

7. A value returning method must have a return statement somewhere in its block ( usually the last statement). 8. A return statement consists of the reserved word return followed by a variable or expression. 9. Methods may (or may not) have arguments. Arguments are variable names separated by commas. 10. Note: the position, type, and no. of arguments in the method call must match those in the method heading. Remember: no types are stated in the method call. See p.81

11. Def. assignment statement an instruction that stores a value (or result of an expression) in a variable. The assignment operator is: = 12. ex. char ch = ‘z’; ans = cost; //typing done previously d = getDouble( ); 13. Arithmetic operators permitted in expressions in order of precedence: - (unary minus) *, /, % (left associative for operators of same level) +, -

14. Expressions with 2 integer operands result in an int. 15. / results in the quotient % results in the remainder ex. int c = 5 / 2 results with 2 stored in c int d = 5 % 2 results with 1 stored in d 16. Expressions with 1 integer operand and 1 double operand results in a double unless typecasting is used. 17. Def type casting creates a value of one type from a variable or expression of another type.

Ex. int m = 5, n = 2, c; double x = 3.8 c = x + m / n / error !! c = (int) x + m / n / c = 5 See p.92 Do p.95 # 1 - 4