BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Sunday, March 27, 2011

ASSIGNMENT 2







EXERCISE BEFORE MIDTERM

1) Change the if...else to swicth case ... statement
#include<iostream.h>
main( )
{
int nomA,nomB,selesction,value;
cout<<"Enter 2 numbers :";
cin>>nomA>>nomB;
cout<<"1.addition";
cout<<"2.substraction";
cout<<"3.multiply";
cout<<"4.divison";
cout<<"enter selection";
cin>>selection;
{
if(seletion==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
}
return0;
}

ANSWER:


#include<iostream.h>
main( )
{
int nomA,nomB,selesction,value;
cout<<"Enter 2 numbers :";

cin>>nomA>>nomB;
cout<<"1.addition";
cout<<"2.substraction";
cout<<"3.multiply";
cout<<"4.divison";
cout<<"enter selection";
cin>>selection;
{
//swicth ...case statement
(swictth selection)
{case1:nomA+nomB;break;
case2:nomA-nomB;break;
case3:nomA*nomB;break;
case4:nomA/nomB;break;
default:cout<<"invalid selection";
cout<<"The value is: " <<value;
}
return0;
}


2)Change for loop below to while loop

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

ANSWER:


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

3)Write a program that input 2 numbers . compare the numbers and display only the biggest number . If the number are same display "the number are same"

#include<iostream.h>
{
main()
int num1,num2
cout<<"enter an integer";
cin>>num;
//if (num2>num1)
{cout<<"num2 is bigger than num1;}
ele if (num2==num1)
cout<<"num2 is same as num 1";
else
{cout<<"invalid ";}
return0;
}

4.write a program using for loop hat receive prices of 3 products, calculate the price that must be paid after 16% 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;
dicount=total *0.01;
cout<<"discount"
return0;
}

5. what is the output for following program

a) intx=20
for (int i=5,i<=x,i++)
{
cout<< i;
}

answer: i =5,10,15,20

b) int mul=1
do
{
mul=mul*2;
cout<<"the mul is :" <<mul;
mul++;
while (mul10)

answer : mul = 1 ,3, 7

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

ASSINGMENT 1

Instruction : write a program

   
**********************************
          MESIN TIN MINUMAN
-----------------------------------------------
          JENIS                     RM
-----------------------------------------------
1.  PEPSI                          1.80
2. COCA COLA               1.90
3. FS ORANGE                1.50
4. FS MIRINDA               1.60
5. 100 PLUS                     2.00
*********************************















EXECISE 2 MAR 2011

1) a - initializing variable pie with the value 3.14
    answer : float pie = 3.14
    b- declare a variable and perimeter with double data type
    answer : Double perimeter ;
    c- give instruction that allowed user to input data
    answer : cout << " enter your data " ;
                   cin >> data ;
    d- input number of computer using variable
    answer : cout << " enter computer number " ;
    cin >> number ;


2) change else statement to swicth..case

#include <iostream.h>
main ( )
{
int selection , quantity ;
float price ;
cout << "1.pen = rm 0.50" ;
cout<< "2.pencil = rm 0.30";
cout<< "3.ruler = rm0.20";
cout<< "4.eraser=rm0.10';
cin>>selection;
cin>>quantity;
if (selection==1)
{price = quantity*0.20}
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 << "invalid seletion" ;}
cout<< "the price is :      " << price ;
return 0;
}

answer :

#include <iostream.h>
main ( )
{
int selection , quantity ;
float price ;
cout << "1.pen = rm 0.50" ;
cout<< "2.pencil = rm 0.30";
cout<< "3.ruler = rm0.20";
cout<< "4.eraser=rm0.10';
cin>>selection;
cin>>quantity;
swicth (selection)
{
case 1 : price=quantity*0.50;break;
case 2 : price=quantity*0.30;break;
case 3 : price=quantity*0.20;break;
case 4 : price=quantity*0.10;break;
default : cout << "invalid selection";
}
cout << the price is :      " << price;
return 0;
}

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

FOP CHAPTER 4

OPERATORS AND EXPRESSION

1) Arithmetic operators
++ (plus)
-- (minus)
+ (addition)
- (substraction)
* (multiplication)
/ (floating point division / int division)
% (modulus)

2) Increment and decrement in C++

++ (pre-increment) ++m
++ (post-increment) --n
-- (pre-decrement) --n
-- (post-decrement) n--

EXAMPLE 1:

1) a=2 , m=2 , p=2 , x=2 , b=3 , n=3 , q=3 , y=3



question :
  (++a) + (--b) * 4> (++m) * ( -- n) + 4
=(2+1) + (3-1) * 4> (2) * (3) + 4
=               3+2* 4> 2*3+4
=                3+8   > 6+4
=                 11    > 10
=                    true/1

3) Reltional operators:-

< less than
> greater than
== equal too
<= less than or equal too
>= greater than or equal too
!= not equal too

4) logical operators

( 0/FALSE = 1/TRUE ) && (AND) {tips if got 0 will be 0/false}
II (OR) { TIPS IF GOT 1 WILL BE 1/TRUE

 ! (NOT)
 ! (&&) NOT AND
 ! (II) (NOT



EXAMPLE :

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

++ a +  --b * 4 > ++m * --n +4 && p++ + q -- * 4 < x++ * y-- + 4
(2+1)+(3-1)*4 > (2+1)*(3-1)+4 &&       2+3*4      < 2*3+4
   3   + 2 * 4    >   3    * 2    +4 &&       2 + 12      <  6+4
         11         >         10          &&        14          <   10
                  1/true                    &&              0/false
                                     0/false

Saturday, March 5, 2011

EXECISE 23 FEB 2011

1) SOLVE THE QUESTION BELOW

a) 5 * 2 % 3 + 25 / 5
    10     % 3 + 5
    1              + 5
    6 (answer)

b)  a=5 , b=6
  
    ! ( ( a <  3 ) && ( a = = 3 ) II ( b > 9 ) )
    ! ( ( 5 <  3 ) && ( 5 = = 3 ) II ( 6 > 9 ) )
    ! ( (    0    ) &&  (  0   )      II (   0     ) )
    ! ( 0 )           =       1   II TRUE


2 ) Identify the syntax errors in the following program

# include < iostream.h>
mai ( )
{
float allowance = 300.00 salary ;
// input
cout  << " input salary = '' ;
cin > salary ;
salary = salary + allowance ;
// output
cout << '' salary is = '' << salary;
}

answer :
# include < iostream.h >
main ( )
{
float allowance = 300.00 salary ;
// input
cout  << " input salary = '' ;
cin >> salary ;
salary = salary + allowance ;
// output

cout << '' salary is = '' << salary ;
return 0 ;

}

3. write a program that calculate the monthly salary for an employee that where saturday & sunday are considered as non working days

# include < iostream.h >
main ( )
// declare variable
float no working days ;
float salary per day ;
float monthly salary ;
// input 1
cout << '' enter no working days '' ;
cin >> '' no working days '' ;
// input 2
cout << '' enter salary per day '' ;
cin >> '' salary per day '' ;
// formula
'' monthly salary = working days * salary per day '' ;
// output
cout << '' monthly salary << monthly salary '' ;
return 0 ;
}

4) write a program that calculates the average of 5 numbers that can be input by user

# include < iostream.h >
main  ( )
float no 1
float no 2
float no 3
float no 4
float no 5
float total
float average
// input
cout << '' num 1 '' ;
cin >> '' num 1 '' ;
cout << '' num 2 '' ;
cin >> '' num 2 '' ;
cout << '' num 3 '' ;
cin  >> num 3 '' ;
cout << '' num 4 '' ;
cin >> '' num 4 '' ;
cout << '' num 5 '' ;
cin >> '' num 5 '' ;
// formula
total = num1 + num2 + num3 + num4 + num5
// output 1
cout << '' total / 5 '' ;
//output 2
cout << '' average '' << average ;
return 0 ;
}

5 ) write  program that will calculate the area of rectangular , triangle , circle


# include < iostream.h >
main ( )
{
declare variable
float height ;
float width ;
float area_rectangle ;
float radius ;
float area_circle ;
float height ;
float area_triangle ;
// input 1
cout << '' enter height '' ;
cin >> '' height '' ;
// input 2
cout << '' enter width '' ;
cin >> '' width '' ;
// input 3
cout << '' enter radius '' ;
cin >> '' radius '' ;
// formula 1
area_rectangle = height*width ;
//output 1
cout << '' area_rectangle = '' << area_rectangle ;
// formula 2
area_circle = 3.14*radius*radius ;
//output2
cout << '' area_circle = '' << area circle ;
// formula3
area_triangle = 0.5*height*height ;
//output3
cout << '' area_triangle = '' area_triangle ;
retrun o ;
}

MATA DAH NGANTOK , SAMBUNG ESOK LA JWBNYERR

Thursday, February 10, 2011

EXERCISE , EXERCISE , AGAIN AND AGAIN

DATE : 9 FEB (WED)

EXERCISE 1 

Exercise programming ( group discussion )

Question :-
Add and minus number 1 & number 2 with using the formula below

ADD = NUM1 + NUM2
MINUS = NUM2 - NUM1

Flowchart : Start ---> read number 1 ----> read number 2 ----> add = num1 + num2 / minus = num2 - num1 --- > display output ----> end

Exercise programming ( group discussion )

Question :-
Add and minus number 1 & number 2 with using the formula below

ADD = NUM1 + NUM2
MINUS = NUM2 - NUM1

Flowchart : Start ---> read number 1 ----> read number 2 ----> add = num1 + num2 / minus = num2 - num1 --- > display output ----> end

Programming :-

# include < iostream.h >
main ()
{
// variable declaration
int num1 , num2 , add ,minus ;
// input 1
cout << " enter num1 : " ;
cin >> num1 ;
// input 2
cout << " enter num2 : " ;
cin >> num2 ;
// formula
add = num1 + n2 ;
// output
cot << " minus = <<
minus ;
return 0
}


EXERCISE 2

BAHASA MELAYU =
BAHASA INGGERIS =
MATEMATIK =
SAINS =

TOTAL=
AVERAGE=

FORMULA

total=bm+bi+math+sains
average=total/4

method :- ( di praktikkan dalam komputer hak cosmopoint sahaja )
1. open your computer
2. go to my computer ---> local disk (C:) ----> folder TC ----> folder BIN ----> pic MSDOS

*** if cannot, find folder TC at loal disks (C:) , go to folder program , Files ---> folder TC ----> folder BIN ---- >pic MSDOS

3. after open the turbo ctt file ---> new ---> type your group coding
4. to cmpile , go to compilemenu
5. to run , go to run menu


Rules:
---->Tengok formula
---->Cari ade bape variable name
---->Declare variable

Input:
Cout <<“----------------------” ;
Cin >>variable_name_that_had_declared;
WARNING : BE CAREFULL HURUF KECIL DAN BESAR

Output:
Cout <<“----------------------”<<
variable_name_that_had_declared;

EXAMPLE OF PROGRAMMING

Flow chart

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

#include <iDStream.h>//header
Main( ) //start body
{ // Open curly braket
//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

FOP CHAPTER 2

C++ BASICS 
DATE : 2 FEB 2011 (WED)

C++  language consists of two basic elements :-
1. Semantics
2. Syntax

How to create the programming ?

compulsory symbol before starting to create the programming


#include <IDStream.h> //header
Main ( ) // start body
{ // Open curly braket
} // close curly braket
// comment hidden
/ * , * /

Declare variable

Data_type and variable_name

int = integer 0-9
float = float (decimal)
double = double (decimal)
char = character (a-z / A-Z)
string = string (sentences)
const = constant ( tidak berubah )

Rules:
---->Tengok formula
---->Cari ade bape variable name
---->Declare variable

Input:
Cout <<“----------------------” ;
Cin >>variable_name_that_had_declared;
WARNING : BE CAREFULL HURUF KECIL DAN BESAR

Output:
Cout <<“----------------------”<<
variable_name_that_had_declared;

EXAMPLE OF PROGRAMMING

Flow chart

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

#include <iDStream.h>//header
Main( ) //start body
{ // Open curly braket
//declare variable
Float area;
Float radius;
// input 1
Cout <<“enter radius”;
Cin>> radius;
//formula
area = 3.142 *radius*radius
//output
Cout <<“answer”<<area ;
Return 0 ;
} // close curly bracket
//end bracket

Friday, February 4, 2011

FOP CHAPTER1

DATE : 2 FEB 2011 ( WED )

PROGRAMMING AND PROBLEM SOLVING 
1) Algorithm - Is a sequence of instruction to solve a problem. It can be written in human language and programming language.

Example : Determines the area of rectangle .

FORMULA = WIDTH*HEIGHT

1. Get the width of the rectangle
2. Get the height of rectangle
3. Calculate the area using the formula
4. Annouce the answer

2) Pseudocodes - Is an outline of a program , written in a form that can easily be converted into real programming statements.

Example : Determines the area of rectangle .

FORMULA = WIDTH*HEIGHT

1. Read the width
2. Read the height
3. Set the area to the width multiplied by height
4. Print the area

3) Flowchart - Flowchart is a graphic representation of the logic or steps in a program .

Example of flowchart :  start > read width > set the area = width*height > print output > end

4) The software life cycle ( remark list down in exam )
    1. Analysis and specification of the task (problem definition)
    2. Design of the software (algorithm design)
    3. Implementation (coding)
    4. Testing
    5. Maintenance and evolution of the system
    6. Obsolescence

EXERCISE TIME !!!

Question 1 : print the area of circle area 
                  
                  FORMULA : CIRCLE AREA = 3.142*RADIUS*RADIUS

Agorithm : 1. Get the radius of circle
                 2. Calculate the area of circle with 3.142 multiply radius by radius
                 3. Display the area of circle
Pseudocode : 1. Read the radius
                        2. Set the area = 3.142*radius*radius
                        3. Print output

Flowchart : start > read radius > 3.142*radius*radius > print output > end


Question 2 : Find the celcius

                FORMULA : CELCIUS = (5/9)*(FAHREINHEIT-32)

Algorithm : 1. Get the fahreinheit of celcius
                  2. Calculate the celcius equal to five devide by nine multiple fahreinheit -32
                  3. Display celcius

Pseudocode :1. Read fahreinheit
                       2. Set the celcius = (5/9)*(fahreiheit-32)
                       3. Print output

Flowchart : start > read fahreinheit > calculate (5/9)*(fahreinheit-32) > print output > end


Question 3 : Find the fahreinheit

                  FORMULA : FAHREINHEIT  =( 9/5) *( CELCIUS + 32 ) 

Algorithm : 1. Get the celcius of fahreinheit
                  2. Calculate the fahreinheit equal nine divide by five multiply celcius 32
                  3. Display fahreinheit


Pseudocode : 1. Read celcius 
                        2. Set the fahreinheit =(9/5)*(celcius +32)
                        3. Print output


Flowchart : Start > read celcius > set the fahreinheit = (9/5)*(celcius +32) > print output > end




FINISH CHAPTER 1 !!!!!!!!!!!!!!!!!!   

feel so tired to finish it coz this is 1st time i'm create a blog like this !!