COMP102 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

COMP102

Description:

... the 1st paragraph of advice letter //use if-statement to give different advice according to BMI //... output the rest of the advice letter. else. cout '...' endl; ... – PowerPoint PPT presentation

Number of Views:17
Avg rating:3.0/5.0
Slides: 12
Provided by: jack52
Category:
Tags: advice | comp102

less

Transcript and Presenter's Notes

Title: COMP102


1
COMP102 Programming Fundamentals I
  • LA2B (Mon 5-7pm)
  • LA2E (Fri 3-5pm)
  • LA2F (Fri 5-7pm)
  • TA Jackie Lo

2
Lecture Review
  • if statement
  • Provides the means of choosing
  • Between two or more execution paths in a program
  • E.g. In ATM,
  • if user key in correct password?
  • correct allow user to cash-out money
  • not correct force user to quit

3
Lecture Review
  • Syntax
  • if (condition)
  • action
  • if (condition)
  • action_1
  • else
  • action_2
  • if (condition_1)
  • action_1
  • else if (condition_2)
  • action_2
  • else if (condition_3)
  • action_3
  • else action_4

4
Lecture Review
  • Example
  • if (exam mark is larger than 49)
  • exam passed
  • if (exam mark is larger than 49)
  • exam passed
  • else
  • retake exam

5
Lecture Review
  • Example
  • if (exam mark is larger than 89)
  • A grade
  • else if (exam mark is larger than 69)
  • B grade
  • else if (exam mark is larger than 59)
  • C grade
  • else if (exam mark is larger than 49)
  • D grade
  • else F grade

6
Lecture Review
  • Relational Operators
  • is equal to
  • lt is smaller than
  • lt is smaller than or equal to
  • gt is larger than
  • gt is larger than or equal to
  • ! not equal to
  • E.g.
  • (10 gt 8) True
  • (8 6) False
  • (8 lt 8) True

7
Lecture Review
  • Example
  • if (exam_mark gt 89)
  • coutltltA grade
  • else if (exam_mark gt 70)
  • coutltltB grade
  • else if (59 lt exam_mark)
  • coutltltC grade
  • else if (50 lt exam_mark)
  • coutltltD grade
  • else coutltltF grade

8
Lecture Review
  • Boolean Operators
  • and
  • or
  • ! Not
  • E.g.
  • if (is_102TA is_girl)
  • cout ltltHello Jackie!ltltendl
  • if (is_102TA is_helpYou)
  • cout ltltYou are so nice, Thank you!ltltendl

9
Leeture Review
  • Nested if Statement
  • if statement is inside another if

if (condition_1) if (condition_2) if
(condition_3) action_1
action_2a else action_2b
action_3
10
Summary
  • By the end of this lab, you should be able to
  • Implement if statement
  • Set condition with
  • Relational operators
  • Boolean operators
  • Use shortcut assignment

11
Lab3
  • Use if-statement

coutltlt cingtgtgreater_than_18 if
(greater_than_18 y greater_than_18
Y) coutltlt cingtgtname // input height
and weight BMI // coutltltDear
ltltnameltlt,ltltendl // output the 1st paragraph
of advice letter //use if-statement to give
different advice according to BMI
/ / // output the rest of the advice
letter else coutltltltltendl
Write a Comment
User Comments (0)
About PowerShow.com