Você está na página 1de 18

KOLEJ PROFESIONAL MARA BERANANG FOUNDATION OF HIGHER NATIONAL DIPLOMA IN COMPUTING (BIT) ASSESSMENT COVER SHEET Student Name

Student ID No. Unit Name Unit Code Status: Instructor : : : Programming On c# Assessment No Assignment title Assignment No :3 : EUT :-

Assignment [ ]/Lab [ ]/ Quiz [ ] / Midterm : CSC 2154 Test [ ] / End of unit test[ x ] : Core : YM Raja Mahani binti Raja Date Out/In : 24 October 2008 Mohamed Ali Cik Norazimah Nasir Pn. Nur Akmal Hafizan Kamal Iqbal : Jul-Dec 2008 : FHND 2 (1) 18 RMM Duration Decision sampled by IV FHND 2 (2) 10 NHK : 2 hours : Yes[ ] / No[ Total 28 2 ]

Semester Mentors Name Group No. of Students Assessor Signature Questions No.

Assessment Criteria 1. Appreciate problem specification and develop appropriate program design. 2. Apply the structure and elements of a structured high level programming language.

SECTION A, SECTION B AND SECTION C

Overall Grading Scheme for Assessment Grade DISTINCTION MERIT PASS FAIL D M+ M P+ P F Criteria As specified in Assessment Grading Scheme for D As specified in Assessment Grading Scheme for M+ As specified in Assessment Grading Scheme for M As specified in Assessment Grading Scheme for P+ As specified in Assessment Grading Scheme for P None of the above or copied others work

OVERALL GRADE FOR ASSESSMENT 3 : ______________

Lecturers Comments: What you have done :

What you should do :

___________________ Lecturers signature Date:______________ Verification: Prepared by: YM Raja Mahani binti Raja Mohamed Ali Verified by Subject Leader Sign. Sign. Initial NHK Initial Date 21/10/08 Date

Date:21/10/2008 Unit Coordinator SAO

SECTION A : METHOD (35 MARKS)

Answer all questions.

1. Which one of the following best describes a method call?

a. Identifies a method parameters b. Defines the operation a method must perform c. States the name of the method and passes parameters d. Identifies the type of data returned from a method

2. The parameter list in the method definition are known as

a. Actual parameter b. Global parameter c. Local parameter d. Formal parameter.

3. What is the purpose of the term method type in a method definition?

a. To specify the type of variables passed to the method b. To specify the type of data the method returns c. To specify the type of variables used as parameters d. To specify the data type of the method

4. The syntax of a method call is

a. data type method name (parameter list); b. <modifier> method name (parameter list); c. method name (argument list); d. return type method name (parameter list);

5. Given the following code fragment, what is the value of num after the method count ( ) is called and executed twice? static void count ( ) { int num=0; num+=2; }

a. 0 b. 1 c. 2 d. more than 2

6. Which of the following is FALSE about parameters?

a. Is also known as arguments b. Can be more than 5 parameters in one method c. The number of parameters list in method definition must not be the same as the number of parameter list in method call. d. The data type for parameters in method definition can consist of different data types. 7. When a value is return back from a particular method to main method, it is called

a. method type b. return type c. return value d. method call

8. i. ii. only can pass back an updated value from a method must be written with a special modifier

Which of the following is suitable for the above description?


a. Reference parameter b. Value parameter c. Out parameter d. Params parameter

9. A parameter without any modifier is a

a. Reference parameter b. Value parameter c. Out parameter d. Params parameter

10. Which one of the following best describes a method definition

a. Contains the statements that indicate the method name and parameters to be used in processing. b. Calls a predefined method and passes the necessary parameters. c. Allocates a storage location for the return value. d. Tells the compiler which method you are using.

11. Write a method header for each of the following method information

a. Method average () has 3 arguments. The first and second arguments x and y are type of double. The third argument, avg is reference parameter of type double.

b. Method max() that return the biggest of the given 3 numbers of num1, num2 and num3 through its integer parameter big.

c. Method small () that returns the smallest of the given 2 double, a and b, using an integer variable, smallest.

d. Method count_length () that takes an argument of name and it will then return the length of name through its parameter of length_of_name.

e. Method Calculate_price () that takes 1 parameter of price and another parameter of quantity. It would then return using a variable total_price.

[10 marks]

12. Fill jn the blank with appropriate answers.

** This method will be able to calculate and display no. of 50 ringgit, 20 ringgit and 10 ringgit from the amount money (rounded number) entered by user and bring back the updated value through its parameters.
using System; class method { public static void Main () { ________ money; int no_of_50ringgit=0, no_of _20ringgit=0, no_of_10ringgit=0; Console.WriteLine (Please enter amount of money : RM); __________ = Convert.ToInt32 (Console.ReadLine ( )); calculate_no_of_cent(money, _______ no_of_50ringgit, _______ no_of_20ringgit, _______ no_of _10ringgit); Console.WriteLine(The no of 50 ringgit is {0}, 20 ringgit is {1} and 10 ringgit is {2}, no_of_50ringgit, no_of_20ringgit, no_of_10ringgit); } static void calculate_no_of_cent (____________money, ___________ _________no_of_50ringgit, ___________ _________no_of _20ringgit, __________ _________no_of _10ringgit) { int balance=0, balance1=0; no_of_50ringgit =__________ /50; balance=money%50; ___________________=balance/20; balance1=balance%20; ___________________=balance1/10; }

[15 marks]

SECTION B : ARRAY (35 MARKS)

Answer all questions.

1. Which of the following correctly declares an array? A. int array1[10]; B. int array1; C. array1{10}; D. array array[10];

2.

What is the index number of the last element of an array with 15 elements? A. 15 B. 14 C. 0 D. more than 15

3. Which of the following is a two-dimensional array? A. array array2[20][20]; B. int array2[20][20]; C. int array2[20, 20]; D. char array2[20];

4. Which of the following correctly accesses the eighth element stored in name, an array with 100 elements? A. myarray[7]; B. myarray[8]; C. myarray(8); D. myarray;

5. Which of the following gives the memory address of the first element in array of your_array, an array with 100 elements? A. your_array [0]; B. your_array; C. your_array[1,0]; D. your_array [1];

6. Which of the following gives the memory address of the last element in twodimensional array of two_d_array, with [9][9] elements? A. two_d_array [0,8]; B. two_d_array[8]; C. two_d_array [8,0]; D. two_d_array [8,8];

7.

In two dimensional array, first number refer to _________ and the second number refer to ________

A. column, row B. row, column C. x-axis, y-axis D. y-axis, x-axis


8. Which of the following is TRUE?

A. Array should be declared with the array size. B. Array cannot be declared in the programmer defined method. C. Array can be initialized. D. Array cannot be brought as parameter to a method 9. double [ , ]array1=new double [5,5]; What is the default value for the above declaration?
A. NULL B. 0 C. Nothing D. 0.00

10. Array name : randomnumber


30 16 54 32 19 31 34 23 78 45 49 71

How to initialize the above array?

A. int [ , ] randomumber= {{30, 54, 19, 34}, {16, 32, 31, 23}, {78, 45, 49, 71}}; B. int [ , ] randomumber= {(30, 16, 78), (54, 32, 45), (19, 31, 49), (34, 23, 71)}; C. int [ , ] randomumber= {30, 16, 78, 54, 32, 45, 19, 31, 49, 34, 23, 71}; D. int [ , ] randomumber= {{30, 16, 78}, {54, 32, 45}, {19, 31, 49}, {34, 23, 71}};

[10 marks]

11. Determine whether the following declarations are VALID or INVALID statements and make correction for INVALID statement. a. int [ ] name_list=new name [4]; ANSWER: CORRECTION : b. int size=6; int [ ] array1 new int [size]; ANSWER: CORRECTION: c. double list [ ] = {1.1,2.2,3.3,4.4,5.5}; ANSWER : CORRECTION : d. int [ ]student = new int [3] {5,6,7,8};
ANSWER : CORRECTION :

e. char [ , ] grade = {{D,D,M}, {P,R,M}, {D,M,F}}; ANSWER : CORRECTION : [10 marks] 12. Refer to the following program. Draw the array list and the contents of the array list after the execution of the i. First for loop ii. Second for loop [10 marks] using System; public static void Main() { Int [ ] list=new int [8]; int count; //first for loop for(count=0;count<8;count++) { list[count]=count; } //second for loop Console.WriteLine{list=); for(count=0;count<8;count++) { list[count]=list[count]+list[count+1]; Console.WriteLine{list[count]); } } SECOND FOR LOOP : ANSWER : FIRST FOR LOOP:

13. Use the following declaration: int [ ] arr1={3,4,6,2,7}; int [ , ] arr2={{9,6},{7,3},{5,2}, {4, 8}}; char [ ] arr3=new char [3]; int i; a. What is the value for arr1[4], arr2[1,2], arr1[0], arr3[1],arr2[2,0], and arr3[0]? arr1[4] : ___________ arr2[1,2] : ___________ arr1[0] : ___________ arr3[1] : ___________ arr2[2,0] : ___________ arr3[0] : ___________ [3 marks] b. If we execute i=2, what is the value of the expression arr1[ i ]*arr1[ i+2 ]? [1 mark] c. If we execute i=0, what is the value of the expression arr2[ i ,2] + arr2[ i+2, 1 ]? [1 mark]

SECTION C: STRUCT (30 MARKS)


1. The program below will calculate 3 menu items and display the total price to user. Correct the errors contain in the program. Indicate the line numbers that contain errors. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 } } } static double totalPrice(menuType[] menu) { int i; double payment=0.0; for (i = 1; i <= 3; i++) payment = payment + menuOrdered[i - 1].price; return payment; class Program { public struct menuType { public string menuItem; public double price; } public static void Main() { menuType[] menuOrdered = new menuType[3]; double payment; menuOrdered[0].menuItem = "Spaghetti"; menuOrdered[0].menuPrice = 8.90; menuOrdered[1].menuItem = "Lasagna"; menuOrdered[1]. menuPrice = 10.50; menuOrdered[2].menuItem = "Chicken Wing"; menuOrdered[2]. menuPrice = 9.90; totalPrice(menuOrdered); Console.WriteLine("Total price: RM{0}", payment);

Answer:______________________________________________ ____ __________________________________________________ __________________________________________________ __________________________________________________ __________________________________________________ [5 marks]


2. Write the output of the program below: using System; class Program { public struct Time { public int hour; public int minute; public int second; } public static void Main( ) { Time dinnerTime; dinnerTime.hour = 18; dinnerTime.minute = 30; dinnerTime.second = 0; Console.Write("Dinner will be held at "); printMilitary(dinnerTime); Console.Write(" military time,\nwhich is "); printStandard(dinnerTime); Console.WriteLine(" standard time"); Console.ReadLine(); } static void printMilitary(Time t) { if (t.hour < 10) Console.Write("0{0}", t.hour); else Console.Write("{0}", t.hour);

if (t.minute < 10) Console.Write(":0{0}", t.minute); else Console.Write(":{0}", t.minute); } static void printStandard(Time t) { Console.Write("{0}",t.hour % 12); if(t.minute<10) Console.Write(":0{0}",t.minute); else Console.Write(":{0}",t.minute); if(t.second<10) Console.Write(":0{0}",t.second); else Console.Write(":{0}",t.second); if (t.hour < 12) Console.Write(" AM"); else Console.Write(" PM"); } }

Answer: __________________________________________________ _________________________________________________ [3 marks] What is the output of the above program if the initial values of dinnerTime.hour and dinnerTime.minute are as below: dinnerTime.hour=10 and dinnerTime.minute=5 Answer: __________________________________________________ __________________________________________________ [8 marks]

3. Write a program that will prompt user to enter 3 sets of date which consist values: day, month and year in method Main( ). Use struct in array to store the values entered. Display the entered date in method displayDate. Use struct to declare a struct type of named date.

[14 marks]

Assessment 3 Grading Scheme Grade


st

Assessment Grading Criteria


1 attempt

Remarks

D M+ M P+ P

75% and above


1st attempt

70-74.9%
1st attempt

65-69.9%
1st attempt

60-64.9%
1st attempt

50-59.9%
1st attempt

0-49.9%

Grade (1st attempt) : _____________________________

Você também pode gostar