NO1 Best Kala Jadu Expert Specialist In Germany Kala Jadu Expert Specialist I...
Assignment1
1. TK6913 : PROGRAMMING 1
SEMESTER 3, 2004/2005
Name: Mohd Nasir Ahmad Aziz
Matrix No: G71508
ASSIGNMENT 1
1. The following table shows the exchange rates for a number of foreign
currencies:
Singapore Australia UK
SGD 1 = MYR 2.20 AUD 1 = MYR 2.60 UKP 1 = MYR 7.30
a. Calculate the following:
• the amount of Malaysian ringgit that can be obtained for SGD10.00
• the amount of Malaysian ringgit that can be obtained for UKP50.00
b. (*A) Build an algorithm for converting an amount of Singapore dollars to
Malaysian ringgit.
c. (*B) Build an algorithm for converting an amount of Australia dollars to
Malaysian ringgit.
d. (*C) Build an algorithm for converting an amount of UK pound to
Malaysian ringgit.
e. Generalize your algorithm so that it is capable of converting an amount
of any of the foreign currencies in the table given above to Malaysian
ringgit. Use the steps provided in (b) to build the algorithm.
2. A teacher needs to calculate the average marks for her students based on
the marks scored for the three tests given to them.
a. What is the average mark Ahmad will obtain if he scored 45%, 67% and
88% for those tests?
b. Build an algorithm to calculate the average mark obtained by a single
student.
c. Generalize your algorithm so that it is capable of calculating the average
marks for a number of students.
d. (Lab Task) Write your algorithms in CFlow and test them.
1
7. 2. d) Test with C Programming:
#include <stdio.h>
void main() {
int mark[12], i, bil, total_mark;
float Average_mark;
for(i = 0; i < 12; i++){
printf("Enter mark %d : ", i);
scanf("%d", &mark[i]);
}
total_mark= 0;
7
Total Mark 0
Total Mark + Mark [ i ]
OUTPUT
Average Mark
END
While i <12
Average Mark Total Mark / 12
8. for (i = 0; i < 12; i++)
total_mark += mark[i];
Average_mark = (float) total_mark / 12;
bil = 0;
for (i = 0; i < 12; i++ )
if (mark[i] > Average_mark)
bil++;
printf("nAverage mark= %.2f", Average_mark);
}
Output:
Enter mark 0 : 80
Enter mark 1 : 85
Enter mark 2 : 93
Enter mark 3 : 100
Enter mark 4 : 98
Enter mark 5 : 92
Enter mark 6 : 98
Enter mark 7 : 96
Enter mark 8 : 95
Enter mark 9 : 65
Enter mark 10 : 60
Enter mark 11 : 63
Average mark= 85.42
c) Alternative Answer
8
START
INPUT
Mark for Student 1: Test1, Test 2,Test 3
Mark for Student 2: Test1, Test 2,Test 3
Mark for Student 3: Test1, Test 2,Test 3
Mark for Student 4: Test1, Test 2,Test 3
9. 2. d) Test with C Programming: Alternative Answer
/* This Programme compute the Average mark of a number of students in three tests */
#include<stdio.h>
void main(){
int S1T1,S1T2,S1T3,Ave_S1,S2T1,S2T2,S2T3,Ave_S2,S3T1,S3T2,S3T3,Ave_S3,S4T1,
S4T2,S4T3,Ave_S4,Average;
printf("Marks for Student1 in Test1,2,3:n");
scanf("%d %d %d", &S1T1, &S1T2, &S1T3);
printf("Test1:%d, Test2:%d, Test3:%dn", S1T1, S1T2, S1T3);
Ave_S1=(S1T1+S1T2+S1T3)/3;
printf("Print marks for Student2 in Test1,2,3:n");
scanf("%d %d %d",&S2T1,&S2T2,&S2T3);
printf("Test1:%d,Test2:%d,Test3:%dn",S2T1,S2T2,S2T3);
Ave_S2=(S2T1+S2T2+S2T3)/3;
9
Average Student 1 (Test1 + Test2 + Test3 )/3
Average Student 2 (Test1 + Test2 + Test3 )/3
Average Student 3 (Test1 + Test2 + Test3 )/3
Average Student 4 (Test1 + Test2 + Test3 )/3
Average Average Student 1 + Average Student 2 + Average Student 3 +
Average Student 4
OUTPUT
Average
END
10. printf("Print marks for Student3 in Test1,2,3:n");
scanf("%d %d %d",&S3T1,&S3T2,&S3T3);
printf("Test1:%d,Test2:%d,Test3:%dn",S3T1,S3T2,S3T3);
Ave_S3=(S3T1+S3T2+S3T3)/3;
printf("Print marks for Student4 in Test1,2,3:n");
scanf("%d %d %d",&S4T1,&S4T2,&S4T3);
printf("Test1:%d,Test2:%d,Test3:%dn",S4T1,S4T2,S4T3);
Ave_S4=(S4T1+S4T2+S4T3)/3;
Average=(Ave_S1+Ave_S2+Ave_S3+Ave_S4)/4;
printf("Average:%d",Average);
}
OUTPUT
Marks for Student1 in Test1,2,3:
80 85 93
Test1:80, Test2:85, Test3:93
Print marks for Student2 in Test1,2,3:
100 98 92
Test1:100,Test2:98,Test3:92
Print marks for Student3 in Test1,2,3:
98 96 95
Test1:98,Test2:96,Test3:95
Print marks for Student4 in Test1,2,3:
65 60 63
Test1:65,Test2:60,Test3:63
Average:85
Page 49,Text Book
Question 4:
10
START
INPUT
Kod , Integer X, Integer Y
Z X + YIf Kod=c
Yes
11. Question 5: (Page 50,Text Book)
11
OUTPUT
Z
END
Z X - YIf Kod=c
Z X * YIf Kod=c
Z X / YIf Kod=c
Yes
Yes
Yes
No
No
No
No
START
INPUT
Kod Item
Harga 1 30.00 * qIf Kod Item=1
Yes
No
INPUT
Quantity, q
Harga 2 35.00 * qIf Kod Item=2
Yes
INPUT
Quantity, q
12. 12
OUTPUT
Jumlah Harga
END
No
Harga 3 40.00 * qIf Kod Item=3
Yes
No
INPUT
Quantity, q
Harga 4 90.00 * qIf Kod Item=4
Yes
No
INPUT
Quantity, q
Harga 5 120.00 * qIf Kod Item=5
Yes
No
INPUT
Quantity, q
Jumlah Harga Harga 1 + Harga 2 + Harga 3 + Harga 4 + Harga 5