# include <iostream.h>
# include <math.h>
main ( )
{ int x,y,z;
float a = 5.0;
x = y= z= 10;
x = 9%2*3 +pow(10,2);
cout << “\n The value of x is “<< x++;
y = +2+z;
y = a/y + z%5;
if(y<=5)
cout <<” \n value of y is greater than z”;<<z;
cout<<x<<”\n”<<y<<”\n”<<z;
return ;
}
3. .
int a,b,y=0;
cout << “Please enter any two integer number “;
cin >> a >> b;
if (a>b),y =pow(a,b);
if (a<b),y =pow(b,a);
cout << “the value of y is ” <<y;
What is the ouput for the above program segment if the value of
i. a = 4 and b = 2 ii. A = 2 and b = 4 iii a = 2 and b =2
4. Can all the if..elseif statement can be change to switch statement?
5. A person who want to work in Intel factory, must fulfill two requirements which
are
1. Pass SPM with minimum gred 2 and
2. Pass matemathics
State and draw the control structure to solve this problem.
“ Kekuatan tidak datang dari kemampuan fizikal, tetapi ianya datang dari semangat yang tidak pernah
mengalah”
Jh/tut1/2011
6. Convert the below flowchart to program . Use
a. if.. elseif statement
b. switch statement
Start
Input k and b
y
If k
==2 or
4
n Print
“modulus”
y
If k B%=2
==3 or
5
Print n
“multipicatio
n” Print
“division”
B*=2
b/=2
end
“ Kekuatan tidak datang dari kemampuan fizikal, tetapi ianya datang dari semangat yang tidak pernah
mengalah”
Jh/tut1/2011
7. Trace and write the output for the below program
No =1;
N1 = 2;
If ( no != n1-1)
{ no=n1;
n1=no;
}
else
{ n1=no;
no=n1;
}
cout << no<<n1;
8. Analyze the below program segment and find the error. State the type of error and
correct the error.
.
/* Tracing The Error*/
cin >> a,b,name;
a*b = j;
cout << salary << name << is << j;
9. Write a pseudo code and program to calculate salary for a person who work j
hours per week with the rate of RM K per hour. There will be 9% of KWSP and
RM100 insurance deduction from the salary. The program should display gross
salary (before deduction) and net salary for the person. (Note : Assume there is
four weeks in one month).
10 Clean Fast laundry shop is charging for the laundry based on a weight. Rate that
imposed is RM2.5 for one kilogram. If the total payment is RM30 and above,
10% discount would be given to the customer every day except for the
weekend.
“ Kekuatan tidak datang dari kemampuan fizikal, tetapi ianya datang dari semangat yang tidak pernah
mengalah”
Jh/tut1/2011