Introduction to Computing Dr. Nadeem A Khan. Lecture 14.

Slides:



Advertisements
Similar presentations
What Does This Program Do?
Advertisements

Programming Fundamentals Chapter 4. Floating Point Numbers  Scientific notation 98 = 0.98 x = x = x10 -1 
Proyek Queri-queri Lanjut dan Sub-subqueri. Variables dan Data.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
Fundamentals of Programming in Visual Basic
Introduction to Computing Dr. Nadeem A Khan. Lecture 22.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Introduction to Computing Dr. Nadeem A Khan. Lecture 10.
VB Built-in Functions School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 5, Monday 2/10/03)
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Built-In Functions.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to VB prepared by Dr. I A Moneim Reference Book Schneider.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture 4.
Introduction to Computing Dr. Nadeem A Khan. Lecture
Introduction to Computing Dr. Nadeem A Khan. Lecture 24.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 3 Control Statements.
Introduction to Computing Dr. Nadeem A Khan. Lecture 17.
Introduction to Computing Dr. Nadeem A Khan. Lecture 19.
Introduction to Computing Dr. Nadeem A Khan. Lecture 11.
Programming Fundamentals. Floating Point Numbers Scientific notation 98 = 0.98 x = x = x10 -1 Sign bit; Fraction.
Introduction to Computing Dr. Nadeem A Khan. Lecture 7.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Introduction to Computing Dr. Nadeem A Khan. Lecture 6.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Introduction to Computing Dr. Nadeem A Khan. Lecture 13.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
Introduction to Computing Dr. Nadeem A Khan. Lecture 18.
Introduction to Computing Dr. Nadeem A Khan. Lecture 8.
Introduction to Computing Dr. Nadeem A Khan. Lecture 9.
On to… string operations & functions. Concatenation (&) §When we want to combine two character strings into one new (longer) string, we can concatenate.
Introduction to Computing Dr. Nadeem A Khan. Lecture 5.
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
Chapter 9 Formatted Input/Output Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Chapter 9 - Formatted Input/Output Outline 9.1Introduction 9.2Streams 9.3Formatting Output with printf 9.4Printing Integers 9.5Printing Floating-Point.
Manipulation Masterclass By the VB Gods. In this masterclass, we will learn how to use some of the string manipulation function such as Len, Right, Left,
1 Chapter 3 – Variables, Input, and Output 3.1 Numbers 3.2 Strings 3.3 Input and Output.
CSC 162 Visual Basic I Programming. Randomizing and Formatting Randomizing Formatting –User-Defined Formats –Named Numeric Formats.
Lecture 8 Visual Basic (2).
Input, Output, and Processing
CIS 338: Operators and Formatting in VB.NET Dr. Ralph D. Westfall April, 2011.
1 E0001 Computers in Engineering Built in Functions.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Numerical Functions & Tricks In today’s lesson we will look at: why we might want to use mathematical techniques some useful functions other mathematical.
Chapter 8 - Visual Basic Schneider
Visual Basic I Programming
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.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
1 VB-06-String Manipulation Mar 03, 2002 String Function VISUAL BASIC.
CSC 162 Visual Basic I Programming. String Functions LTrim( string ) –Removes leading spaces from the left side of string RTrim( string ) –Removes trailing.
1 Chapter 3 Numeric Types, Expressions, and Output Dale/Weems/Headington.
Introduction to Computing Dr. Nadeem A Khan. Lecture 21.
Chapter 9 - Formatted Input/Output
Lesson 18 Math Functions Lesson 19 Format Functions
Chapter 9 - Formatted Input/Output
CSI 101 Elements of Computing Spring 2009
Sub Procedures and Functions
Prepared By: Deborah Becker
VBScript Session 10.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Presentation transcript:

Introduction to Computing Dr. Nadeem A Khan

Lecture 14

Built-in Functions ► Take one or more input values ► Return an output value ► Already seen:  Val(..), Str$(..), Asc(..), Chr(..)

Built-in Numeric Functions ► Sqr: calculates square-root and returns the value as double data type e.g: e.g:  Sqr(9) is 3  Sqr(0) is 0  Sqr(2) is  Sqr(30*2+4) is 8

Built-in Numeric Functions ► Int: Greatest integer less than and equal to a number e.g: e.g:  Int(2.7) is 2  Int(3) is 3  Int(-2.7) is -3

Built-in String Functions ► Left$, Mid$, Right$, UCase$, Trim$ Left$(“fanatic”, 3) is “fan”Right$(“fanatic”, 3) is “tic” Left$(“12/15/93”,2) is “12”Right$(“12/15/93”, 2) is “93” Mid$(“fanatic”, 5,1) is “t”Mid$(“12/15/93”,4, 2) is “15” Ucase(“Disk”) is “DISK”Ucase(“12two”) is “12TWO” Trim$(“ 1 2 ”) is “1 2”Trim$(“-12 ”) is “-12”

Built-in Functions (Contd.) ► Len Len(“Shenandoah”) is ? Len(“Just a moment”) is ? Len(“m”) is ?

Built-in Functions (Contd.) ► Len Len(“Shenandoah”) is 10 Len(“Just a moment”) is 13 Len(“m”) is 1

Built-in Functions (Contd.) ► Instr Instr(“Shenandoah”, “nand”) is ? Instr(“Just a moment”, “ ”) is ? Instr(“Croissant”, “ist”) is ?

Built-in Functions (Contd.) ► Instr Instr(“Shenandoah”, “nand”) is 4 Instr(“Just a moment”, “ ”) is 5 Instr(“Croissant”, “ist”) is 0

Built-in Functions (Contd.) ► Format$ Format$(num, fmt) num: number, numeric expression, string of a number fmt: format string Result => String consisting of a formatted version of the number

Built-in Functions (Contd.) ► FunctionString Value Format$( , “Standard”)12, Format$( , “Currency”)$12, Format$(-1234, “Standard”)-1, Format$(-1234, “Standard”)-1, Format$(-1234, “Currency”)($1,234.00) Format$(-1234, “Currency”)($1,234.00) =>Result: two digits after decimal; Commas every three places to the left of the decimal point; leading ‘$’ sign for currency

Built-in Functions (Contd.) ► FunctionString Value Format$(1/4, “Standard”)? Format$(“.2”, “Currency”)? Format$( , “Currency”)?

Built-in Functions (Contd.) ► FunctionString Value Format$(1/4, “Standard”)0.25 Format$(“.2”, “Currency”)$0.20 Format$( , “Currency”)($1,234.80)

Built-in Functions (Contd.) ► FunctionString Value Format$( , “#,0”)12,346 Format$(-3.6, “#,0”)-4 =>Result: Rounded; =>Result: Rounded; Commas every three places to the left of the decimal point

Built-in Functions (Contd.) ► FunctionString Value Format$(123.82, “#,0”)? Format$(-3.2, “#,0”)?

Built-in Functions (Contd.) ► FunctionString Value Format$( , “Percent”) % =>Result: Multiplied by 100; trailing % sign; two digits after decimal

Built-in Functions (Contd.) ► FunctionString Value Format$(.06265, “Percent”)? Format$(1/8, “Percent”)?

Built-in Functions (Contd.) ► FunctionString Value Format$(.06265, “Percent”)6.27% Format$(1/8, “Percent”)12.50%

Built-in Functions (Contd.) ► FunctionString Value Format$( , “Scientific”)1.23E+04 =>Result: first number between 1 and 9.99 and of two digits after decimal; and of two digits after decimal; Exponent value preceded by E and sign; Exponent value preceded by E and sign;

Built-in Functions (Contd.) ► FunctionString Value Format$( , “Scientific”)? Format$(1/8, “Scientific”)?

Built-in Functions (Contd.) ► FunctionString Value Format$( , “Scientific”)-6.00E+02 Format$(1/8, “Scientific”)-1.25E-01

Built-in Functions (Contd.) Formatting dates: Formatting dates: ► FunctionString Value Format$(“7/4/96”, “Long Date”)Thursday, July 4, 1996 Format$(“7/4/96”, “Medium Date”) 04-Jul-96

Built-in Functions (Contd.) Fixed length string formatting: Fixed length string formatting: ► FunctionString Value Format$( , Format$(123, Format$(“ ”, Format$(“$1,234.56”, Format$(1/4,

Generating Random Numbers The function: Rnd The function: Rnd ► Generates a random number from 0 up to but not including 1 Picture1.Print Rnd‘print a different number each time Let numvar= Rnd‘a random value is assigned

Generating Random Numbers (Contd.) The function: Rnd The function: Rnd Display numbers from the set {1,2,3,4,5,6} randomly!

Generating Random Numbers (Contd.) The statement: Randomize Timer? The statement: Randomize Timer?

Generating Random Numbers (Contd.) The statement: Randomize Timer The statement: Randomize Timer Sub Command1_Click ( ) Rem Display a lottery number Picture1.Cls Randomize Timer Picture1.Print Int(10*Rnd); Picture1.Print Int(10*Rnd) End Sub

Built-in Functions (Contd.) Abs(10) is 10 Abs(-10) is 10 Sgn(10) is 1 Sgn(0) is 0 Sgn(-10) is -1

Note: ► Schneider: Chapter 3 finished ► More on Msgbox and InputBox function in Warner (Sec: 7.1, 7.2)