Saturday, March 26, 2011

LATIHAN DAN ASSIGMENT

EXERCISE & ASSIGNMENT QUESTIONS

1.
a) Initializing variable Pi with the value 3.14
b) Declare a variable names perimeter with double data type
c) Give instruction that alloed user to input data
d) Input number of computer using variable

2. Change the if...else statement below to switch...case statement.

# include
main ( )
{

int selection, quantity;
float price;

cout<< " 1. Pen=RM0.50";
cout< < " 2. Pencil=RM0.20"; cout< < "
3. Ruler=RM0.20";
cout< < " 4. Eraser=RM0.10";
cin> > selection;

cin> > quantity;

if (selection ==1)
{ price = quantity*0.50 }

else if (selection ==2 )
{ price=quantity*0.30; }

else if (selection ==3 )
{ price=quantity*0.20; }

else if selection ==4 )
{ price=quantity*0.10; }

else
{ cout< < " The price is;',,PRICE;
 RETURN O;
}

JAWAPAN
1.

a) const Pi=3.14;


b) double perimeter;


c) cout<<"Enter data=";
cin>> data;


d)//declare variable
int num;
// input
cout<<"Enter Number=";
cin>> Number;

2.

#include
main()
{

int selection.quantity;
float price;

switch(selection,quantity)
{

case "1.Pen=RM0.50" : price=quantity*0.50 ; break;
case "2.Pencil=Rm0.20" : price=quantity*0.20 ; break;
case "3.Ruler=RM0.20" : price=quantity*0.20 ; break;
case "4.Eraser=RM0.10" : price=quantity*0.10 ; break;

default : cout<< "The price is : " <
}
return 0;
}

SOALAN ASSIGMENT 1


Write a program :
* * * * * * * * * * * * * * * * *
M E S I N T I N M I N U M A N
- - - - - - - - - - - - - - - - -
Jenis                                   RM
- - - - - - - - - - - - - - - - -
1.Pepsi                               1.80
2.Coca Cola                       1.90
3.F&N Orange                  1.50
4.F&N Mirinda                 1.60
5.100 Plus                       2.00
* * * * * * * * * * * * * * * * *
your selection :
Insert your money :

*Your Balance are ________
* Please insert _________ . Your money is not enough !! : _________

Thank You !
Please Come Again

STEP 1


STEP 2



STEP 3



STEP 4


STEP 5



STEP 6



STEP 7



STEP 8



STEP 9



STEP 10


STEP 11



STEP 12



STEP 13



STEP 14



STEP 15



STEP 16


STEP 17



STEP 18



STEP 19




No comments:

Post a Comment