Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Division & Divisibility. a divides b if a is not zero there is a m such that a.m = b a is a factor of b b is a multiple of a a|b Division.
Mod arithmetic.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Input Dialog Box An input dialog box can be used to obtain a single item of input from the user Presents a window (dialog box) requesting input Syntax:
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Introduction to Computing Dr. Nadeem A Khan. Lecture 14.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
Function.
String Escape Sequences
Vocabulary Section 1-3. Vocabulary Section 1-3 continued…
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 3 Variables, Calculations, and Colors Starting Out with Games.
Variables and Constants
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Variable Declaration  It is possible to declare multiple variables of the same data type on the same line.  Ex. double hours, rate, total;  Variables.
Computer Science 111 Fundamentals of Programming I Number Systems.
SECTION 5-1 Prime and Composite Numbers Slide
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Lecture 8 Visual Basic (2).
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
Chapter 3: Functions and Graphs 3.1: Functions Essential Question: How are functions different from relations that are not functions?
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
Factor Each Expression Section 8.4 Multiplying and Dividing Rational Expressions Remember that a rational number can be expressed as a quotient.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
1 Week 2: Variables and Assignment Statements READING: 1.4 – 1.6 EECS Introduction to Computing for the Physical Sciences.
Data Representation – Chapter 3 Section 3-1. Terminology “Digital” –Discrete, well defined values/steps –Opposite of analog –Analogy: digital is to analog.
Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical.
Arithmetic Expressions Russell Taylor NC Computing Software Application Development.
Chapter 8 - Visual Basic Schneider
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Visual Basic I Programming
String and General Procedures. Answer to the last question of Exam 1 Start Get a number Divide the Number By 2 Is the quotient Equal to 1? Print The Remain.
Unit 2: Integers Unit Review. Multiplying Integers The product of two integers with the same sign is a positive. Eg: (+6) x (+4) = +24; (-18) x (-3) =
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
Doing math In java.
3 Basics © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
CS4 –lecture 6 Wednesday, Jan 19, 2011 Roxana Gheorghiu.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
DIVISION. Standards G4.1M.C2.PO4A. Use multiple strategies to divide whole numbers using 4-digit dividends and divisors from 1 to 12 with remainders.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
21. THE STANDARD LIBRARY. General Rules The C standard library is divided into 15 parts (24 in C99), with each part described by a header. The names of.
Controlling Program Flow with Decision Structures.
1 Inside Module 8 Extracting Data Page n Using the Extract command2 n Coercion3 n $-functions4 n Extract from a table7.
 2012 Pearson Education, Inc. Slide Chapter 5 Number Theory.
Variables and Constants Chapter 4 Review. Declaring Variables A variable is a name for a value stored in memory. Variables and constants are used in programs.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
Chapter 3 - Visual Basic Schneider. Private Sub cmdEvaluate_Click() Dim n As Single, root As Single n = 6.76 root = Sqr(n) picResults.Print root; Int(n);
2.3 Output Formatting. Outputting Format Specify the number of spaces, “c”, used to print an integer value with specifier %cd, e.g., %3d, %4d. E.g. printf.
CS 1428 Exam I Review.
Arithmetic Operator Operation Example + addition x + y
Fundamentals of Programming I Number Systems
CEV208 Computer Programming
Sub Procedures and Functions
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CS 1428 Exam I Review.
COMPUTING.
Presentation transcript:

Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings

Functions - terminology §Functions are called from within a procedure. l e.g., Sqr(x) is a function call §A function receives 1 or more input values & returns a unique output value n = Left (string, 3) input Function name Output assigned to n

Numeric functions §Sqr §Int §Round §Rnd

Numeric functions - Sqr §Sqr (n) : returns the square root of n. l requires exactly one positive numeric input value l may contain an expression for n §Examples: assume n = 25 Sqr (16) returns 4 Sqr (2) returns Sqr (n) returns 5 Sqr (n + 11) returns 6 Sqr (-4) returns an error

Numeric functions - Int §Int (n) returns the greatest integer less than or equal to n l requires exactly one integer input value l n may be a numeric expression §Examples: assume n is 10 Int (5.2) returns 5 Int (-6.7) returns -7 Int (n + 15) returns 25

Numeric functions - Round §How numbers are rounded to integers: l 23.7 rounds up to 24 l 23.4 rounds down to 23 l 23.5 rounds up to 24 nRound (n)

Another format for Round §Round (2.357, 2) returns 2.36 §Round ( , 2) returns §This variation of Round is useful when our programs are processing monetary values. §Example: Private Sub Command1_Click() Picture1.Print Round(txtNum.Text, 2) End Sub

Two mathematical operators that are useful in programs §If x & y are integers, then the integer quotient of x divided by y can be found by using \ quotient = x \ y §Also, to get the remainder, use mod: remainder = x mod y §try it with: x = 26; y = 7

Numeric functions - Rnd §Used to enable your program to generate pseudorandom values; useful in the creation of games. §Rnd does not require any input value and returns a numeric value r where 0 <= r < 1 Int (Rnd * 10) will generate a value that is between 0 & 9

Some uses of Rnd §Randomly generate an integer between 1 & 10: x = 1 + Int(10 * Rnd) §Randomly generate a 0 or 1: x = Int (2 * Rnd) §Randomly generate evens between 0 & 98: x = 2 * Int (50 * Rnd) more...

More uses of Rnd §Randomly generate l a lowercase alphabetic character l an uppercase alphabetic character l the uppercase alphabetic characters between A & J

Still more examples of Rnd §Randomly generate an integer between l 1 & 10 l 3 & 23 l 0 & 100 evens only l 5 & 75 divisible by 5 §Randomly generate l a lowercase alphabetic character l an uppercase alphabetic character l p. 132: #116, 117

Lab §Page 132 # 121 §Page 133 #122, 124