Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

) Explain the term overloading in the context of Java constructors and methods. [2 marks] (b) Without describing the details of either, outline the relationship

) Explain the term overloading in the context of Java constructors and methods. [2 marks] (b) Without describing the details of either, outline the relationship between the Java methods System.out.printf() and String.format(). [2 marks] The ISO representation for the time of day is hh:mm:ss where (for the purposes of this question) hh is a two-digit integer in the range 00 to 23 and each of mm and ss is a two-digit integer in the range 00 to 59. The following Java test program exercises a proposed class Time which enables a time to be represented in ISO format and allows one time to be added to another: public class TimeProg { public static void main(String[] args) { Time t1 = new Time(15,10,5); t1.add(5,10,15); t1.add(10,20); t1.add(5); System.out.printf("%s%n", t1); // outputs 20:30:45 Time t2 = new Time(60,70,80); System.out.printf("%s%n", t2); // outputs 13:11:20 t1.add(t2); System.out.printf("%s%n", t1); // outputs 09:42:05 Time t3 = new Time(); System.out.printf("%s%n", t3); // outputs 00:00:00 } } It may be assumed that only positive arguments are used but note that outof-range values for minutes and seconds are treated sensibly (thus 80 seconds results in 1 being added to the number of minutes). An out-of-range value for hours is held modulo 24. (c) Outline suitable specifications for the two versions of the constructor Time() and the four versions of the add() method. [6 marks] (d) Wte a class Time that would work with the test program above.

Let datatype 'a bintree = empty | node of 'a * 'a bintree * 'a bintree be the polymorphic data type representing binary trees. (a) Define the curried function treemap that given an 'a -> 'b function and then an 'a bintree produces a 'b bintree of exactly the same shape as the given one but with all nodes having been mapped by the function. [4 marks] (b) Use treemap to define the function lift that converts an 'a bintree into an 'a option bintree. Further use treemap to define the curried functional prefilter that given a predicate 'a -> bool and then an 'a bintree returns an 'a option bintree in which the information on the nodes that do satisfy the predicate is omitted. [3 marks] (c) Define the function ('a, 'b) DFfoldRtoL : ('a * 'b -> 'b) -> 'b -> 'a bintree -> 'b that folds a binary tree (using its second input as base case and its first input in each recursive step) as the tree is traversed in a depth-first manner from right to left. Your definition should be such that the function fun inorder t = DFfoldRtoL op:: [] t lists a binary tree in infix order. [5 marks] (d) Use DFfoldRtoL to define the function 'a inorderData : 'a option bintree -> 'a list that lists the data in its input tree in infix order. [2 marks] (e) Define a function 'a cleanup : 'a option bintree -> 'a bintree satisfying the specification inorder(cleanup t) = inorderData(t) for all types and values t of type option bintree and such that cleanup(lift t) = t for all types and values t of type bintree

(a) What is the difference between MouseListener and MouseAdapter? [3 marks] (b) Via suitable HTML, the compiled version of the following Java code is presented to the appletviewer application: import java.applet.Applet; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class MouseTest extends Applet { private String s = "Hello World"; public void init() { this.addMouseListener(new ML()); } public void paint(Graphics g) { g.drawRect(15, 15, 270, 70); g.drawString(this.s, 100, 60); } class ML extends MouseAdapter { public void mousePressed(MouseEvent e) { MouseTest.this.s = "Mouse Pressed"; } } } Briefly explain what the code does and describe the initial appearance of the applet window. [6 marks] (c) The programmer moves the mouse pointer into the applet window, presses the mouse button and expects a new message to appear. Why doesn't it appear? Give three ways in which the expected result can be provoked without leaving appletviewer. [6 marks] (d) The line MouseTest.this.paint(MouseTest.this.getGraphics()); is added to the method mousePressed(). Describe the behaviour now if the mouse button is pressed when the pointer is in the applet. [3 marks] (e) What would have been a more appropriate amendment to the method mousePressed()? Explain.

(a) Define the terms injective, surjective and bijective, and state the Schroder- Bernstein theorem concerning the existence of a bijection between two sets. [4 marks] (b) What is a countable set? [2 marks] (c) Prove the following assertions: (i) If C is a countable set and f : A C is an injection, then A is countable. [2 marks] (ii) If A and B are countable sets, then A B is countable. [2 marks] (iii) Z and Q, the sets of integer and rational numbers, are both countable. [4 marks] (iv) P(N), the set of all subsets of the natural numbers, is not countable. [2 marks] (v) If U is an uncountable set and f : U V is an injection, then V is not countable. [2 marks] (vi) R, the set of real numbers, is not countable.

You are to ite Java program. Its main class should be called Replicate and its behaviour is to be that the following two sequences of Unix commands must result in exactly the same text appearing on your terminal: 1. cat Replicate.java 2. javac Replicate.java java Replicate in other words the output from the program should be identical to its own source. Your code is not permitted to inspect the file system, so items along the lines of ... new InputStream(new File("Replicate.java")) ... are prohibited. Your code is expected to be reasonably neatly laid out and must contain at least one comment! Credit will be given for code brevity and for inclusion of a clear explanation of how your code works. (a) Describe, with the aid of diagrams where appropriate, how Unix implements and manages: (i) a hierarchical name space for files; [2 marks] (ii) allocation of storage on disk; [2 marks] (iii) file-system and file meta-data; [8 marks] (iv) pipes. [4 marks] (b) A system administrator decides to make a 'versioned' file-system in which there are a number of directories called /root-dd-mm-yyyy, each of which holds a copy of the file-system on day dd, month mm and year yyyy. The idea is that at any particular time only the most recent snapshot will be used as the 'real' filesystem root, but that all previous snapshots will be available by explicitly accessing the directory in question. In this way the system administrator hopes to allow resilience to mistaken edits or unintentional deletions by users, or to hardware problems such as a disk head crash. To implement this, the system administrator arranges for a program to run every morning at 01:00 which recursively 'copies' the current snapshot to the new one. However to save disk space, hardlinks are used in place of actual copies. Once the 'copy' is complete, the new snapshot is used as the new root. To what extent will this scheme provide the functionality the system administrator hopes for? What advantages and disadvantages does it have?

ite Java program to read a file content line by line and then print the content as console output Java program to read 2D matrix of type integer, with size 6*6, and display the diagonal matrix. java program to read two integer and swap the values using third variable.

(a) Describe with the aid of a diagram how a simple computer executes a program in terms of the fetch-execute cycle, including the ways in which arithmetic instructions, memory accesses and control flow instructions are handled. [12 marks]

: te JAVA program to read and then add two numbers type integer and display the result. java program to read database tables from Microsoft Azure. The database is in azure. We a java program how to access the database and read the tables.

(a) In order to remove the overhead of a function call, a programmer decides to replace all calls to a function f with the macro F, where f and F are defined as follows: int f(int x) { return x+x;} #define F(X) (X)+(X) (i) Give two valid C expressions involving f which produce different results when F is substituted for f. Justify your answer. [4 marks] (ii) State the C language feature which can be used to correctly remove the overhead of a function call. [1 mark] (b) Consider the following: static struct link { int v; struct link *next; } *head=0; void convert(int a[], int len); Write function definition for convert which updates head to point to a linked-list containing the elements of a in the same order. You may assume len contains the number of elements in a. [5 marks] (c) Consider the following C++ declaration: template int SumSquares(); (i) Using function specialisation, provide an implementation of SumSquares so that, given an integer N, SumSquares() returns: X N i=1 i 2 [5 marks] (ii) Compare and contrast the functionality of the C preprocessor and the C++ template system. Explain why it is not possible to write a C preprocessor macro to implement SumSquares.

(a) The extension of a list `, denoted #`, is the set of all its elements; that is, formally, #[] = { } #(h::t) = {h} #t Thus, for instance, #[0,1,2,3,1,2,3,2,3,3] = {0, 1, 2, 3}. You are asked to give four implementations of an (extensional) remove curried function ''a rm : ''a -> ''a list -> ''a list satisfying the following specification: #(rm x `) = (#`) \ {x} for all equality types , and values x of type and ` of type list. (i) The first implementation should use the ML built-in functional 'a filter : ('a -> bool) -> 'a list -> 'a list [2 marks] (ii) The second implementation should use the ML built-in functionals 'a concat : 'a list list -> 'a list ('a, 'b) map : ('a -> 'b) -> 'a list -> 'b list [2 marks] (iii) The third implementation should be a simple recursive function using only the list datatype constructors. [4 marks] (iv) The fourth implementation should be a tail-recursive function using only the list datatype constructors. [6 marks] (b) Rigorously argue for the correctness of either the third or the fourth of your

Consider the following grammar for expressions (where Id is a terminal symbol representing an identifier resulting from lexical analysis): Expr ::= 1 | 2 | Id | Expr + Expr | Expr / Expr | Expr ^ Expr | (Expr) (a) Explain in what principal respect this grammar is unsatisfactory. [1 mark] (b) Assuming further that + is to be left-associative, ^ is to be right-associative and / is to be non-associative (i.e. 2/2/2 is forbidden but (2/2)/2 and 2/(2/2) are allowed), re-write the grammar to reflect this. [4 marks] (c) List the terminal symbols and non-terminal symbols, and count the production rules both in the original grammar and in the grammar in your answer to part (b). Indicate the start symbol in both grammars. [2 marks] (d) Define a type or types (in C, Java, or ML) suitable for holding an abstract syntax tree resulting from your answer to part (b). [2 marks] (e) Give a brief and elementary explanation of the principles of how the grammar resulting from part (b) might be used to cre a syntax analyser taking a token stream as input (via calls to function lex()) and giving as output an abstract syntax tree corresponding to part (d). Mention both hand-written and automatically-generated syntax analysers. [8 marks] (f ) Summarise any issues related to left- or right-associative operators in the two techniques (in implementing the parser and in constructing the tool) you outlined in part (e). [3 marks]

(a) Wte a procedure and a call to it in block-structured pseudocode such that the execution of the procedure under pass-by-reference and under pass-by-value/result yields different outcomes. Justify your answer. [7 marks] (b) Explain the meaning of static (i.e. compile-time) and dynamic (i.e. run-time) type checking. Compare the advantages and disadvantages of these two approaches to type checking from the point of view of the language designer, the language implementer, and the programmer. [6 marks] (c) Explain how objects can be simulated in SML, giving an example. Does it follow that SML, together with its module system, is an object-oriented programming language? Why? [7 marks] 8 Databases (a) What is the difference between a key and a functional dependency? [3 marks] (b) The schema R(A, B, C, D, E) has the following functional dependencies. A, B C B, C D C, D E D, E A (i) What are all of the keys of R? [3 marks] (ii) Which functional dependencies violate Boyce-Codd Normal form (BCNF)? [3 marks] (iii) Which functional dependencies violate Third Normal form (3NF)? [3 marks] (iv) Find a lossless-join decomposition of R into BCNF relations. [8 marks]

(a) Define the translation of the call-by-name -calculus into continuation passing style. [9 marks] (b) How does the translation differ for the call-by-value -calculus? [2 marks] (c) Now consider extending the call-by-name -calculus with exceptions: M ::== try M catch M | raise | x. M | M M | x where it reduces in the following way: try raise catch M M try x.M1 catch M2 x.M1 raise M raise Show how to translate this language into pure -calculus using continuations. [Hint: Use two continuations: one for the exceptional case, and one for the normal case.] [9 marks]

Decrease weight (DW): Decrease the weight on an existing edge in the graph by the given amount. Delete vertex (DV): Delete the given vertex from the graph and all its incident edges. Delete edge (DE): Delete the given edge from the graph. Increase weight (IW): Increase the weight on an existing edge by the given amount. (extra credit) Path (PA): Given two vertex identifiers, compute and print the weight and path between them in the MST using Dijkstra's algorithm. If the vertices are not in the same tree, then print a message stating this. Here is a summary of the update directives: Print-graph Print the graph print-mst Print the MST(s) insert-vertex u Insert vertex u in the graph insert-edge u v w Insert edge (u,v) with weight w in the graph decrease-weight u v w Decrease the weight of edge (u,v) by w units delete-vertex u Delete vertex u from the graph delete-edge u v Delete edge (u,v) from the graph increase-weight u v w Increase the weight of edge (u,v) by w units (extra credit) path u v Print the weight and path from u to v in the MST

You may assume that the input will adhere to these conventions and have valid values for vertices and weights. After each update operation, print a message indicating what operation was performed, and which vertex or edges were added to or deleted from the graph and full graph and MST. Operations input file for above example: PG will print full graph PM will print MST IV V4 message vertex V4 added, print full graph and MSTs (since V4 has no edges yet not-connected) IE V3 V4 10 message edge V3 V4 weight 10 added, print full graph and MST IW V3 V4 12 message added 12 to weight of edge V3 V4 (weight now 22), print full graph and MST IV V5 message vertex V5 added, print full graph and MSTs (since V5 has no edges yet not-connected) IE V2 V5 15 message edge V2 V5 weight 15 added, print full graph and MST DW V3 V4 6 message subtracted 6 from weight of edge V3 V5 (weight now 16), print full graph and MST DV V3 messages edge V2 V3 deleted, edge V3 V4 deleted, vertex V3 deleted, print full graph and MSTs DE V1 V2 message edge V1 V2 deleted, print full graph and MSTs PG print full graph PM print MSTs note: V1 and V4 in graph with no edges so 3 MSTs IE V4 V5 12 message edge V4 V5 weight 12 added, print full graph and MSTs IE V1 V2 43 message edge V1 V2 weight 43 added, print full graph and MST IE V1 V4 17 message edge V1 V4 weight 17 added, print full graph and MST IV V3 message vertex V3 added, print full graph and MSTs IE V1 V3 5 message edge V1 V3 weight 5 added, print full graph and MST IE V3 V4 26 message edge V3 V4 weight 26 added, print full graph and MST DV V2 messages edge V1 V2 deleted, edge V2 V5 deleted, vertex V2 deleted, print full graph and MSTs IV V6 message vertex V6 added, print full graph and MSTs IE V1 V3 2 message edge V1 V3 weight 2 added, print full graph and MST PA V5 V3 message print all Dijkstra's tables like lecture slide since number of vertices is less than 10, final distance V2 to V4 is 38, path V5 V4 V3 (extra credit) Implementation Requirements: You are required to implement at least three separate data structures for the assignment: (1) an undirected weighted graph, (2) a multiway tree, and (3) a binary heap. The undirected graph must be implemented using an adjacency matrix or adjacency list, and edges must have cross links between. The MST is to be stored in the multiway tree, using the leftChild and rightSibling representation. It will also be necessary to have a parent pointer for each node for path finding operations. The binary heap is used in Prim's algorithm. The update operations must be performed incrementally, by completely rebuilding the MST from scratch after each operation using Prim's algorithm.

Wrte a menu based program implementing the following functions: (1) rite a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in the two dimensional array. Wrie the two dimensional array out as a text file. You will want the file format to be as follows: The first two values stored in the file is the number of rows and the number of columns. The remaining data is to be the two dimensional array being stored as long double typed values. (2) Write a function like function #1, except in this time, instead of asking the user for the values for each row and column element, have the function create a randomily generated values for the row and column elements. Have the function that prompt the user for the name of a file to output as a text file, the randomily generated values between the numbers 0 and 1 such as 0.036757, 0.45425676, etc (inclusively means to include 0 and 1). Hint you may want to have your program generate two random numbers and divide the smaller of the two random numbers into the larger random number.

You will want the file format to be as follows: The first two values stored in the file is the number of rows and the number of columns. The remaining data is to be the two dimensional array being stored as long double typed values (3) Write a function to prompt the user for the name of a file to input as a text file to read in the two dimensional array of long double type. Output the contents of the two dimensional array to the screen. (4) ite a function to prompt the user for the name of a file to read in as a two dimensional array of the long double type and another filename for the name of the output file that will be outputting the two dimensional array after it has been sorted. Load in the data from the original text file and ask the user which column would they like to sort by Sort the two dimensional array based on the column the user specifies, and output the sorted two dimensional array to the output filename. (5) Wte a function to prompt the user for the name of a file to input as a text file to read in the two dimensional array of long double data type. Load in the data for the two dimensional array.

Kindly answer all the questions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago