1. Fill in the blank with the appropriate data types for the following variable declaration syntax
a .integer number 1=1
b. float number 3=30
c. string text 1=" i have a car"
d. string huruf = "b"
e. string account no = "6666666443"
2. You are given PTPTN loan with the amount of rm16000. calculate the amount that you should pay other PTPTN discount based on the CGPA. you must use if...else statement
Output
Jumlah pinjaman = rm16.000
CGPA yg diperoleh = 3.00
Diskaun = rm 12.800
Jumlah pinjaman yang perlu dibayar selepas diskaun = RM3200
3. You are required to do program that will execute the multiply or divided operation is based on the user's choice. you must use switch.....case statement
Output:
answer :
4.Change the algebra expression to anthmetic 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
Solve the statement below to find in value. Show the working :-
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";
b) int n = 20; n/= 5;
7. Convert the while statement below for for statement :-
{
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)
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";
b) int n = 20; n/= 5;
Answer :-
Output :
Cout<<Var1 bigger than Var 2 “ ;
<!--[if !supportLists]-->b) <!--[endif]-->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;
}
No comments:
Post a Comment