COMP102 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

COMP102

Description:

Post-increment/decrement i i-- Unary operators ! Pre-increment/decrement i --i. Multiplicative operators * / % Additive operators ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 15
Provided by: jack52
Category:

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
1. Introduction to Computer Systems
  • Hardware
  • Input
  • Process
  • Memory
  • Output
  • Software
  • System
  • Operating system
  • Translation System
  • Application

3
2. Data Types , Variables and Constants
  • Data Types
  • void, int, char, float, double, bool
  • Variables Name / Identifiers Name
  • Start with a-z/A-Z
  • Contain only a-z/A-Z/0-9//_
  • Case sensitive
  • Variables Declaration
  • lttypegt ltidentifiergt
  • lttypegt ltidentifiergt ltvaluegt

4
2. Data Types , Variables and Constants
  • Constants
  • Never changed in the program
  • const lttypegt ltidentifiergt ltvaluegt
  • Type casting
  • int(ltchargt)
  • int(ltdoublegt)
  • int(ltboolgt)
  • double(ltintgt)
  • bool(ltintgt)
  • Common Mistakes
  • char a A

5
3. Structure of C Programs
  • include
  • ltiostreamgt
  • ltiomanipgt
  • ltcstdlibgt
  • ltctimegt
  • using namespace std
  • Match with ltiostreamgt, ltiomanipgt

6
3. Structure of C Programs
  • cin gtgt
  • User input
  • cout ltlt
  • Screen output
  • Common mistakes
  • cin gtgtaltltendl

Should be cingtgta coutltltendl
7
3. Structure of C Programs
  • Rules for division
  • double / double double
  • double / int double
  • int / double double
  • int / int int
  • Random number
  • srand(time(0))
  • int ran rand() x

8
3. Structure of C Programs
  • Order of Precedence
  • Parentheses ( )
  • Post-increment/decrement i i--
  • Unary operators !
  • Pre-increment/decrement i --i
  • Multiplicative operators /
  • Additive operators -
  • Relational ordering lt lt gt gt
  • Relational equality !
  • Logical and
  • Logical or
  • Assignment - /

9
4. Selections
10
4. Selections
switch statement
Value1
Value3
selector
action
Value2
action
action
11
4. Selections
  • Truth Table

E1 E2 E1 E2
true true true
true false false
false true false
false false false
E1 E2 E1 E2
true true true
true false true
false true true
false false false
E !E
true false
false true
12
5. Loops
  • for loop
  • for(iltinit valuegt i ltcontinue conditiongt i
    ltupdategt)
  • while loop
  • while ( ltcontinue conditiongt )
  • do-while loop
  • do
  • while ( ltcontinue conditiongt )

13
6. Functions
  • Return statement
  • void no return statement or return nothing
  • other return value to the caller through the
    function name
  • Pass by value
  • parameters inside and outside functions is not
    related
  • Pass by reference
  • parameters inside and outside functions is
    related
  • Value changed inside functions will affect
    outside
  • Value changed outside functions will affect inside

14
6. Functions (03 past paper Q6)
  • include ltiostream.hgt
  • int Test(int, int, int)
  • int a 2
  • int b 3
  • int main()
  • int b 4
  • int c 5
  • int d
  • d Test(a, b, c)
  • b b 3
  • cout ltlt a ltlt ' ' ltlt b ltlt ' ' ltlt c ltlt ' ' ltlt d ltlt
    endl
  • return 0
  • int Test(int z, int x, int y)
  • z 3
  • x b
Write a Comment
User Comments (0)
About PowerShow.com