Monday, 28 March 2011

CONTOH MID TERM EXAMINATION

EXERCISE


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 :-

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;

}

WEEKLY REFLECTION 7

-seperti biase,kami diberi rehat selama 1 jam.

-PN.AYUNI mengarahkan student  FOP,supaya menyiapkan segala tugasan yang telah diberikan selama ini ke dalam blog.

-kami diberi mase sehingga pukul 1.oo petang.

EXERCISE

 

Exercise

1. Write correct C++ syntax & for each statement below:

a) Initializing variable Pi with the value 3.14 (constant)
answer :
float pi =3.142;

b) Declare a variable named Perimeter with double data type
(declare variable)
answer :

double perimeter

c) Give instruction that allowed user to input data (input)
answer :
int data;
//input
cout<<"enter your data";
cin>>data;

d) Input number of computer using variable (input assign to variable value)
answer :
int number;
cin>>number;

2. Solve the question below. Show the working.

a) 5 * 2 % 3 + 25 / 5
answer :
= [10%3]+25/5
= 1+[25/5]
= 1+5
= 6

b) a = 5, b = 6
!((a < 3) && (a == 3) || (b > 9))
answer :
= !((5<3)&&(5 == 3) || (6>9))
= !((0)    &&(0)          || (0)
=           !((0)             (0)
=                   !(0)
=                      1

3. Identify syntax errors in the following program. (5errors)

include<iostream.h>
main()
{
float allowance = 300.00, salary;

cout<<"Input Salary = ";
cin>>salary;

TSalary = salary + Allowance;

cout<<"Salary is= "<< salary;
}

answer :
#include<iostream.h>
main()
{
float allowance = 300.00, salary;

cout<<"Input Salary = ";
cin>>salary;

TSalary = salary + Allowance;

cout<<"Total Salary is= "<< Tsalary;

return 0;}
4. Write a program that will calculate the monthly salary for an employee that where Saturday and Sunday are considered as non-working days.
answer :


5. Write a program that calculates the average of 5 numbers that can be input by user.

answer :


6. Write a program that will calculate the area of rectangular, triangle and circle.

answer :

SIFIR LOOP

EXERCISE IF...ELSE

2. CALCULATE (IF...ELSE)

CALCULATE:
a) RECTANGULAR
b) TRIANGLE
c) CIRCLE
d) FAHRENHEIT
e) CELCIUS

Your Selection:

Your Selection is _________ and you are calculate _________. The answer is _____________












ASSIGNMENT 1 MESIN TIN MINUMAN (SWITCH...CASE)

1. MESIN TIN MINUMAN (SWITCH...CASE & IF...ELSE)

*************************
MESIN TIN MINUMAN
--------------------
1- PEPSI
2- COCA COLA
3- F&N MIRINDA
4- F&N ORANGE
5- 100 PLUS
*************************

Enter your drink:
Enter your money (RM):

Your drink is __________ and your balance are __________

*If the customer does not enter enough money, asked the customer to insert the money. (if...else)







WEEKLY REFLECTION 6


- seperti biase,kami diberi rehat selama 1 jam.
- PN.AYUNI telah memberi kami latihan yang Exercise Question Past Years.
- PN.AYUNI memberi tempoh kepada kami untuk menyiapkan tugasan dari pukul 10.00 hingga 12.00 tengahari.
.
-PN.AYUNI akan menyemak jawapan yang kami berikan..

-PN.AYUNI telah memberikan kami tugasan iaitu Assignment yang kedua-2 iaitu Membuat Sifat menggunakan coding (looping)..

contoh loop



WEEKLY REFLECTION 4

_seperti biase,kami diberi rehat selama 1 jam.

-selepas rehat,kami belajar chapter 4 iaitu operators and expressions.

-kami belajar ARITHMETIC OPERATORS,RELATIONAL OPERATORS,LOGICAL OPERATORS DAN ASSISMENT OPERATORS.

-Pn.Ayuni memberi kami exercise dan kami diberi tempoh selama 45 minit untuk menyiapkannya.

 - setiap group hendaklah menyiapkannya dan setiap wakil ahli group prelu membuat jawapan didepan.


CHAPTER 4 OPERATORS AND EXPRESSIONS.
4.1 Operators
-   C++ is very rich in built-in operators.
-  Operators triggers some computations when applied to operands in an expression.
- The commonly use operators are as follows :-
    a) Arithmetic Operators
    b) Relational Operators
    c) Logical Operators
    d) Assignment Operators

- Table 4-1 shows the commonly use operators in C++ programming language.

Arithmetic Operators
Relational Operators
Logical Operators
Assignment Operators
+
>

&&
=
-
<

||

*
>=
!

/
<=


%
==



INCREMENT AND DECREMENT OPERATOR

- Increment  -  Pro-increment   (++N)
                    - Post-increment  (N++)

- Decrement  - Pro- decrement   (--N)
                      - Post-decrement   (N--)
- For Example :-

 Int n ;                                                                            Int n ;
n = 5                                                                              N=5

cout << n, 5                                                                   cout << n, 5
cout << ++N ; 1+5 =6                                                    cout << N++ ;
cout << N ; 6                                                                 cout<< n ;  




Int M;                                                                                      Int M ;       
M= 9                                                                              M = 10
         
Cout << m; 9                                                                 cout << m ; 10
Cout << --M ; 8                                                             cout << M-- ; 10-1 =9
Cout << M ; 8                                                                cout << M ; 9


LOGICAL OPERATING

M
N
M&&N
M||N
0
0
0
0
1
0
0
1
0
1
0
1
1
1
1
1

!(M&&N)
!(M||N)
!M
!N
1
1
1
1
1
0
1
0
1
0
0
1
0
0
0
0


















! (M&&N) && (M||N)
!(M) || !(N)
1
1
0
1
0
1
0
0

For Example :-

++ a + --b * 4  > ++n  && p++ + q-- * 4 < x++ + 4

= 3 + 2 * 4 > 3* 2 + 4 &&      3 + 2 * 4 < 3 * 2 + 4
= 3 + 8 > 6 + 4            &&      3 + 8 < 6 + 4
= 11 > 10                     &&      11 < 10
=    1                            &&           0
                                      0