1. Fill in the blank with appropriate data type for the
following variables declaration syntax :
a) __________Number 1=1
b) __________Number 3=3.0
c) __________Text 1=”1 have a car”
d) __________Huruf = “B”
e) __________AccountNo =”6666666443”
ANSWER
a) int Number 1=1
b) float Number 3=3.0
c) string Text 1=”1 have a car”
d) char Huruf = “B”
e) int AccountNo =”6666666443”
2. You are given PTPTN loan with the amount of RM1600.Calculate the amount that you should pay after PTPTN discount based on 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 diperolehi:3.00
Diskaun:RM 12800
Jumlah oinjaman yang perlu dibayar selepas diskaun: RM3200
ANSWER
#include <iostrean.h>
main()
{
//declare variable
float (cgpa,discount,jumlah_pinjaman,bayaran_pinjaman;
cout<<"jumlah pinjaman=";
cin>>jumlah_pinjaman;
cout<<"cgpa yg diperolehi=";
cin>>cgpa;
if (cgpa>=3.99&&cgpa<=3.00);
diskaun = jumlah_pinjaman * 80/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun ="<<diskaun<<endl;
cout<<"jumlah pinjaman yg perlu dibayar selepas="<<bayaran_pinjaman<<endl;
3. You are required to do a program that will execute the multiply 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 8 ialah 32
ANSWER
#include <iostream.h>
main()
{
//Declare variable
int num1,num2,selection,total_multiply,total_divided;
cout<<"masukkan nombor 1=";
cin>>num1;
cout<<"masukkan nombor kedua=";
cin>>num2;
cout<<"masukkan pilihan anda=";
cin>>selection;
switch(selection)
{
case 1:(selection=1)
total_multiply = num1*num2;
cout<<hasil darab"<<num1<<"dan<<num2<<"ialah"<<total_multiply endl;
break
case 2:(selection=2)
total_divide = num1/num2;
cout<<hasil_bahagi"<<num1<<"dan<<num2<<"ialah"<<total_divide endl:
break
}
return 0;
}
4. Change the algebra expression to anathematic expression:
a) y=(m-4ax)/79
b) y=6bc/(45s-2xy)
c) y=((2+AB+C)/3d)+5xyz
d) y=(2kb/2ki)-3jb
e) y=xy+x*x-2ab
5. Solve the statement below to find m value show the working.
ANSWER
a) m=5
m*=m(3+4)*2
m=5*5(7)*2
m=25*14
m=350
b) m=2
m*=((3*4)1/2)-9
m=2*(12*1/2)-9
m=2*6-9
m=12-9
m=3
6. Find the output for the following segment.
a) float var 1=25.12, var 2=15.0;
if (var 1<=2)cout<<"var1 less or same as var2";
else cout<<"var1 bigger than var2";
b) in n=20; n/=5;
ANSWER
a)
float var 1=25.12, var 2=15.0;
if (var 1<=2)
cout<<"var1 less or same as var2";
else
cout<<"var1 bigger than var2";
output:
if(25.12<=2)
var 1 bigger than var 2
b)
int n=20;
n/=5;
output:
n=n/5
n=20/5
n=4
7. Convert the while statement below for statement
ANSWER
int j;
for(j=10;j>0;j--)
{
cout<<" "<
}
8. Write of program that needs 4 prices using while loop
and calculate the sum of the thing a program must
use function while for calculate the average of the
prices.
#include
main ()
{
int k;
float P,total,average;
K=1
while (k<=4)
{
cout<<"Enter price"<<k<<"=j;
cin>>P;
k++; total=total+P;
}
average=total/4;
cout<<"your total is"<<total<<"and average="" is"average;=""
return 0;
}