Monday, February 28, 2011

PROGRAMMING EXERCISE SWITCH....CASE


#include<iostream.h>
main ()
{
     int selection,quantity;
     double price;

     cout<<"\n 1. Pen    =RM 0.50";
     cout<<"\n 2. Pensil =RM 0.30";
     cout<<"\n 3. Ruler  =RM 0.20";
     cout<<"\n 4. Erser  =RM 0.10"<<endl;

     cout<<"\n Enter your selection= ";
     cin>>selection;
     cout<<"\n Enter your quantity= ";
     cin>>quantity;

switch (selection)
{
     case 1:
price = quantity * 0.50;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Pen with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
  
case 2:
price = quantity * 0.30;
cout<<"\n Price = RM "<<price<<endl;
cout<<"\n Your selection is Pensil with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;

     case 3:
price = quantity * 0.20;
cout<<"\n Price = RM  "<<price<<endl;
cout<<"\n Your selection is Ruler with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;
  
case 4:
price = quantity * 0.10;
cout<<"\n Price = RM  "<<price<<endl;
cout<<"\n Your selection is Erser with "<<quantity;
cout<<" ,as your quantity(s)"<<endl;
break;

default:
cout<<"\n Invalid selection"<<endl;
}

return 0;
}



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;
               
               
                }


















EXERCISE


1. Calculate 3 numbers with using the formula below :-
       calculate = (num1*num2)-num3+(num2/num1)
#include<iostream.h>
main()
{
//declare variable
float num1,num2,num3,calculate;
//input1
cout<<"Enter Num1";
cin>>num1;
//input2
cout<<"Enter Num2";
cin>>num2;
//input3
cout<<"Enter Num3";
cin>>num3;
//formula
calculate=(num1*num2)-num3+(num2/num1);
//output
cout<<"Answer is="<<calculate;
return 0;
}




WEEKLY REFLECTION 3


08 JANUARI 2011

- Kelas bermula pada Jam 09.00 a.m,selepas tu di berikan waktu rehat selama 1 jam.


- Pada Pukul 10.00 a.m,Kelas telah bermulakan class Fop...


- Kami dikehendaki Install turbo C++

- Seterusnya mendapatkan tugasan tentang coding untuk menyiapkan bersama ahli kumpulan...



- Ulangkaji Chapter 1 and Chapter 2 


- Miss bagi homework1 and homework2


- Tutorials Blogspot







   

















HOMEWORK 2



HOMEWORK 2
OUTPUT:

Subject 1 (0.00) :
Subject 2 (0.00) :
Subject 3 (0.00) :
Subject 4 (0.00) :
Subject 5 (0.00) :

CPA:

FORMULA:
CPA = ((Subject1*3) + (Subject2*3) + (Subject3*2) + (Subject4*2) + (Subject5*4)) / 5



Answer :-