QUESTION 1
1. Fill in the blank with appropriate data type for the following variables declaration syntax :-
a) Numerik (Integer) Number 1=1
b) Numerik (Nombor Nyata) Number 3=3.0
c) Bukan Numerik (Rentetan)Text 1=”1 have a car”
d) Bukan Numerik (Aksara) Huruf = “B”
e) Bukan Numerik (Rentetan) AccountNo =”6666666443”
1. 2 You are be given PTPTN loan with the amount of RM 1600.00. Calculate the amount of after PTPTN discount based on the CGPA. You must us if…else statement :
CGPA | DISCOUNT |
4.00
|
100%
|
3.99-3.00
|
80%
|
2.99-2.00 |
40%
|
0-1.99 |
0%
|
OUTPUT
Jumlah Pimjaman = RM 1600.00
CGPA yang Diperolehi = 3.00
Diskun = RM 12800.00
Jumlah pinjaman yang perlu dibayar selepas Diskun = RM 3200.00
Answer :-
#include <iostream.h>
main()
{
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<<endl;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = "<<bayaran_pinjaman<<endl;
if ((cgpa>=0) && (cgpa<=1.99));
diskaun = jumlah_pinjaman * 0/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = "<<diskaun<<endl;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = "<<bayaran_pinjaman<<endl;
if ((cgpa>=2.99) && (cgpa<=2.00));
diskaun = jumlah_pinjaman * 40/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = "<<diskaun<<endl;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = "<<bayaran_pinjaman<<endl;
if (cgpa=4.00);
diskaun = jumlah_pinjaman * 100/100;
bayaran_pinjaman = jumlah_pinjaman - diskaun;
cout<<"\n Diskaun = "<<diskaun<<endl;
cout<<" Jumlah pinjaman yang perlu dibayar selepas diskaun = "<<bayaran_pinjaman<<endl;
}
return 0;
}
1. 3. You are required to do a program that will execute the multiply or divide operation. The operating is based on the user’s. 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 darb 4 dan 8 ialah 32
Answer :
#include<iostream.h>
Main ()
{
Int num1,num2,selction,total_multiy,total_divide ;
Cout<<”Masukkan Nombor 1 =” ;
Cin>>Nombor 1 ;
Cout<<”Masukkan Nombor 2 =” ;
Cin>>Nombor 2 ;
Cout<<”Masukkan Nombor Pilihan =”;
Cin>>Pilihan ;
Switch(selection)
{
Case 1 =(selection=1)
Total_multiy =num1*num2 ;
Cout<<”Hasil_Darab”<<Num1<<”dan”<<Num2<<”Total_Multiply<<endl ;
Case 2 =(selection=2)
Total_Divide=Num1/Num2 ;
Cout<<”Hasil_Bahagi “<<Num1<<”dan”Num2<<”Total_Divide<<endl;
}
return 0
}
1. 4. Change the diagram expression to Arithmetic Expression
a) Y = m – 4ax
7a
Answer : Y = (m - 4 ax) / 7a
b) Y = 6ab___
4sd – 2xy
Answer : Y = 6 bc / (4 sd – 2xy)
c) Y = 2 + (AB + ( ) + 5 xyz
3d
Answer : Y = (( 2 + AB + c ) / 3d ) + 5 xyz
d) Y = 2kb = 3jb
2k1
Answer : Y = (2kb / 2 ki ) – 3 jb
e) Y = xy + x2 – 2ab
Answer : Y= xy + x * x – 2 ab
5.Solve the statement below to find in value. Show the working :-
a) M=5
M * = (3 + 4) * 2
Answer :-
M = 5 * ( 3 + 4 ) * 2
M = (5 * 7 )* 2
M = 35 * 2
M = 70
1 (TRUE)
b) M=2
M * = ((3 *4 ) / 2 ) = 9
Answer :-
M = 2 * (12/ 2 ) =9
M = ( 2* 6 ) = 9
M = 12 = 9
0 (FALSE)
1. 6. Find the output for the following segment :-
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 “ ;
Answer :-
Output :
Cout<<Var1 bigger than Var 2 “ ;
b) In n = 20 ;
n/ = 5 ;
Answer :-
Output :
Cout<<20 / 5 = 4 “ ;
7.
Convert the while statement below for for statement :-
Int j = 10 ;
While ( j > 10)
{
Cout << “ “ << j ;
J______ ;
}
Answer :-
#incude<iostream.h>
Main ()
{
//declare variable
Int x ;
X = 1 ;
While (x < = 10 )
{
Cout<<”number “<<x*1 ;
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
8.Write a program the reads 4 prices using while loop and calculate the sum of things. A program must use function while for calculate the average of the prices.
#include<iostream.h>
main ()
{
int k;
float p,total,averge;
k=1;
while (k<=4)
{
cout<<"Enter price "<<k<<"= ;
cin>>p;
k++;
total=total+p;
}
Average=total/4;
cout<<"Your total is "<<total<<"and average is "average;
return 0;
}