INTERNATIONAL DIPLOMA IN COMPUTER STUDIES
PROGRAMMING TECHNIQUES USING JAVA
|
Registration No: |
|
|
|
- |
|
|
|
- |
|
|
|
|
Student No: |
|
|
|
|
|
|
|
DURATION: 3 Hours and 10 Minutes Reading Time
INSTRUCTIONS:
ü Students are reminded to write their own Registration and Student Number clearly on Question Paper and All Pages of Answer Scripts.
ü Students are reminded to read the questions carefully.
ü No reference material of any kind may be taken in the examination.
ü Students must attempt ANY FIVE questions.
ü Clearly cross out the SURPLUS answers, failure to do this will result in the first five answers being marked.
ü There are 3 pages altogether.
QUESTION NO |
MAXIMUM MARKS |
MARKS OBTAINED |
1 | 20 |
|
2 | 20 |
|
3 | 20 |
|
4 | 20 |
|
5 | 20 |
|
6 | 20 |
|
7 | 20 |
|
8 | 20 |
|
TOTAL | 100 |
|
Question 1
Compare and contrast the advantages and disadvantages between programming using Machine languages, Assembly languages, and High-level languages. [20 Marks]
Reference as following:
languages | Advantages | Disadvantages |
Machine | Efficiency at run time and simplicity of instructions | Difficult to learn , time consuming to write and very difficult to amend |
Assembly | Very efficient in its use of the machines’s facilities, eg: most system and time critical routines | Requires the programmer to have a good knowledge of the machine |
High-level | Much more complex formulae may be expressed by using a single instruction in these high-level language | Need to be translated into equivalent machine instructions |
Question 2
A supermarket introduces the following payment procedures for candies:
1. 10% discount if you buy more than 20 packets
2. 7% discount if you buy more than 10 packets
3. Otherwise the discount is 5%
Construct a decision table for implementing the above decision procedure. [20 Marks]
Reference as following:
1 candies>=20packets | Y | N | N | N |
|
|
2 candies>=10packets | N | Y | N | N |
|
|
3 candies<=10packets | N | N | Y | N |
|
|
|
|
|
|
|
|
|
10% discount is given | X |
|
|
|
|
|
7% discount is given |
| X |
|
|
|
|
5% discount is given |
|
| X | X |
|
|
Question 3
The Fibonacci numbers are defined as the following sequence:
1 1 2 3 5 8 13 21 34 55 …
Use the recursive method to calculate the sum of the first N Fibonacci numbers. [20 Marks]
Reference as following: |
|
public class aaa{
public static int fib(int n){
if(n<2){ return 1; }
else{
return((fib(n-1))+(fib(n-2))); }
}
public static void main(String[] args){ int i=0;
while(i<=9){ System.out.print(fib(i)+" "); i++; } System.out.println();// next line }//main }//class |
Question 4
Explain the meaning of the terms “class” and “object” used in object-oriented programming.
Reference as following: | |
class | A class can contain properties(variables)and methods(subroutines), is used to create objects , is a kind of factory for constructing objects |
object | Object is abstraction of class, is created and destroyed as the program runs, and there can be many objects with the same structure, if they are created using the same class |
[20 Marks]
Question 5
Dry running the following code and show the result:
int i = 0;
String strTmp = "";
while (i<9)
{
i = i + 3;
strTmp += "*";
strTmp += i;
}
System.out.print(strTmp);
Reference as following: | |
public class aaa{
public static void main(String[] args){
int i=0; String str=""; while(i<9){
i=i+3; str+="*"; str+=i; } System.out.println(str);
}//main
}//class
|
|
[20 Marks]
Question 6
Write short notes on the features of the following program development aids:
1. Flowcharter [5 Marks]
2. Text editor [5 Marks]
3. Screen formatter [5 Marks]
4. Decision Table preprocessor [5 Marks]
Reference as following: | |
Flowcharter | It takes the source code of the compiled program , this is particularly useful for comparison with the original flowchart to check that the code ,with all modifications ,still conforms to the logic of the original specification |
Text editor | It is used for the creation and maintenance of program files, the availability of a context search makes a text editor a suitable tool for use during program testing |
Screen formatter | It improve the formatting of screens for on-line systems |
Decision Table preprocessor | It is used for checking the validity of logic expressed in decision table form and to produce object code which is suitable,after testing ,for running as production programs |
Question 7
Write a program to sort the following array using the “Quicksort” algorithm:
5 4 86 1 45 74 20 40 10 4 8
1. With recursive [10 Marks]
2. Without recursive [10 Marks]
Reference as following: |
|
With recursive | Without recursive |
public class aaa{ public static void main(String[] args){ int i; int[] a={5,4,86,1,45,74,20,40,10,4,8}; sort(a); for(i=0;i<11;i++){
System.out.print(a[i]+" "); }
System.out.println();
}//main
public static void sort(int[] number) { sort(number, 0, number.length-1); }
private static void sort(int[] number, int left, int right) { if(left < right) { int q = partition(number, left, right); sort(number, left, q-1); sort(number, q+1, right); } }
private static int partition(int number[], int left, int right) { int s = number[right]; int i = left - 1;
for(int j = left; j < right; j++) { if(number[j] <= s) { i++; swap(number, i, j); } }
swap(number, i+1, right);
return i+1; }
private static void swap(int[] number, int i, int j) { int t; t = number[i]; number[i] = number[j]; number[j] = t; } }//class
|
|
Question 8
Briefly describe the steps to debug a program. [12 Marks]
“Debugging is the process of searching for errors in a program.” Comment on this statement.
[8 Marks]
Reference as following: |
|
1) unit testing. For example testing for local data structure、bound condition 2) integration testing. |
INTERNATIONAL DIPLOMA IN COMPUTER STUDIES PROGRAMMING TECHNIQUE USING JAVA |
Registration No: |
|
|
|
- |
|
|
|
- |
|
|
|
|
Student No: |
|
|
|
|
|
|
|
DURATION: 3 Hours and 10 Minutes Reading Time
INSTRUCTIONS:
ü Students are reminded to write their own Registration and Student Number clearly on Question Paper and All Pages of Answer Scripts.
ü Students are reminded to read the questions carefully.
ü No reference material of any kind may be taken in the examination.
ü Students must attempt ANY FIVE questions.
ü Clearly cross out the SURPLUS answers, failure to do this will result in the first five answers being marked.
ü There are 3 pages altogether.
QUESTION NO |
MAXIMUM MARKS |
MARKS OBTAINED |
1 | 20 |
|
2 | 20 |
|
3 | 20 |
|
4 | 20 |
|
5 | 20 |
|
6 | 20 |
|
7 | 20 |
|
8 | 20 |
|
TOTAL | 100 |
|
Question 1
1. Describe the following terms related to a decision table:
a. Action Stub [7 Marks]
b. Action Entry [7 Marks]
References as following: |
| ||||||||||||||
|
2. “Use float variables to keep money value is not safe” Comment on this statement.
[6 Marks]
References as following: |
|
A float can have about 7 significant digits.so that 32.3989231134 and 32.3989234399 would both have to be bounded off to about 32.39892 in order to be stored in a variable of type float |
Question 2
1. List and describe branch statements in Java language. Give examples.
[10 Marks]
References as following: |
|
Branch statement tells the computer to take one alternative courses of action, depending on whether the value of a given Boolean-value expression is true or false. For example An if statement is as following: If(grade>60) System.out.println(“you have passed the exam!”); Else System.out.println(“sory you haven’t passed the exam!”); |
2. Describe the overload and override concepts in object-oriented programming. Give examples. [10 Marks]
References as following: | 方法的重写Overriding和重载Overloading是Java多态性的不同表现。 |
Overload:重载Overloading是一个类中多态性的一种表现。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载(Overloading)。Overload的方法是可以改变返回值的类型。
| |
Override:重写Overriding是父类与子类之间多态性的一种表现,如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding)。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被"屏蔽"了。
|
Question 3
1. What do you understand by the term “Compiler”? [12 Marks]
References as following: |
|
Compiler is the program that translates source code programs into computer language. The result is an executable file or program. · First the source code is read into the computer's memory · Then it will be translated into a kind of in between code: OBJECT CODE · A program will have many different objects and libraries that need to be linked together into one (large) executable |
2. What is unbalanced array? Give example. [8 Marks]
References as following: |
|
An unbalanced array is a multidimensional array where the dimension isn't the same for all rows. For example:
|
Question 4
Develop a program, using for loop to print out the following numbers: [20 Marks]
9 8 7 6 5 4 3 2 1 0
8 7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
6 5 4 3 2 1 0
5 4 3 2 1 0
4 3 2 1 0
3 2 1 0
2 1 0
1 0
0
References as following: |
|
public class aaa{ public static void main(String[] args){ int i=0,j=0,k=0; int x; for(i=9;i>=0;i--){ for(k=0;k<(9-i);k++) System.out.print(" "); //4个空格
for(j=i;j>=0;j--){
System.out.print(j+" "); //3个空格
} System.out.println();
} } } |
Question 5
Write a program to multiply the following matrixes [20 Marks]
List and describe Layouts and Components concept in Java. Give examples.
[10 Marks]
References as following: |
|
public class aaa{ public static void main(String[] args){
int[][] a={{5,4,-2},{4,-6,-5},{7,8,1}}; int[][] b={{8,2},{-2,4},{3,3}}; int[][] c=new int[3][2]; int i,j,k;
System.out.println("Array a=="); for(i=0;i<3;i++){ for(j=0;j<3;j++){ System.out.print(a[i][j]+" "); } System.out.println(); } System.out.println(); System.out.println("Array b=="); for(i=0;i<3;i++){ for(j=0;j<2;j++){ System.out.print(b[i][j]+" "); } System.out.println(); } System.out.println(); System.out.println("Array a*b=="); for(i=0;i<3;i++){ for(j=0;j<2;j++){ c[i][j]=0; for(k=0;k<3;k++){
c[i][j]+=a[i][k]*b[k][j];
}//k
}//j
}//i
for(i=0;i<3;i++){ for(j=0;j<2;j++){ System.out.print(c[i][j]+" "); } System.out.println(); } }//main }//class |
Question 6
Use example to explain the Quick sort algorithm [20 Marks]
References as following: |
|
Quicksort is a very efficient sorting algorithm, It has two phases: the partition phase and the sort phase. For example: sort the following array 5 4 86 1 45 74 20 40 10 4 8
public class aaa{ public static void main(String[] args){ int[] a={5,4,86,1,45,74,20,40,10,4,8}; sort(a); for(i=0;i<11;i++){ System.out.print(a[i]+" "); } System.out.println(); }//main public static void sort(int[] number) { sort(number, 0, number.length-1); } private static void sort(int[] number, int left, int right) { if(left < right) { int q = partition(number, left, right); sort(number, left, q-1); sort(number, q+1, right); } }
private static int partition(int number[], int left, int right) { int s = number[right]; int i = left - 1;
for(int j = left; j < right; j++) { if(number[j] <= s) { i++; swap(number, i, j); } }
swap(number, i+1, right); return i+1; } private static void swap(int[] number, int i, int j) { int t; t = number[i]; number[i] = number[j]; number[j] = t; } }//class |
Question 7
Using Java programming language, give one example of
1. Syntax error [10 Marks]
2. Logic error [10 Marks]
References as following: | example |
Syntax error(语法错误) | public class aaa{ public static void main(String[] args){ int i=0; …… System.out.println(i) //缺分号 } } |
Logic error(逻辑错误) | public class aaa{ public static void main(String[] args){ while (i >= 0){ …… } //infinite loop } } |
Question 8
Briefly describe step to debug a program. [20 Marks]
INTERNATIONAL DIPLOMA IN COMPUTER STUDIES PROGRAMMING TECHNIQUE USING JAVA |
Registration No: |
|
|
|
- |
|
|
|
- |
|
|
|
|
Student No: |
|
|
|
|
|
|
|
DURATION: 3 Hours and 10 Minutes Reading Time
INSTRUCTIONS:
ü Students are reminded to write their own Registration and Student Number clearly on Question Paper and All Pages of Answer Scripts.
ü Students are reminded to read the questions carefully.
ü No reference material of any kind may be taken in the examination.
ü Students must attempt ANY FIVE questions.
ü Clearly cross out the SURPLUS answers, failure to do this will result in the first five answers being marked.
ü There are 3 pages altogether.
QUESTION NO |
MAXIMUM MARKS |
MARKS OBTAINED |
1 | 20 |
|
2 | 20 |
|
3 | 20 |
|
4 | 20 |
|
5 | 20 |
|
6 | 20 |
|
7 | 20 |
|
8 | 20 |
|
TOTAL | 100 |
|
Question 1
1. What is Link List? Give example? [10 Marks]
2. Write a program to find an item in a link list. [10 Marks]
References as following: |
|
Link List: is a particular type of data structure, made up of objects linked together by pointers.
| |
Class node{ String item; Node next; } Public boolean search(String sItem){ aaa=head; | While(aaa!=null){ If(aaa.item.equals(sItem)) return true; Aaa=aaa.next; }//while return false; } |
Question 2
Describe:
- Software Quality Assurance – Early involvement [10 Marks]
- Test Metrics [10 Marks]
References as following: |
Software Quality Assurance(SQA for shortly)is very necessary in the course of software development, it consists of a means of monitoring the software engineering processes and methods used to ensure quality. It does this by means of audits of the quality management system under which the software system is created. These audits are backed by one or more standards, usually ISO 9000. engineering,goes into a design phase. Test QA get involved at this design phase. These two teams are working in parallel, at early design phase. Software testing is as much an art as a science. In large, complex applications, such as operating systems, it is practically impossible to iron out every single bug before releasing it both from a difficulty point of view and due to time constraints. Different software applications require different approaches when it comes to testing, but some of the most common tasks in software QA include: Validation testing Validation testing is the act of entering data that the tester knows to be erroneous into an application. For instance, typing "Hello" into an edit box that is expecting to receive a numeric entry. Data comparison Comparing the output of an application with specific parameters to a previously created set of data with the same parameters that is known to be accurate. Stress testing A stress test is when the software is used as heavily as possible for a period of time to see whether it copes with high levels of load. Often used for server software that will have multiple users connected to it simultaneously. Also known as Destruction testing. Usability testing Sometimes getting users who are unfamiliar with the software to try it for a while and offer feedback to the developers about what they found difficult to do is the best way of making improvements to a user interface. |
Question 3
- Compare and contrast the advantages and the disadvantages of Interpreters and Compilers. List 2 common interpreters and 2 common compilers. [10 Marks]
References as following: |
| ||||||||||||
Similarity: They both translate high-level language program into machine language program. Differences:
|
- Describe steps to choose a programming languages [10 Marks]
References as following: |
|
根据兴趣选一个你认为有发展的语言,然后闭关修炼去。不管外面怎么说,学好了才是硬道理。以后不用担心你转不成其他语言。对于学生来说,我建议C/C++作为入门的基础。重点可以放在C++中,学好面向对象的思想。从编程中体会到为什么要用面向对象,而不是单纯的背书。计算机系的课不应该去背的,不懂的就查资料就行了。当学生有了一定编程能力后,就可以选择你以后作为主要的语言。即可以继续研究C++,也可以选择Java或.net中的任何一门语言。如果不浪费太多时间,大学时间内足够造就一个技术根基很好的计算机系学生。 |
Question 4
1. Write a recursive递归 method to calculate the factorial of a number: N! = N*(N-1)*(N-2)* … *3*1
Where N is a parameter and can be key in from keyboard. [12 Marks]
References as following: |
import java.io.*; public class aaa{ public static long Fac(int n){
if(n==1) return 1; else return n*Fac(n-1); } public static void main(String[] args){
String str=""; DataInputStream in=new DataInputStream(System.in); int N=0; System.out.println("please input a int data ! "); try{ str=in.readLine(); N=Integer.valueOf(str).intValue();
} catch(Exception e){ System.out.println("Sorry!, u are wrong");
}
System.out.println("N(int)= " +N);
System.out.println(N+"!= "+Fac(N)); } } |
2. Rewrite the method to calculate N! using the for loop. [8 Marks]
References as following: |
import java.io.*; public class aaa{ public static long Fac(int n){ long val=1; for(int i=1;i <=n;i++){ val=val*i; } return val; } public static void main(String[] args){
String str=""; DataInputStream in=new DataInputStream(System.in); int N=0; System.out.println("please input a int data ! "); try{ str=in.readLine(); N=Integer.valueOf(str).intValue();
} catch(Exception e){ System.out.println("Sorry!, u are wrong");
}
System.out.println("N(int)= " +N);
System.out.println(N+"!= "+Fac(N)); } } |
Question 5
In the library, they want to keep the following information about a book
Book ID String
Book title String
Author String
Year Integer
1. Declare a class to keep this information [8 Marks]
References as following: |
class book{ String book_id; String book_title; String author; int year; } public class aaa { public static void main(String args[]) { book a =new book(); a.book_id="love u"; System.out.println(a.book_id); }} |
2. Write a method to read data from keyboard [12 Marks]
References as following: |
import java.io.*; class book{ String book_id; String book_title; String author; int year; } public class aaa{
public static void main(String[] args){
String str=""; book a =new book(); DataInputStream in=new DataInputStream(System.in); int N=0; System.out.println("please input a int data ! "); try{
a.book_id=in.readLine(); a.book_title=in.readLine(); a.author=in.readLine();
str=in.readLine(); a.year=Integer.valueOf(str).intValue();
} catch(Exception e){ System.out.println("Sorry!, u are wrong");
} System.out.println(a.author); System.out.println(a.book_id); System.out.println(a.book_title); System.out.println(a.year); } } |
Question 6
- List and describe loop statements in Java. Give example. [10 Marks]
References as following: |
loop statements in Java are following: 1)the while statements , a while loop will repeat a statement over and over, but only so long as a specified condition remains true. For example: int number; // The number to be printed. number = 1; // Start with 1. while ( number < 1001 ) { // Keep going as long as number is < 1001. System.out.println(number); number = number + 1; // Go on to the next number. } System.out.println("Done!"); 2) the for statements, it contains three statements: initialization; continuation-condition; update. Use a block statement to do sth together. For example: int number; // The number to be printed. for ( number = 1 ; number < 1001 ; number++ ) System.out.println( number ); System.out.println("Done!"); 3) the do……while statements . The do..while statement is very similar to the while statement, except that the word "while," along with the condition that it tests, has been moved to the end. For example: int number; // The number to be printed. number = 1; // Start with 1.
do { System.out.println(number); number = number + 1; // Go on to the next number. } while ( number<1001 ); // Keep going as long as number is < 1001
System.out.println("Done!");
|
- Create an Array to store 5 float number [4 Marks]
References as following: |
float[] yt =new float[5]; |
- Sort this array use bubble sort algorithm [6 Marks]
References as following: |
import java.util.*; class aaa { public static void main(String args[]) {
float[] n ={ 0.5f , 0.9f , 0.1f , 0.6f , 0.3f }; // print the array's initial order System.out.println("Before sorting:"); for (int i = 0; i < n.length; i++) { System.out.println("n["+i+"] = " + n[i]); }
boolean sorted = false; // sort the array while (!sorted) { sorted = true; for (int i=0; i < n.length-1; i++) { if (n[i] > n[i+1]) { // swap if greater than... float temp = n[i]; n[i] = n[i+1]; n[i+1] = temp; sorted = false; } // if } // for } // while
// print the sorted array System.out.println(); System.out.println("After sorting:"); for (int i = 0; i <n.length ; i++) { System.out.println("n["+i+"] = " + n[i]); } } // main } // class |
Question 7
- In object-oriented programming, what are the Class and Object concept?
[8 Marks]
References as following: |
A class can contain properties (variables) and methods (subroutines).it is a kind of factory for constructing objects. objects belong to classes. |
A object is also a collection of properties and methods, but it is created and destroyed as the program runs, and there can be many objects with the same structure, if they are created using the same class. |
- Use example to explain step to create and destroy an object [6 Marks]
References as following: |
class Student { String name; // Student's name. double test1, test2; // Grades on two tests.
double getAverage() { // compute average test grade return (test1 + test2) //2; } } // end of class Student public class app{ public static void main(String[] args){ Student std, std1; // type Student. std = new Student(); // Create a new object belonging // to the class Student, and // store a reference to that // object in the variable std. std1 = new Student(); // Create a second Student object // and store a reference to // it in the variable std1. std.name = "John Smith"; // Set values of some instance variables. std1.name = "Mary Jones"; std=null; //destroy std object }// |
- What is Garbage collection? [6 Marks]
References as following: |
Garbage collection is a procedure that reclaim memory occupied by objects that are no longer accessible to a program. It is the responsibility of the system, not the programmer, to keep track of which objects are "garbage". |
Question 8
- What are stack and queue? Write methods that implement stack using array
[12 Marks]
References as following: |
|
Stack: A stack consists of a sequence of items, which should be thought of piled one on top of the other like a physical stack of boxes, Only the top item on the stack is accessible at any given time. | |
Queue: Queues are similar to stacks in that a queue consists of a sequence of items, and there are restrictions about how items can be added to and removed from the list. However, a queue has two ends, called the front and the back of the queue. Items are always added to the queue at the back and removed from the queue at the front. | |
|
- List some Java development aids packages available in your country and describe their purposes. [8 Marks]
References as following: |
|
Struts,Tiles , Ant ,Hibernate |