FUNDAMENTAL OF PROGRAMMING
Monday, March 28, 2011
ASSIGNMENT 1
#include <iostream.h>
main()
{
//variable declaration
float balance,money;
char select;
//menu
cout<<"**********************"<<endl;
cout<<"MESIN TIN MINUMAN"<<endl;
cout<<"JENIS RM"<<endl;
cout<<"p - PEPSI 1.80 "<<endl;
cout<<"c - COCA COLA 1.90 "<<endl;
cout<<"o - F&N ORANGE 1.50 "<<endl;
cout<<"m - F&N MIRINDA 1.60 "<<endl;
cout<<"l = 100 PLUS 2.00 "<<endl;
cout<<"**********************"<<endl;
cout<<"Your Selection= "<<endl;
cin>>select;
cout<<"Insert Your Money= "<<endl;
cin>>money;
//switch if else statement
{
if(select == 'p')
balance = money-1.80;
else
if(select == 'c')
balance = money-1.90;
else
if(select == 'o')
balance = money-1.50;
else
if(select == 'm')
balance = money-1.60;
else
if(select == 'l')
balance = money-2.00;
else
balance = 0;
//output
cout<<"Your balance is= "<<balance<<endl;
cin>>balance;
cout<<"Thank You"<<endl;
cout<<"Please Come again"<<endl;
}
return 0;
}
HERE IS THE OUTPUT
WEEKLY REFLECTION 3
GROUP NAME : NOR , MADARITA , SITI SALEHA , ISWARA
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

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
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
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
EXERCISE 2
Question 1
a)Float Pi=”3.14”;
b)double perimeter;
c) int data;
cout<<”Enter your data “;
cin>>data;
d) int num;
cout<<”Enter your num “;
cin>>num;
Question 2
#include <iostream.h>
main()
{
Int selection,quantity;
float price;
cout << “1 Pen = RM0.50”;
cout << “2 Pensil = RM0.30”;
cout << “3 Rules = RM0.20”;
cout << “4 Erasers = RM0.10”;
cin >> selection;
cin >> quantity;
switch (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;
}
WEEKLY REFLECTION 2
class on 9 Feb 2011
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
( MISS SORRY NI DAH SAVE FLOWCHART DLM PIC FORMAT JPEG , TP STILL XTAU CMNE NK UPLOAD DLM NI
)
Programming :-
remark : banyak yang betul dari yang salah time ms check .. beberapa simbol ; tertinggal di belakang sentences, agk hura hara jugak nk buat programming ni ... tp exercise ni xde markah ...
# 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 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
( MISS SORRY NI DAH SAVE FLOWCHART DLM PIC FORMAT JPEG , TP STILL XTAU CMNE NK UPLOAD DLM NI


Programming :-
remark : banyak yang betul dari yang salah time ms check .. beberapa simbol ; tertinggal di belakang sentences, agk hura hara jugak nk buat programming ni ... tp exercise ni xde markah ...
# 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 1
Question 1
A) [5*2] % 3 + 25/5
=[10 % 3] + 25/5
=1 + 5
= 6#
- a=5 b=6
! [ (a < 3) && (a == 3) || (b > 9) ]
! [ (5 < 3) && (5 == 3) || (6> 9) ]
! [ ( 0 ) && ( 0 ) || ( 0 ) ]
! [ ( 0 ) ( 0 ) ]
! ( 0 )
= 1#
Question 2
#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;
}
Question 3
#include <iostream.h>
main()
{
//declare variable
float no_working_day,salary_per_day,monthly_salary;
//input1
cout << ” enter no working day = “;
cin >> no_working_day;
//input2
cout << “ enter salary per day = “;
cin >> salary_per_day;
//formula
monthly_salary = no_working_day + salary_per_day;
//output
cout >> “monthly salary = “<<monthly_salary;
return 0;
}
Question 4
#include <iostream.h>
main()
{
//variable declaration
float num1,num2,num3,num4,num5,total,average;
//input1
cout<<"num1= ";
cin>>num1;
//input2
cout<<"num2= ";
cin>>num2;
//input3
cout<<"num3= ";
cin>>num3;
//input4
cout<<"num4= ";
cin>>num4;
//input5
cout<<"num5= ";
cin>>num5;
//formula
total = num1 + num2 + num3 + num4 + num5/5;
//output
cout<<"average= "<<total;
return 0;
}
Question 5
#include <iostream.h>
main()
{
//variable declaration
int length,width,radius;
float areaR,areaT,areaC;
//input
cout<<"Enter the length= ";
cin>>length;
cout<<"Enter the width= ";
cin>>width;
cout<<"Enter the radius= ";
cin>>radius;
//formula
areaR = length * width;
areaT = 0.5 * length * width;
areaC = 3.142 * radius * radius;
//output
cout<<"The area of rectangle: "<<areaR;
cout<<"The area of triangle: "<<areaT;
cout<<"The area of circle: "<<areaC;
return 0;
}
WEEKLY REFLECTION 1
FANSTACTIC 4
madarita,nor kolifatun,noridayu,eswaran
chapter 1 :
algorithm (arahan pnjg) > pseodocode (arahan pendek) > flowchart > programming C++
sample question!!!!!!!!!!!!!!!!!!
example 1 :
Find the area of rectangle
Area = width * height[/color]
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
Pseudocode
1.Read width
2.Read Height
3.Set the area = width * height
4.Print output
Flow chart
Read width > raed 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
flow chart :
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 fahrenheit
pseudocode
1.read celcius
2.set the fohrenheit ( 9/5 *( celcius + 32 ) )
3.print output
Flow chart
Start > read celcius > set the area = ( 9/5 ) *( celcius + 32 ) > print output >end
Chapter 2 :
#include <IDStream.h> //header
Main ( ) // start body
{ // Open curly braket
} // close curly braket
// comment hidden
// 1 baris coding
/ * , * / sume coding @ lbh dr 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 ( xberubah)
Rules:
1. ~ Tengok formula
2. ~Cari ade bape variable name
3. ~Declare variable
Input:
Cout <<“----------------------” ;
Cin >>variable_name_that_had_declared;
Rules: carefull dgn ejaan,huruf (kck & bsr)
Output:
Cout <<“----------------------”<<
variable_name_that_had_declared;
sample question!!!!!!!!!!
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 braket
//end baraket
madarita,nor kolifatun,noridayu,eswaran
chapter 1 :
algorithm (arahan pnjg) > pseodocode (arahan pendek) > flowchart > programming C++
sample question!!!!!!!!!!!!!!!!!!
example 1 :
Find the area of rectangle
Area = width * height[/color]
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
Pseudocode
1.Read width
2.Read Height
3.Set the area = width * height
4.Print output
Flow chart
Read width > raed 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
flow chart :
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 fahrenheit
pseudocode
1.read celcius
2.set the fohrenheit ( 9/5 *( celcius + 32 ) )
3.print output
Flow chart
Start > read celcius > set the area = ( 9/5 ) *( celcius + 32 ) > print output >end
Chapter 2 :
#include <IDStream.h> //header
Main ( ) // start body
{ // Open curly braket
} // close curly braket
// comment hidden
// 1 baris coding
/ * , * / sume coding @ lbh dr 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 ( xberubah)
Rules:
1. ~ Tengok formula
2. ~Cari ade bape variable name
3. ~Declare variable
Input:
Cout <<“----------------------” ;
Cin >>variable_name_that_had_declared;
Rules: carefull dgn ejaan,huruf (kck & bsr)
Output:
Cout <<“----------------------”<<
variable_name_that_had_declared;
sample question!!!!!!!!!!
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 braket
//end baraket
Subscribe to:
Posts (Atom)