FOR
# include < iostream.h >
main ( )
// declare variable
int x , y;
1) //get input
C out << " inter on integer = " ;
C in >> x;4
2) assign input
x = 5j
// loop for...
for ( y = 1; y < x; y++ )
{
C out << " " << x;
}
WHILE
# include < iostream.h >
main ( )
{
int x , y;
C out << Enter an integer = "
C in >> x ;
// while
y = 1;
while ( y<x )
{
C out << ' enter an integer =' ;
y++;
}
}
SOALAN
1) Change the if...else statement below to switch case statement
# include < iostream.h >
main ( )
{
int nom A, int no B, selection, value ;
C out << 2 number: " ;
Cout << "1. addition ";
Cout << "2.subtraction";
Cout << "3.multiply ";
Cout << "4.division ";
Cout << " enter selection = ";
Cin >> selection ;
{
if ( selection = = 1 )
{ value = nom A + nom B ; }
else if ( selection = = 2 )
{ value = nom A - nom B ; }
else if ( selection = = 3 )
{ value = nom A * nom B; }
else if ( selection = = 4 )
{ value = nom A / nom B; }
else {
Cout << " Invalid selection "; }
Cout << " the value is : ". << value ;
}
2) Change for loop statement below to while loop
# include < iostream.h >
main ( )
{
int i, power 2;
for ( i = 1; i < = 9; i ++ )
{
power 2 = i*i ;
Cout << " " << i << " power 2 " << power2;
}
}
Jawapan
# include ( iostream.h >
main ( )
int i, power 2 ;
// while
1 = 1;
while ( i < = 9 )
{
power 2 = i * i;
Cout << " " << " power2 " << power 2;
i ++ ;
}
}
3) write a program that input 2 number compare the numbers and display only the biggest number if the number are same, display " the numbers are same.
Jawapan
# include ( iostream.h >
main ( )
{
int num1, num2; numbers ;
Cout << " enter 2 numbers:;
Cin >> nom A >> nom B;
// if..else statement
if ( num2 > num 1 )
{ Cout << " num2 is bigger than num1 "; }
else if ( num2 = = num1 )
{ Cout << num2 is same as num1 "; }
else
{ ( out << " invalid " ; }
return O
}
4) write a nprogram using for loop that receive price of 3 products. Calculate the price that must be paid after 10% discount is given to every customer.
Jawapan
For Loop
# include < iostream.h )
main ( )
{
int x price , total discount;
for ( m = 1, x < 4; x++ )
Cout << " total " = << total ;
discount = total * 0.01;
Cout << discount = " << discount ;
return O ;
{
5) what is the input for the following program segment :
i) int x = 20;
for ( int i =5; i < = ; i ++ )
{
Cout << i ;
i = i + 4;
}
ii) int mul = ;
do
{
mul * 2;
Cout << " the mul is " << mul ;
mul ++ ;
}
while ( mul < 10 )
Jawapan
i) 5
10
15
20
ii) 1
3
7
#
Tuesday, April 12, 2011
Tuesday, April 5, 2011
example of C++ coding
1) printf ( " % d ", P- > angka ) ;
2) void main ( ){
3) Clrscr ( );
4) textcolor (14);
5) postorder ( p-> left );
6) postorder ( p-> right );
7) if ( p== NUL ) return;
8) free (p);
9) void clearall ( stuct data * p ) {
10) insert ( 8 ( * p)-> right,angka,level );
2) void main ( ){
3) Clrscr ( );
4) textcolor (14);
5) postorder ( p-> left );
6) postorder ( p-> right );
7) if ( p== NUL ) return;
8) free (p);
9) void clearall ( stuct data * p ) {
10) insert ( 8 ( * p)-> right,angka,level );
Wednesday, March 30, 2011
assignment 1
ANSWER :Step 1 :
Step 6 :
Step 2 :
Step 3 :
Step 4 :
Steap 5 :
Step 7 :
Step 8 : ( bile masukkan duit lebih dpd harga asal )
Step 9 :
Step 10 :
Step 11 :
Step 12 :
Step 13 :
Step 14 : ( bile masukkan duit kurang dpd harga asal )
Step 15 :
Step 16 :
Step 17 :
Step 18 :
Step 19 :
Friday, March 25, 2011
Tuesday, March 8, 2011
Latihan
1) solve the question below solve the working
a) 5*2 % 3 + 25/5
= 10 % 3 + 5
= 1+5
= 6
b) a = 5, b = 6
! ( ( a < 3 ) < & ( a = = 3 ) ll ( b > a ))
= 0 0 0
0 0
1 1
1/ true
2)identify the syntax errors in the following program
include < iostream.h >
main ( )
{
float allowance = Rm 300.00 salary,
Cout << "input salary = " ;
Cin > salary = " ;
T salary = salary + allowance ;
Cout << " salary is = " << salary ;
}
answer
n #
main ( )
Cin >>
return O;
3) write a program that will calculate the montly salary for an employee that where saturday & sunday are considered as no working days.
answer
# include < iosterea m . h >
main ( )
{
// declare variable
float noworking days ;
float salaryperday ;
float monthly salary ;
// input 1
Cout << " noworkingdays";
Cin >> noworking days ;
// input 2
Cout << " enter salaryperday = ";
Cin salaryperdays ;
formula
monthly salary = noworking days * salary perday " ;
// output
Cout << " monthlysalary << monthly salary ;
return O
}
4) write a program that allowance their everege of 5 number that can be input by user.
answer
# include <iostream . h >
main ( )
{
float no 1
float no 2
float no 3
float no 4
float total
float average
// input 1
Cout << " num 1 " ;
Cin >> num 1 ;
// input 2
a) 5*2 % 3 + 25/5
= 10 % 3 + 5
= 1+5
= 6
b) a = 5, b = 6
! ( ( a < 3 ) < & ( a = = 3 ) ll ( b > a ))
= 0 0 0
0 0
1 1
1/ true
2)identify the syntax errors in the following program
include < iostream.h >
main ( )
{
float allowance = Rm 300.00 salary,
Cout << "input salary = " ;
Cin > salary = " ;
T salary = salary + allowance ;
Cout << " salary is = " << salary ;
}
answer
n #
main ( )
Cin >>
return O;
3) write a program that will calculate the montly salary for an employee that where saturday & sunday are considered as no working days.
answer
# include < iosterea m . h >
main ( )
{
// declare variable
float noworking days ;
float salaryperday ;
float monthly salary ;
// input 1
Cout << " noworkingdays";
Cin >> noworking days ;
// input 2
Cout << " enter salaryperday = ";
Cin salaryperdays ;
formula
monthly salary = noworking days * salary perday " ;
// output
Cout << " monthlysalary << monthly salary ;
return O
}
4) write a program that allowance their everege of 5 number that can be input by user.
answer
# include <iostream . h >
main ( )
{
float no 1
float no 2
float no 3
float no 4
float total
float average
// input 1
Cout << " num 1 " ;
Cin >> num 1 ;
// input 2
Monday, March 7, 2011
miggu ke 2 bersama FOP
Alglorithm
1)Get the beight of the rectangle
2)Get the beight of the rectangle
3)Calculate the area of rectangle with multhply width by height.
4)Display the area of rectangle
Pseudcode
1)Read width
2) heiRead height
3)Set the area = width + height
4)Print output
1) find the area of circle:
[ area : 3.14* radius # radius ]
2) fine celcius
[ celcius = ( 5/9 ) # ( fahrenhait - 32 ) ]
3) find fahrenhait
[fahrenhait = ( 9/5 ) # ( {celcius + 32 } )
Question 1
1) Get the radius of circle
2) Set the area of circle with 3.14 multiphy the area of circle.
3) display the area of circle.
1) Read radius
2) Set the area = 3.14 # radius # radius
3) Print output
1)Get the beight of the rectangle
2)Get the beight of the rectangle
3)Calculate the area of rectangle with multhply width by height.
4)Display the area of rectangle
Pseudcode
1)Read width
2) heiRead height
3)Set the area = width + height
4)Print output
1) find the area of circle:
[ area : 3.14* radius # radius ]
2) fine celcius
[ celcius = ( 5/9 ) # ( fahrenhait - 32 ) ]
3) find fahrenhait
[fahrenhait = ( 9/5 ) # ( {celcius + 32 } )
Question 1
1) Get the radius of circle
2) Set the area of circle with 3.14 multiphy the area of circle.
3) display the area of circle.
1) Read radius
2) Set the area = 3.14 # radius # radius
3) Print output
First dayy with FOP
jam menunjukkn pukul tujuh..oppss sy lambat masuk kelas..mcam biaselh cari makan dulu..di hari pertama nie miss ayuni membahagikn kmi kepada beberapa kumpulan..mula mula tu nak same ngan ziehan..tapi miss kate mesti berdikari so sy pun masuk group lain..
di bwah nie adalah senarai tugasan yang mesti kami buat sepanjang sem nie tuk dpat yang terbaik:
Info: C++ ( programming language )
: Sofware = turbo C++
borland C++
der C++
visual C++
Carry mark:
Forum : upload file & chat
Weekly reflection (5m )
outcome 1-4
assignment ( 5m )
outcome 1-4
kena ade email & blog toturial (blog.sport.com / windows.com
midterm
final
buka internet - go to http// lect-ayuni.forums.net -regester by check "join" - check email -check the hhk given - test your user name and pastword by log in the forum =( this is for weekly reflection and other the latest info)
di bwah nie adalah senarai tugasan yang mesti kami buat sepanjang sem nie tuk dpat yang terbaik:
Info: C++ ( programming language )
: Sofware = turbo C++
borland C++
der C++
visual C++
Carry mark:
Forum : upload file & chat
Weekly reflection (5m )
outcome 1-4
assignment ( 5m )
outcome 1-4
kena ade email & blog toturial (blog.sport.com / windows.com
midterm
final
buka internet - go to http// lect-ayuni.forums.net -regester by check "join" - check email -check the hhk given - test your user name and pastword by log in the forum =( this is for weekly reflection and other the latest info)
Subscribe to:
Posts (Atom)