Question
eu Assume MLreadint and MLwriteint are primitives with side effects for inputoutput and consider the ML expression add1 of type int: let val x =
eu
Assume MLreadint and MLwriteint are primitives with side effects for inputoutput and consider the ML expression add1 of type int: let val x = MLreadint() in MLwriteint(x+1); x end (i) Give an equivalent expression which uses the IO monad instead of side-effects, and state its type. [3 marks] (ii) Give a function run2diff which can be applied to your answer to part (c)(i). When so applied it should give a value in the IO monad which corresponds to ML code that runs add1 twice and returns the difference between the values read. [4 marks] (d) State what happens when attempting to compile and execute the following Java fragment (explaining the origin of any error messages or exceptions which might arise). Object n = new Integer(42), o = new String("Whoops"); Object [] v; Integer [] w = new Integer[10]; v = w; v[4] = n; v[5] = o; [4 marks] (e) Consider the Java code: Object n = new Integer(42); ArrayList extends Object> v1; ArrayList
You have been given a new programming language with a C-like syntax, with integer variables and functions and with static binding of free variables. Your manager can For "int f(int x) { ... }" whether the variable x is passed by l-value ("by reference") or by r-value ("by value"). If the switch is set to "l-value" and the value passed is only an r-value then a new l-value is created, initialised and passed.
(i) implemented as a custom instruction [2 marks] (ii) implemented in a peripheral controlled using programmed I/O [2 marks] (iii) implemented in an autonomous bus master [2 marks] (c) Discuss whether each of the three means of part (b) could be appropriate for the bit-intensive operations mentioned above.
ensure to answer all
You have been given a new programming language with a C-like syntax, with integer variables and functions and with static binding of free variables. Your manager can parameterise certain aspects of the language, including the following three options: For "int x = e;" whether the variable x has the same l-value of e or whether a new l-value is created and initialised to the r-value of e. If e is only an r-value then a new l-value is created in both circumstances. For "int f(int x) { ... }" whether the variable x is passed by l-value ("by reference") or by r-value ("by value"). If the switch is set to "l-value" and the value passed is only an r-value then a new l-value is created, initialised and passed. For "int f(int x) { ... y ... }" (where the variable y is free to f) whether the value of y is calculated at the times of its uses (association by l-value) or at the time of the definition of f (association by r-value). As a test of your programming skills your manager asks you to write a program which tells how the language has been parameterised. Do so by printing a 3-digit decimal number where the "hundreds" digit is one or two according to whether the first option is by l-value or r-value respectively, similarly with the "tens" digit for the second and with the "units" digit for the third option. [10 marks] Explain the structure of an object module which an assembler or compiler might produce to be processed by a linker. Your answer should include discussion of the various object module features needed to represent the compiled form of the C program: int a[10] = { 2,3,5,7,11,13,17,19,23,29 }; extern int b[10]; extern int g(int); int f(int y) { return g(y) + b[5] + a[6]; }
(a) Randomness is used in several places in communication protocols. Discuss the role of random choices with regard to resource allocation, making reference to telephony call routing, Ethernet Media Access Control, and Queue Management in IP routers. [15 marks] (b) Some researchers have claimed that RED (Random Early Discard) queueing can reduce the latency through a bottleneck router for all users. (i) How might this be the case? [3 marks] (ii) How could the addition of Explicit Congestion Notification help make it so?
(a) (i) Write out the matrix for the three-qubit Toffoli gate. [2 marks] (ii) A three-qubit system is in the state 1 2 (|000i + |101i + |110i + |111i). The Toffoli gate is applied to this system and then a measurement is performed on the first qubit. What is the probability of observing a |1i? Show all working out. [2 marks] (b) State and prove the no-cloning theorem. [6 marks] (c) Suppose we are given a qubit |i in an unknown state, but we know it is either |0i or 1 2 (|0i + |1i). We would like to devise a circuit to determine, with certainty, which of the two is the case, using any number of unitary and measurement operations. Either explain how to construct such a circuit, or prove that no such circuit is possible.
The lifecycle of an exam question in a fictitious university includes at least the following stages, which take place over several months: 1. Professor invents question. 2. Chief examiner sanity-checks it. 3. Professor amends it if necessary. 4. External auditor sanity-checks it. 5. Professor amends it again if necessary. 6. Chief examiner approves final version. 7. Clerk prints question in required number of copies. Following a scandal whereby some dishonest candidates got hold of questions ahead of time, thus forcing the whole exam to be invalidated and repeated to the dismay of the honest participants, the university has put pressure on its departments to ensure this will not happen again. (a) The Head of Department A, where the leak occurred, is now paranoid about computer networks and insists that no exam question shall ever reside on any networked computer system until after the corresponding exam takes place. (i) Describe four ways that a determined undergraduate might nonetheless get hold of exam questions before the exam even if that requirement were observed. [4 marks] (ii) Describe a security policy suitable for department A, taking into account the head-of-department's requirements and the staff workflow. Discuss it thoroughly, including requirements analysis, incentives and technical mechanisms. [4 marks] (b) The Head of Department B finds that A's requirement would impose an excessive penalty on the productivity of her staff. At the same time, she certainly does not want to be blamed for the next leak. (i) Describe a security policy suitable for department B, taking into account the head-of-department's requirements and the staff workflow. Discuss it thoroughly, including requirements analysis, incentives and technical mechanisms.
Many languages either forbid explicit pointer arithmetic or restrict its use. What kinds of problem are they seeking to avoid? Why is it allowed (with some restrictions) in C and C++, and commonly used by programmers? [8 marks] What are the dangers inherent in allowing memory deallocation to be under the direct control of the programmer? Given these dangers, why has memory deallocation not been automated in standardised C or C++? [12 marks] 7 Prolog for Artificial Intelligence According to the rules of the Billy Badger Fan Club, an applicant is acceptable for membership provided that: The applicant must have two proposers who are members of the club. The applicant must be aged between 18 and 30 years of age (inclusive). Each proposer must have been a member for at least two years. Each proposer must not be a parent of the applicant. Write a Prolog program that includes a rule for deciding whether an applicant is acceptable for membership, illustrating with a sample database.
a Programmer-Defined Class in Java Summary In this lab, you will a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type double. W public set methods to set the values for length and width. Write public get methods to retrieve the values for length and width. Write a public calculateArea Omethod and a public calculate Perimeter) method to calculate and return the area of the rectangle and the perimeter of the rectangle. Open the file named MyRectangleClassProgramjava. In the MyRectangleClassProgram class, create two Rectangle objects named rectangle1 and rectanglez Set the lengthof rectangle1 to 10.0and the width to 5.0. Set the length of ectangle2 to 7.0 ridthto
Print the value of rectangle1's perimeter and area, and then print the value of rectangle2's perimeter and area. Execute the program. MYRECTANGLECLASSPROGRAM.JAVA class Rectangle /Length of this rectangle. I/ Width of this rectangle. I/ Write set methods here. //Write get methods here. //Write the calculatePerimeter0 and
// Write the calculatePerimeter0 and I/ calculateArea) methods here. RECTANGLE.JAVA -lass Rectangle //Length of this rectangle. I/Width of this rectangle. /Write set methods here. I/Write get methods here.
View the example video to see how your program should run (Doesn't have to be exactly the same but should be similar). See example video Download the supplied starter project: See download link Extract the project from the zip file to a location on your hard drive. (I recommend a location like Documents/FullSail/DES1/Assignments). Do not use generic types or LINQ commands - the point of this assignment is to show that you understand arrays and how to use data stored in them. Deck class: constructors Default: Parameters None Overloaded constructor: Parameters Int: this value represents the desired number of cards in the deck and should be used to initialize the deck's array of PlayingCards to hold that number of cards. Create public methods static void FillDeckWithPlayingCards Parameters Deck: this is the deck object that is to be filled with cards Function If the deck passed in cannot hold 52 cards - initialize the array to hold 52 cards. fill the deck with each card ace-king for each suit (hearts, clubs ...) void DisplayDeck Parameters Int: required parameter that specifies how many cards draw in a row before starting a new row Int: optional parameter that specifies a x position on the screen to start drawing cards at Int: optional parameter that specifies a y position on the screen to start drawing cards at Function Draw ever card in the deck 1 at a time going across the screen in rows. Drop down to a make a new row after x cards where x is the number passed in as the first parameter void AddCard Parameters PlayingCard: card that should be added into the deck Function if the deck isn't full then add the passed in card on top as the next card to be drawn. void Shuffle Parameters None Function This method will randomize the position of all of the cards in the deck PlayingCard DrawCard Parameters None Function This method will remove the top card from the deck and return that card assuming the deck isn't empty void CutDeck Parameters Int: optional parameter that specifies where to cut the deck (number of cards to take off of the top of the deck). Should default to a value of -1. Function If the parameter is a positive value then cut that many cards off the top of the deck. if the parameter is negative then cut a random number of cards off the top of the deck must handle players trying to cut more cards than are in the deck. Program: C a menu in main that will allow the player to test the following deck options. (This menu should run in a loop until the player chooses to quit) Fill the deck with playing cards Shuffle the cards in the deck Cut a random number of cards from the top of the deck Cut a number of cards from the top of the deck specified by the player (required input from the player) Display all of the cards in the deck Quit quit by selecting the menu options (the number) quit by typing "quit" quit by typing "exit" The player should not be able to crash the program with invalid input
(a) Outline five pieces of information required by the Distance Selling Regulations. [5 marks] (b) Explain what is meant by the "Freemium model" for online services. [5 marks] (c) Explain the business model for social networks. [5 marks] (d) Discuss whether newspapers can survive in a digital age.
Write program to calculate the difference between two numbers all of the numbers Even? 2. write a program to calculate (y) from the equation: y-(6-x32 Write program that checks whether an integer number is prime or not. 8. Write a program to read n number of values in an array and display it in reverse order. Write program to read in a character and check whether it's a digit, an alphabet, or a special character.
(a) Describe two ways in which the interpretations of {P}C{Q} differ in Hoare logic and in separation logic. [4 marks] (b) Which of the following equations hold for all P and Q? In each case justify your answer. (i) P ? P = P [2 marks] (ii) P P = P [2 marks] (iii) P ? Q = Q ? P [2 marks] (iv) P Q = Q P [2 marks] (c) Is the Hoare triple {X .= 0 ? Y .= 1} [X]:=Y {X 7 1 ? Y .= 1} true? If so give a proof, stating any rules that you use; if not, explain why not.
Cr a Programmer-Defined Class in Java Summary c a programmer-defined class and then use it in a Java program. The program should create two Rectangle objects and find their area and perimeter. Instructions Make sure the class file named Rectangle.java is open. In the Rectangle class, create two private attributes named lengthand width. Both length and width should be data type dpublic set methods to set the values for length and width. Write public get methods to retrieve the values for length and width. Write public calculateArea Omethod and a public calculate Perimeter) method to calculate and return the area of the rectangle and the perimeter of the rectangle. Open the file named MyRectangleClassProgramjava. In the MyRectangleClassProgram class, create two Rectangle objects named rectangle1 and rectanglez Set the lengthof rectangle1 to 10.0and the width to 5.0. Set the length of ectangle2 to 7.0 ridthto
Explain what is meant by a referential integrity constraint in a relational data model. [4 marks] The University of Cambridge is determined to maintain its standards under increasing financial pressure. The government maintains league tables of various kinds: teaching quality, research rating, unit cost of each student place. The university still enjoys a high reputation worldwide, but it is in competition with institutions such as MIT and Stanford whose unit costs are much greater. The only way to provide facilities such as new research laboratories, graduate accommodation, a much-needed swimming pool, is by public appeal. It is vital that there is close liaison between the university development offices and colleges so that prospective donors do not become alienated by simultaneous demands. You have been invited by the university to assist in recording details of its fund-raising. The main purpose is to coordinate the activities of agencies such as the university and college development offices in their dealings with prospects. The latter may be alumni of some college, charitable foundations or major companies with an educational commitment; it is important to record their interests (bioscience, student welfare, sport) so that they can be approached in a favourable context; also their potential resources, in order to maximise the possible benefit to the university. At any time a number of projects need funding: each will be developed by a single agency, requiring that a target sum be raised by a given date; projects will have one or more purposes which may be linked with the interests of prospects. The other main use of the database is to keep a diary of interaction with prospects; in order to retain their goodwill it is essential to know who has been invited where and when, and in what context. Design the schema for a relational database that will record this information. State clearly any assumptions that you need to make in order to complete the design, and indicate any difficulties that you foresee in maintaining the database.
You have been given a new programming language with a C-like syntax, with integer variables and functions and with static binding of free variables. Your manager can parameterise certain aspects of the language, including the following three options: For "int x = e;" whether the variable x has the same l-value of e or whether a new l-value is created and initialised to the r-value of e. If e is only an r-value then a new l-value is created in both circumstances. For "int f(int x) { ... }" whether the variable x is passed by l-value ("by reference") or by r-value ("by value"). If the switch is set to "l-value" and the value passed is only an r-value then a new l-value is created, initialised and passed.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started