Monday, March 28, 2011

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

Saturday, March 26, 2011

sifir

Weekly Reflection 6

masa nih sya tak dtg sbb demam..tp ada juga tny pada kwn keje fop..

contoh loop





exercise :1. fill in the blank with the appropriate data types for the following variable declaration syntax
a. ____integer_____ number 1=1
b. _____float____ number 3=30
c. ____string_____ text 1=" i have a car"
d. ____string_____ huruf = "b"
e. ____string_____ account no = "6666666443"

2. you are given PTPTN loan with the amount of rm16000. calculate the amount that you should pay other PTPTN discount based on the CGPA. you must use if...else statement
Output
Jumlah pinjaman = rm16.000
CGPA yg diperoleh = 3.00
Diskaun = rm 12.800
Jumlah pinjaman yang perlu dibayar selepas diskaun = RM3200



3. you are required to do program that will execute the multiply or divided operation is based on the user's choice. you must use switch.....case statement
Output:


answer :


4.change the algebra expression to anthmetic expression



a)     Y = m – 4ax
    7a

            Answer :   Y = (m - 4 ax) / 7a

b)    Y  =    6ab___
      4sd – 2xy

Answer :  Y = 6 bc / (4 sd – 2xy)

c)     Y = 2 + (AB + ( )   + 5 xyz
                               3d

             Answer : Y = (( 2 + AB + c ) / 3d ) + 5 xyz

d)    Y = 2kb = 3jb
       2k1

Answer : Y = (2kb / 2 ki ) – 3 jb

e)     Y = xy + x2 – 2ab

Answer : Y= xy + x * x – 2 ab
 
 
Solve the statement below to find in value. Show the working :-

a)     M=5
       M * = (3 + 4) * 2

Answer :-

    M =   5 * ( 3 + 4 ) * 2
    M =   (5 * 7 )* 2
    M =    35 * 2
    M =    70
                        1 (TRUE)

b)    M=2
M * = ((3 *4 ) / 2 ) = 9

Answer :-

M =  2 * (12/ 2 ) =9
M =  ( 2* 6 ) = 9
M =   12 = 9
      0 (FALSE)


6. find the output for the following segment:-
a) float var 1 = 25.12, var 2 = 15.0;
if (var 1<= var 2) cout<<"var 1 less or same as var 2"; else cout<<"var 1 bigger than var 2"; 
b) int n = 20; n/= 5;

Answer :-

Output :
Cout<<Var1 bigger than Var 2 “ ;



<!--[if !supportLists]-->b)    <!--[endif]-->In n = 20 ;
    n/ = 5 ;
             
            Answer :-
            Output  :
            Cout<<20 / 5 = 4 “ ;


7.  Convert the while statement below for for statement :-

Int j = 10 ;
While ( j > 10)

{

                Cout << “             “ << j ;
                J______ ;
}


Answer :-

#incude<iostream.h>
Main  ()

{
//declare variable
Int x  ;
X = 1 ;
While (x < = 10 )

{
Cout<<”number “<<x*1 ;
X ++ ;
}
return 0;
}

Output : 
Number 1 --------- 1
              2 --------- 2
              3 --------- 3
              4 --------- 4
              5 --------- 5
              6 --------- 6
              7 --------- 7
              8 --------- 8
              9 --------- 9
             10 --------- 10
 


8.Write a program the reads 4 prices using while loop and calculate the sum of things. A program must use function while for calculate the average of the prices.

#include<iostream.h>
main ()
{
                int k;
                float p,total,averge;

                k=1;
                while (k<=4)
                {
                                cout<<"Enter price "<<k<<"= ;
                                cin>>p;
                                k++;
                                total=total+p;

                }

                  Average=total/4;
                  cout<<"Your total is "<<total<<"and average is "average;

                  return 0;

}

Saturday, March 19, 2011

Weekly Reflection 5

-bincang 6 soalan..pas tu miss bg keje group..tin minuman..

MESIN TIN MINUMAN (SWITCH...CASE)
*****************
MESIN TIN MINUMAN
-----------------
1- PEPSI
2- COCA COLA
3- F&N MIRINDA
4- F&N ORANGE
5- 100 PLUS
*****************

Enter your drink:
Enter your money (RM):

Your drink is __________ and your balance are __________

*If the customer does not enter enough money, asked the customer to insert the money. (if...else)

answer :



Tuesday, March 15, 2011

Weekly Reflection 4..

Arithmetic Operators

+  = add
-  = subtraction
*  = multiply
/  = divide
%  = modulus
^  = power

Relational Operators

<      greater / more than
>      less than
<=   greater / more than and equal
>=   less than and  equal
= =  equal to!

Logical Operators

&&  and
||  or
! not

Increment & Decrement

Increment
  • pre-increment  (++N)
  • post-increment  (N++)
Decrement
  • pre-decrement (--N)
  • post-decrement (N--)
Example :

int n;
n = 5,
cout<<n; 5
cout<<++n; 1+5
cout>>n; 6

int n;
n = 5
cout<<n; 5
cout<<n++; 5+1
cout<<n; 6

int m;
m = 10
cout<<m; 10
cout<<m--; 10-1
cout<<m; 9

int m;
m = 9
cout<<m; 9
cout<<m--; 8
cout<<m; 8

Logical Operators

m  n  m&&n  m||n
0  0        0        0
0  0        0        1
1  0        0        1
1  1        1        1