Monday, March 28, 2011

Questions


Question 1
1.Fill in the blanks with the appropriate data types for the following variables declaration syntax;
a)________Number 1= 1
b)________Number 3=3.0
c)________Text 1=''I have a car ''
d)________Huruf=''B''
e)________Account No=''66666664443''


Question 2
You are given PTPTN loan with the amount of RM16000.Calculate the amount that you should pay after PTPTN discount based on the CGPA.You must use if...else statement.

CGPA Diskaun
4.00 100%
3.99-3.00 80%
2.99-2.00 40%
0-1.99 0%

output:

Jumlah pinjaman = RM16000.00
CGPA yang diperoleh=3.00
Diskaun=RM12800

Jumlah pinjaman yang perlu dibayar selepas diskaun =RM 3200


Question 3
You are required to do a program that will execute the multipy or divide operation.The operation is based on the user's choice.You must use switch...case statement.

Output:

MENU PILIHAN
1.Pendaraban
2.Pembahagian
Masukkan nombor pertama=4
Masukkan nombor kedua=8
Masukkan pilihan anda=1
Hasil darab 4 dan 8 ialah 32


Question 4
Change the algebra expression to arithmetic expression


Question 5
5.Solve the statement below to find all value.Show the working;
a)m=5
m*=(3+4)*2

b)m=2
m*=((3+4)/2)-9


Question 6
6.Find the output for the folowing segment.
a)float var 1= 25.12 var 2= 15.0;

if
cout<<'' var 1 less or same as var 2'';
else
cout<<''var 1 bigger than var 2'';

b)int n= 20;
n/=5'


Question 7
7.Convert the while statement below to for statement.
int j=10;
while(j>0)
{
cout<<'' '' }


Question 8
8.Write a program that reads 4 prices using while loop and calculates the sum of the things 4 program must use function while for calculate the average of the prices.


Answer :


Question 1
1.a) integer
b) float
c) string
d) string
e) string


Question 2


2.#include < iostream.h >
main()
{

//declair variable
float cgpa, diskaun, jumlah_pinjaman, bayaran_pinjaman;

cout<<" Jumlah Pinjaman : ";
cin>>jumlah_pinjaman;
cout<<" CGPA yang diperoleh: ";
cin>>cgpa;

if ((cgpa>=3.99) && (cgpa<=3.00));
diskaun = jumlah_pinjaman * 80/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = " << diskaun;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = " << jumlah_pinjaman ;

if ((cgpa>=0) && (cgpa<=1.99));
diskaun = jumlah_pinjaman * 0/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = " << diskaun ;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = "<< jumlah_pinjaman ;

if ((cgpa>=2.99) && (cgpa<=2.00));
diskaun = jumlah_pinjaman * 40/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = " << diskaun ;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = " << jumlah_pinjaman ;
if (cgpa=4.00);
diskaun = jumlah_pinjaman * 100/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = "<< diskaun ;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = " << jumlah_pinjaman ;
}

return 0;
}


Question 3


Questions :
3.#include < iostream.h>
main ()
{

//declair variable
int num1,num2,selection,tm,td;

cout<<"Insert Number 1=";
cin>>num1;

cout<<"Insert Number 2=";
cin>>num2;

cout<<"Insert Number Selection=";
cin>>selection;

switch(selection)
{
case 1 : (selection=1)
total_multiply =num1*num2;
cout<<"total_multiply" << tm;

case 2 =(selection=2)
total_divide=num1/num2 ;
cout<<"total divide=" << td;
}

return 0;
}


Question 4
4.a)Y = (m - 4 ax) / 7a
b)Y = 6 bc / (4 sd – 2xy)
c)Y = (( 2 + AB + c ) / 3d ) + 5 xyz
d)Y = (2kb / 2 ki ) – 3 jb
e)Y= xy + x * x – 2 ab


Question 5
5.a) M = 5 * ( 3 + 4 ) * 2
M = (5 * 7 )* 2
M = 35 * 2
M = 70


Question 6
6.a) Float Var 1 = 25.12 , Var 2 = 15.0 ;
If (var 1 <= Var 2 )
Cout << “ Var 1 less or same as Var 2 “ ;
Else
Cout << “ Var 1 bigger than Var 2 “ ;


Question 7


7.#include < iostream.h >
Main()
{

//declaire variable
Int x ;
X = 1 ;
While (x < = 10 )

{
Cout<<”number “<
X++ ;
}
return 0;
}

Output :
Number 1 --------- 1
2 --------- 2
3 --------- 3
4 --------- 4
5 --------- 5
6 --------- 6
7 --------- 7
8 --------- 8
9 --------- 9
10 --------- 10


Question 8


8.#include < iostream.h >
main()
{

//declair variable
int k;
float p,total,averge;

k=1;
while (k<=4)
{
cout<<"Enter price=" << price;
cin>>p;
k++;
total=total+p;
}

Average=total/4;
cout<<"Your total is=" << total;

return 0;
}

No comments:

Post a Comment