Saturday, 17 November 2018

LAB ACTIVITY 7 : Repetition Structure


Exercise 

a)  Create a program to generate a multiplication table by using while loop. The multiply is determined based on user input. Your output should be like below:

     Output:
     Please enter multiplication table: 3

     3 Times Table

     1 * 3 = 3
     2 * 3 = 6
     ..
     ..
     12 * 3 = 36




b)   Calculate the total of any five numbers using do … while loop.Your output should be like below:

      Output:
      Please enter number 1: 2
      Please enter number 2:  3
      Please enter number 3:  1
      Please enter number 4:  4
      Please enter number 5:  5

      The total of five numbers is 15




c)   Write a program for the following problem by using for statement:
Ahmad saves RM1000 in his account in a bank which returns 5% of annual interest. Assuming that all interests is left deposited in his account, calculate and print the amount of money in his account at the end of each year for 10 years by using for loop.









LAB ACTIVITY 6 : Control Structure

Exercise :

a) Write a program using if … else statement to display student’s bachelor class of graduation based on Cumulative Grade Point Average (CGPA) by referring to the table below.





b) Write an interactive program that contains if … else statement to calculate the area of a rectangle OR triangle OR circle. The selection depends on the character entered by the user -R/r for rectangle and T/t for triangle and C/c for circle. You may use the following equation:

area of rectangle = width × length

area of triangle = 12× base × height

area of circle = 3.142 × radius2





c) Modify the program in (b) by using switch … case statement.