Wednesday, March 30, 2011


jom blaja pasal if...else statement & switch...case statement

ok bdasarkan table kt ats . kite bole wt program dlm 2 jenis bentuk . sama ade dlm bntuk if...elseataupon switch...case . ok now kite wt dlm bentuk if..else statement dlu k ..

IF...ELSE STATEMENT
#include<iostream.h>
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//if...else statement
if(age>=1||age<=6)
{cout<<"you are kids !!";}
else if(age>=7||age<=12)
{cout<<"you are child !!";}
else if(age>=13||age<=21)
{cout<<"you are teenager !!";}
else if(age>=22||age<=30)
{cout<<"you are adult !!";}
else if(age>30)
{cout<<"you are old !!";}
else
{cout<<"Invalid selection";}
return 0;
}

SWITCH...CASE STATEMENT
#include<iostream.h>
main()
{
//declare variable
int age;
//input
cout<<"Enter your age=";
cin>>age;
//switch...case statement
switch(age)
{
case('age'>=1||'age'<=6):cout<<"you are kids !!";break;
case('age'>=7||'age'<=12):cout<<"you are kids !!";break;
case('age'>=13||'age'<=21):cout<<"you are kids !!";break;
case('age'>=22||'age'<=30):cout<<"you are kids !!";break;
case('age'>30):cout<<"you are kids !!";break;
default:cout<<"Invalid selection";
}
return 0;
}

ASSIGMENT 2!!!!!...
write your codding.....

                                                       1,write your computer
2.click save by enter your own file.s name
3. go to compile menu
4. press anykey for compiling the program
5. go to run menu


 6. go to windows and check output
7. get the final output


Tuesday, March 29, 2011


assigment 1
write as program.
***************************
MESIN TIN MINUMAN
----------------------------------
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 mmoney is not enough !!!!!!:________________


THANK YOU!!!!
PLEASE COME AGAIN

CODING!!!!!!!!!!!!

STEP BY STEP...      
                                                                    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

Monday, March 28, 2011


homework again
1) Complete the code that can calculate total marks for 3 students
for(int stud=1;____(a)____;stud++)
{
cout<<"Enter Student name:";
____(b)____name;
for(int mark=1;mark<=3;____(c)____)
{
cout<<"Enter assigment marks:";
cin>>marks;
total=____(d)____+marks;
}
}
cout<<"Total marks are"<<____(e)____;

(a) stud<=3
(b) cin>>
(c) mark++
(d) total
(e) total

2) Based on the short code below :
Change for loop statement below to while loop
for(x=1;x<=5;x++)
cout<<x<<"\t"<<x*2<<"In";

x=1;
while(x<=5)
cout<<x<<"\t"<<x*2<<"In";
x++

3) Write the code using while loop to get the output as below !
    20
    15
    10
    5
 
 
x=20
while(x<=5)
cout<<" "<<x;
x--;

yg nie xxhu la btol ke x ea... urmm aku bukn yer tau sngt buat codding nie.. 
ngeeeee.. pening kan kepale aku jerk... :"(
last exercise b4 mid term exam...
1) Change the if...else statement below to switch...case statement
#include<iostream.h>
main()
{
int nomA,nomB,selection,value;
cout<<"Enter 2 number:";
cin>>nomA>>nomB;
cout<<"1.Addition";
cout<<"2.Substraction";
cout<<"3.Multiply";
cout<<"4.Division";
cout<<"Enter selection=";
cin>>selection;
if(selection==1)
{value=nomA+nomB;}
else if(selection==2)
{value=nomA-nomB;}
else if(selection==3)
{value=nomA*nomB;}
else if(selection==4)
{value=nomA/nomB;}
else
{cout<<"Invalid selection";}
cout<<"The value is:"<<value;
return 0;
}

#include<iostream.h>
main()
{
int nomA,nomB,selection,value;
cout<<"Enter 2 number:";
cin>>nomA>>nomB;
cout<<"1.Addition";
cout<<"2.Substraction";
cout<<"3.Multiply";
cout<<"4.Division";
cout<<"Enter selection=";
cin>>selection;
switch(selection)
{
case1:"value=nomA+nomB";break;
case2:"value=nomA-nomB";break;
case3:"value=nomA*nomB";break;
case4:"value=nomA/nomB";break;
default:cout<<"Invalid selection";
cout<<"The value is:"<<value;
}
return 0;
}

2) Change the for loop statement below to while loop
#include<iostream.h>
main()
{
int i,power2;
for(i=1;i<=9;i++)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
}
return 0;
}

#include<iostream.h>
main()
{
int i,power2;
//while
i=1;
while(i<=9)
{
power2=i*i;
cout<<" "<<i<<"power2"<<power2;
i++;
}
return 0;
}

3) Write a program that input 2 numbers. Compare the numbers & display only the biggest number. If the numbers are same, display the numbers are same.
#include<iostream.h>
main()
{
int nomA,nomB;
cout<<"Enter 2 numbers=";
cin>>nomA>>nomB;
if(nomA>nomB)
{cout<<"nom A is bigger than nom B";}
else if(nomA==nomB)
{cout<<"nom A is same as nom B";}
else
{cout<<"Invalid";}
return 0;
}

4) Write a program using for loop that receive prices of 3 products. Calculate the price that must be paid after 10% discount is given to every customer.
#include<iostream.h>
main()
{
int x,price,total,discount;
for(x=1;x<4;x++)
{
cout<<"price["<<x<<"]:";
cin>>price;
total=total+price;
}
cout<<"total="<<total;
discount=total*0.10;
cout<<"discount"<<discount;
return 0;
}

5) What is the output for the following program segmment
i) int x=20;
   for(int i=5;i<=x;i++)
  {
   cout<<i;
   i=i+4;
  }

  5
  10
  15
  20

ii) int mul=1;
   do
  {
   mul=mul*2;
   cout<<"The mul is:"<<mul;
   mul++;
  }
  while(mul<10)

 
 1
  3
  7
Exercise niy ktorang wt tyme mis wt extra class b4 exam . mis suh student wt kt white board . nsb baek ak x kna buat kat depan.. klu x... x tau la ape jd kat aku... hehe.. so jwpn dy insyallah betol (:
Posted by gadis semasa.....

for loop & while loop pulaaak !
FOR LOOP
#include<iostream.h>
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//loop for
for(y=1;y<x;y++)
{
cout<<" "<<x;
}
return 0;
}

WHILE LOOP
#include<iostream.h>
main()
{
//declare variable
int x,y;
cout<<"Enter an integer=";
cin>>x;
//while
y=x;
while(y<x)
{
cout<<" "<<x;
y++;
}
return 0;
}

FOP CHAPTER 6
TOPIC : LOOP&WHILE


LOOP
#include<iostream.h>
main( )
{
//declare variable
//get input
cout<<"enter integer";
cin>>x;
//loop for
for(y=0:y<xy:y++)
{
cout<<"     "x;
}

WHILE
#include<iostream.h>
main( )
int x,y;
cout<<"enter an integer";
cin>>x;
//while(y<x)
cout<<"   "<<x;
y++;
}
}


FOP CHAPTER 5
STUDY DATE : 2 MAR 2011
TOPIC : IF ELSE ... SWICTH CASE......

EXAMPLE :

AGE   =    GENERATION
1-6      =  kids
7-12    =  child
13-21  =  teenagers 
 
22-30  =  adult
> 31    = old

if ..... else 

#include <iostream.h>
main ( )
{
declare variable
int age ;
// input
 
cout << " enter your AGE : " ;
cin >> age ;
//if else statement
 
if (age > = 1 II age <=6)
{cout << " you are kids ! " ;
else if ( age >=7 II age < = 12 )
{cout << '" you are child ! " ;
else if ( age >=13 II age <=21 )
{cout << " you are teenagers ! " ;
else if ( age <=22 II age <=30 )
{cout << " you are adult ! " ;
else if ( age > 30 )
{cout << " you are old ! " ;
else
{cout << "invalid selection" , ;
return 0 ;
}

swicth...case
 

#include < iostream.h>
main ( )
//declre variable
 
int age ;
//input
cout << " enter your age : " ;
cin >> age;
// swicth ... case statement
{ case ('age'>=1 II 'age' <= 6) : cout << " you are kids ! " ; break ;
case ( 'age'>=7 II 'age' <=12) : cout <<  " you are child ! " ; break ;
case ('age'>= 13 II 'age' <= 21) : cout << " you are teengers ! " ; break ;
case ( 'age' >= 22 II 'age' <=30) : cout << "you are adult ! " ; break ;
case ( 'age >30 ) : cout << " you are old ! " ; break ;
default : cout << " invalid selection " ;
}
return 0 ;
}

Tuesday, March 8, 2011

C++

buka interner:
go to start, pilih all progarm, cari boland c++















lepas tu boleh ar start buat progarmming..c++











Monday, March 7, 2011


Ni exercise yg miss ayuni bg, urmmm. Susah beb. Nik pening ak nk buat..

Nasib baek ade kawn2 yg tlg ajarkan... thank frens..
1) a) 5 * 2 % 3 + 25 / 5
        = (5 * 2) % 3 + (25 / 5)  settle bhgi nan darab dlu
        = (10 % 3) + 5  settle modulus dlu
        = 1 + 5
        = 6

   b) a = 5 , b = 6
       !(( a < 3 ) & & ( a = = 3 ) | | ( b > 9 ))
       = !(( 5 < 3 ) & & ( 5 = = 3 ) | | ( 6 > 9 ))   msok kn nilai a nan b dluAA
       = !((    0   ) & & (     0     ) | | (    0    ))   tntukan true / 1 or false / 0
       = !((    0   ) & & (     0     ) | | (    0    ))   settle kn & & dlu
       = !((    0    ) | | (    0    ))   br settle kn | |
       = !(0)   klu not / !, kne tebalek kn
       = 1 / True 
2) Identify the syntex error in the following program 
    include<iostream.h>  x letak simbol #
    mai()  ejaan sala, tetinggal hruf n
    {
     float allowance=300.00,salary;
    cout<<''Input Salary=";
    cin>salary;  sala simbol, ptot nye >>
    Tsalary=Sallary+Allowance;  formula sala, hruf T x perlu ade
    cout<<"salary is="<<salary;  lpas output, kne ltax return 0;
    }  

   JAWAPAN :
    
#include<iostream.h>
    main() 
    {
     float allowance=300.00,salary;
    cout<<''Input Salary=";
    cin>>salary; 
    salary=Sallary+Allowance; 
      cout<<"salary is=”<<salary;
     }

     3.write a program that will calculate the monthly salary for an employee that where saturday&sunday are considered as non working days .                                                                                            
 answer :
# include <iostream.h>
main ()
{
// declare variable
float noworkingdays;
f[oat salaryperdays;
float monthlysalary;
// input 1
cout <<"enter noworkingdays";
cin>> noworkingdays;
// input 2
cout <<"enter salaryperdays=";
cin>>"salaryperdays;
formula
monthly salary=noworkingdays*salaryperdays";
//output
cout<<"monthysalary<<monthlysalary;
return o
}


4.write a program that allowance their everage of 5 numbers that can be input by user.


answer:
# include < iostream.h>
main()
{
float no1
float no2
float no3
float no4
float no5
total average // input 1
cout<<"num 1";
cin>>num 1;
// input 2
cout<<"num 2";
cin>>num 2;
// input 3
cout<<"num 3";
cin>> num 3;
// input 4
cout<<" num 4";
cin>> num 4;
// input 5
cout<<"num5";
cin>> nmu 5;
// formula1
total= num1+num2+nmu3+num4+num5
// output
cout<<"total"<<total;
// formula
 average=total / 5
// output 2
cout<<"average"<<average;
return o
{
5.write a program that win calculate the area of rectangular,triangle&circle.
answer:
# include<iostream.h>
main()
}
// declare variable
float heigh;
float widh;
float area rectangle;
float radius;
float area circle;
float height;
float area triangle
// input 1
cout <<"enter height";
cin>>height;
// input 3
cout<<"enter width";
cin>>width;
//input 3
cout<<"enter radius";
cin >> radius;
// formula
area-rectangle=heightr*width;
// output 1 cout<<"area-rectangle="area-rectangle;
//formula 2
area-circle=3.14*radius*radius;
// output2
cout<<"area-circle="<<area-circle;
// formula 3
area=triangle=0.5*height*height;
// output3cout<<"area-triangle;"area -trinagle;
return o;
}