Wednesday, 30 March 2011

WEEKLY REFLECTION 7

EXERCISE  IN CLASS FOP (8\3\2011)


QUESTION NO 1 

Fill in the blank with appropriate data type for the 
following variables declaration syntax : 

a) __________Number 1=1 
b) __________Number 3=3.0 
c) __________Text 1=”1 have a car” 
d) __________Huruf = “B” 
e) __________AccountNo =”6666666443” 


ANSWER NO 1 

a) int Number 1=1 
b) float Number 3=3.0 
c) string Text 1=”1 have a car” 
d) char Huruf = “B” 
e) int AccountNo =”6666666443” 






QUESTION NO 2 

You are given PTPTN loan with the amount of RM1600.Calculate the amount that you should pay after PTPTN discount based on CGPA.You must use IF…ELSE Statement: 

CGPA Diskaun 
4.00 100% 
3.99 – 3.00 80% 
2.99 – 2.00 40% 
0 – 1.99 0% 


Contoh output: 
Jumlah pinjaman: RM16000.00 
CGPA yang diperolehi:3.00 
Diskaun:RM 12800 
Jumlah oinjaman yang perlu dibayar selepas diskaun: RM3200 


ANSWER NO 2 











QUESTION NO 3 

You are required to do a program that will execute the multiply or divide operation.The operation is based on the user’s choice.You must use SWITCH-CASE STATEMENT:
Output.


____________________________________________
 
MENU PILIHAN 
____________________________________________ 
1.Pendaraban 
2.Pembahagian 
__________________________________________ 
Masukkan nombor pertama:4 
Masukkan nombor kedua:8 
Masukkan pilihan anda:1 
Hasil darab 4 8 ialah 32 

ANSWER NO3






QUESTION NO 4 

Change the algebra expression to anathematic expression:





ANSWER NO4.


 i) y=(m-4ax)/79 
ii) y=6bc/(45s-2xy) 
iii) y=((2+AB+C)/3d)+5xyz 
iv) y=(2kb/2ki)-3jb 
v) y=xy+x*x-2ab
 




QUESTION NO 5 
Solve the statement below to find m value show the working.

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

b) m=2 
m*=((3*4)1/2)-9 


ANSWER NO5

a) m=5 
m*=m(3+4)*2 
m=5*5(7)*2 
m=25*14 
m=350 


b) m=2 
m*=((3*4)1/2)-9 
m=2*(12*1/2)-9 
m=2*6-9 
m=12-9 
m=3 




QUESTION NO 6 

Find the output for the following segment.

a) float var 1=25.12, var 2=15.0; 
if (var 1<=2)cout<<"var1 less or same as var2"; 
else cout<<"var1 bigger than var2"; 

b) in n=20; n/=5; 

ANSWER NO6

a) 
float var 1=25.12, var 2=15.0; 
if (var 1<=2) 
cout<<"var1 less or same as var2"; 
else 
cout<<"var1 bigger than var2"; 

output: 
if(25.12<=2) 
var 1 bigger than var 2 


b)
 

int n=20; 
n/=5; 

output: 
n=n/5 
n=20/5 
n=4 




QUESTION NO 7 

Convert the while statement below for statement 
int j=10; while (j>0) 
{ 
cout<<" "<
J--J 
} 

ANSWER NO7


int j; 
for(j=10;j>0;j--) 
{ 
cout<<" "<
}
 




QUESTION NO 8 

Write of program that needs 4 prices using while loop 
and calculate the sum of the thing a program must 
use function while for calculate the average of the 
prices. 



#include 
main () 
{ 
int k; 
float P,total,average; 
K=1 
while (k<=4) 
{ 
cout<<"Enter price"<<k<<"=j;
cin>>P; 
k++; total=total+P; 
} 
average=total/4; 
cout<<"your total is"<<total<<"and average="" is"average;=""
return 0; 
} 




 ANSWER NO8


















Tuesday, 22 March 2011

WEEKLY REFLECTION 6.

1)EXERCISE

Change the IF...ELSE statement below to SWITCH CASE the statement.

#include<iostream.h>
main()
int selection,quantity;
float price
cout<<"\Pen=Rm0.50";
cout<<"\n 2.Pencil=Rm0.30";
cout<<"\n 3.Ruler=Rm0.20";
cout<<"\ 4.eraser=Rm0.10";
cout<<\n\n Enter your selection= ";
cin>>selection;
cout<<"\n enter your quantity=";
cin>>quantity;


JAWAPAN IF..ELSE



#include<iostream.h>
main()
{
      //declare variable;
      int quantity;
      cout<<"Enter your quantity:";
      
      //if.....else
      if(selection==1) 
      cout<<"price=RM"<<price;)
      else if(selection==2)
      {price=quantity*0.30;
      cout<<"price=Rm"<<price;}
      else if(selection==3)
      {price=quantity*0.20;
      cout<<"price=Rm"<<price;}
      else if(selection==4)
      {price=quantity*0.10;
      cout<<"price=Rm"<<price;}
      else 
      {cout<<"Invalid selection";}
      return 0;
      }
      

JAWAPAN SWITCH..CASE



#include<iostream.h>
main()
{
      //declare variable;
      int quantity;
      cout<<Entter your quantity:";
      
      //if.....else
      if(selection==1) 
      cout<<"price=RM"<<price;)
      else if(selection==2)
      {price=quantity*0.30;
      cout<<"price=Rm"<<price;}
      else if(selection==3)
      {price=quantity*0.20;
      cout<<"price=Rm"<<price;}
      else if(selection==4)
      {price=quantity*0.10;
      cout<<"price=Rm"<<price;}
      else 
      {cout<<"Invalid selection";}
      return 0;
      }
      




WEEKLY REFLACTION 5 ( ASSIGNMENT 1 AND 2)

  • minggu ni miss bagi ASSIGNMENT mengenai TIN MINUMAN(SWITCH) & SIFIR(LOOP) dan buat dalam kumpulan.
  • SEMUA AHLI HADIR :)




1. 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)

JAWAPAN TIN MINUMAN






#include <iostream.h>
main()
{
      //declare
      int selection;
      float money,balance,price,addm,add;
      //out
      cout<<"******************"<<endl;
      cout<<"Mesin Tin Minuman"<<endl;
      cout<<"------------------"<<endl;
      cout<<"1.PEPSI";
      cout<<"\n2.COCA COLA";
      cout<<"\n3.F&N MIRINDA";
      cout<<"\n4.F&N ORANGE";
      cout<<"\n5.100 PLUS"<<endl;
      cout<<"******************"<<endl;
      //input
      cout<<"\nPlease Choose Your Drink"<<endl;
      cin>>selection;
      
      cout<<"\nPlease Enter MONEY: ";
      cin>>money;
      
      switch (selection)
      {
             case 1: cout<<" Your drink is Pepsi";
                     price = 2.00;
                     break;
             case 2: cout<<" Your drink is Coca Cola";
                     price = 2.00;
                     break;
             case 3: cout<<" Your drink is F&N Mirinda";
                     price = 1.80;
                     break;
             case 4: cout<<" Your drink is F&N Orange";
                     price = 1.80;
                     break;
             case 5: cout<<" Your drink is 100 Plus";
                     price = 2.50;
                     break;
             default: cout<<"invalid selection";
             }
      
      if (money>price)
      {
                      balance = money - price;
      }else if (money<price){
                            add = price - money;
                            cout<<"Please add (RM" <<add<< ")= ";
                            cin>>addm;
                            balance = money + addm;
                            }
                            cout<<"Your balance is "<<balance;
                            return 0;
}



ASSIGNMENT2 (SIFIR)
2.JAWAPAN SIFIR



#include <iostream.h>
main()
{
     cout<<"*****"<<endl;
     cout<<"SIFIR"<<endl;
     cout<<"*****"<<endl;
     int a,b;
     char o;
     a=1;
     while (a<=12)
     {
           cout<<"\n";
           for (b=1;b<=12;b++)
           {
               cout<<" "<<a*b;
               }
               a++;
               }
               cout<<"\n\nType EXIT to quit application"<<endl;
               cin>>o;
               return 0;
               }



EXERCISE CALCULATE (IF...ELSE)

CALCULATE:
a) RECTANGULAR
b) TRIANGLE
c) CIRCLE
d) FAHRENHEIT
e) CELCIUS

Your Selection:

Your Selection is _________ and you are calculate _________. The answer is _____________


JAWAPAN







#include<iostream.h>
main()
{
float rectangular, circle, triangle, fahrenheit, celcius, radius,f,c;
float width,height,base;
char selection;

cout<<"calculate:";
cout<<"\n\n a-rectangular";
cout<<" \nb-triangle";
cout<<"\nc-circle";
cout<<"\nd-fahrenheit";
cout<<"\ne-celcius";


cout<<"\n\nenter selection";
cin>>selection;

if (selection=='a')
cout<<"\nYour Selection is a and you are calculate rectangular.";

cout<<"\nenter width";
cin>>width;
cout<<"\nenter height";
cin>>height;
rectangular=width*height;
cout<<"\nthe answer is"<<rectangular;
}

else if (selection=='b')

cout<<"\nYour Selection is b and you are calculate triangle.";
cout<<"\nenter base";
cin>>base;
cout<<"\nenter height";
cin>>height;

cout<<"\nthe answer is"<<triangle;
triangle=(1/2*base*height);
}

else if (selection=='c')
circle=3.142 * radius * radius;
cout<<"\nYour Selection is c and you are calculate circle.";
cout<<"\n enter radius";
cin>>radius;
cout<<"\nthe answer is"<<circle;
}

else if (selection=='d')
;
cout<<"\nYour Selection is d and you are calculate fahrenheit.";
fahrenheit=(celcius*1/8)+32;
cout<<"\nenter celcius";
cin>>c;
cout<<"\nthe answer is"<<fahrenheit;
}

else 
cout<<"\nYour Selection is e and you are calculate celcius.";

cout<<"\nenter fahrenheit";
cin>>f;
cout<<"\nthe answer is"<<celcius;
celcius=(f-32)*(5/9);
}

return 0;
}