Upload
wiggles
View
414
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Citation preview
Application Development ToolsIS202
John McNeillRoom 008, Hamilton Building
ADT 2007 - Part 3 2
Notices• Nothing!
ADT 2007 - Part 3 3
This lecture’s outcomes• The student should be able to:
– Display numbers in a convenient way– Use the mathematical library functions– Carry out both business and scientific calculations
Ch 12
ADT 2007 - Part 3 4
Basics• Already covered in Chapter 4
– Input/Output using text boxes and labels– Conversions of strings and numbers– Precedence rules in expressions– Conversions of expressions with mix int and
double data
ADT 2007 - Part 3 5
Formatting Numbers• Why format?
– Make the meaning of numbers clear
• Use the static String classes method called Format to format double or int numbers
• Format
Value to be formattedString containing format information
Specifier: Treated as decimal number
Number of padded digitsNote string
Single number to be formatted
ADT 2007 - Part 3 6
Examples of Format
123
123
00123
12.34
R 12.34
1,234,000.00
98.12
12
1.20E+007
ADT 2007 - Part 3 7
Basic SpecifiersD Decimal (whole
number)D5 Decimal with padding
N Number with commas for thousands
N2 Number with two decimal places
F Fixed point F6 Fixed point with six decimal places
E Scientific E2 Scientific with two decimal places
C Currency C2 Currency with two decimal places
P Percentage P6 Percentage with four decimal places
ADT 2007 - Part 3 8
Help … plenty web resources!• http://blog.stevex.net/index.php/string-
formatting-in-csharp/
ADT 2007 - Part 3 9
Library Mathematical FunctionsAbs(x) Absolute valueCeiling(x) Round up to the smallest int >= xCos(x) Cosine where x is in radiansExp(x) ex
Floor(x) Round down to the smallest int <= xLog(x) & Log10(x) Natural logarithm to base e and 10Max(x, y) & Min(x, y) Larger of x and yPow(x, y) xy
Round(x) Rounds double value to nearest intSin(x) Sine where x is in radiansSqrt(x) +ve square rootTan(x) Tangent where x is in radians
Archimedes
ADT 2007 - Part 3 10
Using Mathematical Functions• Math is static
class providing a rich set of mathematical functions
• As Math is static an instance of the class does NOT need to be created … use the class directly!
ADT 2007 - Part 3 11
What’s a Radians?
1 radian = 57.296º
ADT 2007 - Part 3 12
Library Mathematical Constants
double x, y;
x = Math.PI; // Πy = Math.E; // e
ADT 2007 - Part 3 13
Constants• Variables
– Are values that may change
• Constants– Are values that don’t change
• Examples– Conversion factor used to convert units of measure
• inches to centimetres, etc
• Declaring Constants
ADT 2007 - Part 3 14
Case Studies• Money case study• Iteration case study• Graphs case study
ADT 2007 - Part 3 15
What you need to do next …• Bell & Parr (2004)
– Chapter 12 self study• Programming principles• Programming pitfalls• Grammar spot• Summary
– Revise Chapter 12 – Practice some of the given examples in the lab– Try the self-test questions