Top Banner
Basic Data Types (almost all P.Languages) int ---- integer Whole number float ---- floating point number with decimal point double ---- for bigger or larger numbers with decimal point char - character single letter, symbol, or number enclosed commonly by single quotes
21

3 Flowcharts

Apr 08, 2018

Download

Documents

Tracy Go
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 1/21

Basic Data Types(almost all P.Languages)

• int ---- integer – Whole number

• float ---- floating point – number with

decimal point• double ---- for bigger or larger

numbers with decimal point

• char - character – single letter, symbol,

or number enclosed commonly bysingle quotes

Page 2: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 2/21

Arithmetic Operators

Symbols Meaning

+ Addition

- Subtraction

* Multiplication

/ Division

% Modulus(Remainder)

Page 3: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 3/21

Hierarchy of Arithmetic Operator 

MDAS RULE

FROM LEFT TO RIGHT

Page 4: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 4/21

Assignment Operator 

= (single equal sign)

---- use to assign valueto a variable

Page 5: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 5/21

Relational Operators

Symbols Meaning

> Greater than

>= Greater than or Equal to

< Less than

<= Less than or Equal to

== Equal to

!= Not Equal to

Page 6: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 6/21

Logical Operator 

Symbols Meaning

&& and

|| or

! not

Page 7: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 7/21

Logical Operator 

A B Z = A&&B

0 0 0

0 1 0

1 0 0

1 1 1

A B Z = A||B

0 0 0

0 1 1

1 0 1

1 1 1

Logical AND(&&) Logical OR(||)

Logical NOT(!)

A Z = !A

0 1

1 0

Page 8: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 8/21

Programming Exercises

PROBLEMS

Page 9: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 9/21

Problem no.1

• Create a flowchart that calculates thesum of two input number and displaythe result.

• Algorithm

Input Process Output

Enter two

numbers (n1,n2)

Compute the sum

(sum = n1+n2)

Display the sum

(sum)

Page 10: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 10/21

start

stop

int n1

int n2int sum

Enter 1st no: _

Enter 2nd

no: _

sum = n1 + n2

THE SUM is sum

Page 11: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 11/21

Problem no.2

(single sided)

• Draw a flowchart that determines if theinput number is positive. Consider zeroas positive.

• AlgorithmEnter a number (n)

if(n>=0)

Display that the number is POSITIVE

Page 12: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 12/21

Page 13: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 13/21

Problem no.3

(double sided)

• Draw a flowchart that determines if theinput number is positive or negative.Consider zero as positive.

• AlgorithmEnter a number (n)

if(n>=0)

Display The number is POSITIVE

else

Display The number is NEGATIVE 

Page 14: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 14/21

start

stop

int n

Enter a number

n: _

The number is

POSITIVEif(n>=0)

yesno

The number is

NEGATIVE

Page 15: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 15/21

Problem no.4

(multiple alternative)

• Draw a flowchart that determines if theinput number is positive or negative orneutral if the input number is zero.

• AlgorithmEnter a number (n)

if(n>0)

Display The number is POSITIVE

else if(n<0)

Display The number is NEGATIVE

else

Display The number is neutral 

Page 16: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 16/21

start

stop

int n

Enter a number n:

_

The

number is

POSITIVE

if(n>0)

yes

no

The

number is

NEGATIVE

if(n<0)

The

number is

NEUTRAL

yesno

Page 17: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 17/21

Problem no.5(case control, similar with

multiple alternative)

• Draw a flowchart that displays anequivalent color once an input lettermatch its first letter. Consider the criteria

• Criteria

Letters Colors

B or b Blue

R or r Red

Y or y Yellow

Other letters Unknown

Page 18: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 18/21

start

stop

char l

Enter a letter l_

Case l

is

Case l is B or b

BLUE RED YELLOW

Unknown

Color

Case l is R or r Case l is Y or y

Case l is other letter

Page 19: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 19/21

Problem no.6(case control, similar with multiple alternative)

• Draw a flowchart that generates/displays the

given sequence of numbers.

Sequence nos.

1

2

3

4

5

Page 20: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 20/21

start

stop

int n = 1

n <=5 Display n

true

n++

Page 21: 3 Flowcharts

8/7/2019 3 Flowcharts

http://slidepdf.com/reader/full/3-flowcharts 21/21

start

stop

int n = 1

Display n

true

n++

n == 6

a

a

false