15
Application Development Tools IS202 John McNeill Room 008, Hamilton Building

Calculations

  • Upload
    wiggles

  • View
    414

  • Download
    1

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Calculations

Application Development ToolsIS202

John McNeillRoom 008, Hamilton Building

Page 2: Calculations

ADT 2007 - Part 3 2

Notices• Nothing!

Page 3: Calculations

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

Page 4: Calculations

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

Page 5: Calculations

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

Page 6: Calculations

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

Page 7: Calculations

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

Page 8: Calculations

ADT 2007 - Part 3 8

Help … plenty web resources!• http://blog.stevex.net/index.php/string-

formatting-in-csharp/

Page 9: Calculations

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

Page 10: Calculations

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!

Page 11: Calculations

ADT 2007 - Part 3 11

What’s a Radians?

1 radian = 57.296º

Page 12: Calculations

ADT 2007 - Part 3 12

Library Mathematical Constants

double x, y;

x = Math.PI; // Πy = Math.E; // e

Page 13: Calculations

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

Page 14: Calculations

ADT 2007 - Part 3 14

Case Studies• Money case study• Iteration case study• Graphs case study

Page 15: Calculations

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