Monday, February 28, 2011

WEEKLY REFLECTION 4

WEEKLY REFLECTION 4


- Kelas bermula pada pukul 10.00 pagi..
- Sebelum kelas bermula Miss diberi nota pada forum dan kemudian di suruh download. -Setelah kelas bermula Sesi pembelajaran iaitu Chapter 4 Operators And expressions.
 chapter ini mengenai tentang Arithmetic Operators,Relational Operators,Logical Operators and Assignment Operators.
-Kemudian telah memberi latihan untuk membuat ye...
- Setelah siap si sambung chapter 6 Control Structures tentang coding cara membuat coding If... else,Do..while, For...,While...., and Switch...case..
- Pada diajar tentang If..Else and Switch..Case.. .Bahagian ini saya kurang faham sedikit tentang cara membuat ye..

CHAPTER 4 OPERATORS AND EXPRESSIONS.
4.1 Operators
-   C++ is very rich in built-in operators.
-  Operators triggers some computations when applied to operands in an expression.
- The commonly use operators are as follows :-
    a) Arithmetic Operators
    b) Relational Operators
    c) Logical Operators
    d) Assignment Operators

- Table 4-1 shows the commonly use operators in C++ programming language.

Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
+
> 
&&
=
-
< 
||

*
>=
!

/
<=


%
==



INCREMENT AND DECREMENT OPERATOR

- Increment  -  Pro-increment   (++N)
                    - Post-increment  (N++)

- Decrement  - Pro- decrement   (--N)
                      - Post-decrement   (N--)
- For Example :-

 Int n ;                                           Int n ;
n = 5                                             N=5

cout << n, 5                                  cout << n, 5
cout << ++N ; 1+5 =6                   cout << N++ ;
cout << N ; 6                                cout<< n ;  




Int M;                                            Int M ;       
M= 9                                             M = 10
         
Cout << m; 9                                cout << m ; 10
Cout << --M ; 8                            cout << M-- ; 10-1 =9
Cout << M ; 8                              cout << M ; 9


LOGICAL OPERATING

M
N
M && N
M || N
0
0
0
0
1
0
0
1
0
1
0
1
1
1
1
1

!(M&&N)
!(M||N)
!M
!N
1
1
1
1
1
0
1
0
1
0
0
1
0
0
0
0







! (M&&N) && (M||N)
!(M) || !(N)
1
1
0
1
0
1
0
0

For Example :-

++ a + --b * 4  > ++n  && p++ + q-- * 4 < x++ + 4

= 3 + 2 * 4 > 3* 2 + 4  &&      3 + 2 * 4 < 3 * 2 + 4
= 3 + 8 > 6 + 4            &&      3 + 8 < 6 + 4
= 11 > 10                    &&      11 < 10
=    1                           &&           0
                                     0


 Chapter 6  Control Structures

Selection Structures
a)     Do..while
b)    While…
c)     For..
d)    If…else
e)     Switch…case

Question :-

Age
Generation
0 – 2
Infant
3 – 6
Kids
7 – 12
Chile
13 – 21
Teenagers
22 – 30
Adult
30 up
Senior Adult

For  the coding :-

#include<iostream.h>
main ()
{
     //datatype variable_name;
     int age;
     cout<<"Enter your age :   ";
     cin>>age ;
    
     //if...else
     if (age>=0 || age <=2)
     {
                cout<<"Infornt";}
                else if (age >=3 || age <=6);
                {cout<<"kids";}
                else if (age >=7 || age <=12);
                {cout<<"child";}
                else if (age >=13 || age <=21);
                {cout<<"feenagers";}
                else if (age >=22 || age <=30);
                {cout << || "adult" ;}
                else if (age > 30)
                {cout<<"senior adult" ;}
                else
                {cout<<"Invalid selection";}
               
                return 0;
               
               
                }


















No comments:

Post a Comment