Thursday, April 7, 2011

PEMBETULAN UNTUK MIDTERM

SECTION A

2.INT
3.FOR
4.i
5.i++
6.i
7.price
8.total
9.price
10.total

SECTION B

1.a) -string
       -float
       -float
       -strng
       -float

QUESTION 2

//include<istream.h>
main()
cout<<******menu******
cout<<"/n1.adition/n2.substract/n3.multiply/n4.division";
cout<<"/n******";
cout<</n/nyour selection=";
cin>>selection;
cout<<"/nenter two integer numbers=";
cin>>num1>>num2;
switch (selection)
{
case1:ans=num1+num2";
case2:ans=num1-num2";
case3:ans=num1*num2";
case4:ans=num1/num2";
default:cout<<"selection invalid!";
}
cout<<:your selection is"<<selection<<"and the answer is"<<ans"
return 0;
}

QUESTION 3

a)
 //include<iostream.h>
main()
{
int x,y=2;
while
x=1;
while(x<=5);
}
cout<<" "<<x*y;
x++
return 0
}
}

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




CHAPTER 4

1) Arithmetic operators :
    + + (Unary Plus)
    - - (Unary minus)
    + (Addition)
    - (Substraction)
    * (multiplication)
    / (Floating-point division / Integer division)
    % (Modulus)
Dlm C++, ade increament nan decrement operator..
    + + (Pre-increment) e.g + +m
    + + (Post-increment) e.g m+ +
    - - (Pre-decrement) e.g - -n
    - - (Post-decrement) e.g n- -

 
SOALAN :        a = 2 , b = 3
                      m = 2 , n = 3
                       p = 2 , q = 3
                       x = 2 , y = 3            

(+ + a) + (- - b) * 4 > (+ + m) * (- - n) + 4

JAWAPAN :
               

2) Relational operators :
    < (Less than)
    > (Greater than)
    = = (Equal to)
    < = (Less than or equal to)
    > = (Greater than or equal to)
    ! = (Not equal to)

3) Logical operators : (0/False , 1/True)
    & & (AND) ----> ade je 0 mesti 0/false
    | | (OR) ----> ade je 1 mesti 1/true
    ! (NOT) ---->
    !(& &) (NOT AND) ---->
    !(| |) (NOT OR) ---->  | |
 e.g
 
 
Exercise 2 :
Bahasa melayu=
Bahasa inggeris=
Matematik=
Sains=
Total=
Average=
total=bm+bi+math+sains
average=total/4

Formula :
#include<iostream.h>//header
main()//start body
{//open curly bracket
float bm;
float bi;
float math;
float sains;
float total;
float average;
//input 1
cout<<"bahasa melayu=";
cin>>bm;
//input 2
cout<<"bahasa inggeris=";
cin>>bi;
//input 3
cout<<"matematik=";
cin>>math;
//input 4
cout<<"sains=";
cin>>sains;
//formula
total=bm+bi+math+sains;
//output
cout<<"total="<<total;
//formula
average=total/4;
//output
cout<<"average="<<average;
return 0;
}//close curly bracket
//end body

Wednesday, March 23, 2011

CHAPTER 2

#include<iostream.h> // header
main ( ) // start body
{ // open curly bracket
} // close curly bracket
// coment hidden
// 1 row coding
/ *,* / lebih dari 1 coding

declare variable
data_type / variable_name

data_type

int > integer
float > float (decimal)
double > double (decimal)
char > character (a-z / A-Z)
string > string (sentences)
const > constant (x berubah)

Rules:
1.look formula
2.find how many variable name
3.declare variable

Input:
cout<<"................";
variable_name_that_had_declared;

sample question

flow chart:

start>read radius>area=3.14 * radius * radius > print output

#include<iostream.h>//header
Main( )//start body
{open curly bracket
//declare variable
Float area;
Float radius;
//input 1
cout<<"enter radius";
cin>>radius;
//formula
area=3.14 * radius * radius
//output
cout<<"answer"<<area;
Return 0;
}//close curly bracket
//end bracket

Tuesday, February 15, 2011

CHAPTER 1

algorithm (arahan panjang)> pseodocode (arahan pendek)> flowchart> programming c++

example 1
find the area of rectangle

area=width * height

algorithm
1.get the width of rectangle
2.get the height of rectangle
3.calculate the area of rectangle with multiply width by height
4.display the area of rectangle

pseodocode
1.read width
2.read height
3.set the area = width * height
4.print output

flowchart
read width > read height > set the area = width * height > print output > end

example 2
find the area of celcius

celcius = (5/9) * (fahrenheit-32)

algorithm
1.get the fahrenheit of celcius
2.calculate celcius equal to five devide by name multiply by fahrenheit minus 32
3.display the area of celcius

pseudocode
1.read fahrenheit
2.set the celcius = (5/9) * (fahrenheit -32)
3.print output

flowchart
start > read radius > area 3.14 * radius * radius > print output > end

example 3
find the area of fahrenheit

fahrenheit = (9/5 * ( celcius + 32) )

algorithm
1.get the celcius of fahrenheit
2.calculate fahrenheit equal nine devide by five multiply celcius plus 32
3.display fahrebheit

pseudocode
1.read celcius
2.set the fahrenheit ( 9/5 * ( celcius + 32 ) )
3.print output

flowchart
start > read celcius > set the area = ( 9/5 * ( celcius + 32 )  ) > print output > end