bp Assume MLreadint and MLwriteint are primitives with side effects…

Question Answered step-by-step bp Assume MLreadint and MLwriteint are primitives with side effects… bpAssume 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 ofside-effects, and state its type. (ii) Give a function run2diff which can be applied to your answer topart (c)(i). When so applied it should give a value in the IO monad whichcorresponds to ML code that runs add1 twice and returns the differencebetween the values read. (d) State what happens when attempting to compile and execute the following Javafragment (explaining the origin of any error messages or exceptions which mightarise).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 v1;ArrayList v2;ArrayList w = new ArrayList<>(10);Explain any differences in behaviour between assignments v1 = w and v2 = wand also between method calls v1.set(4,n) and v2.set(4,n). 6 Further Java(a) Describe the operation of wait() and notifyAll(). Ensure that your answerexplains when locks are acquired and released. [5 marks](b) A future is a mechanism to store the eventual result of a computation done inanother thread. The idea is that the computation is run asynchronously and thecalling thread only blocks if it tries to use a result that hasn’t been computedyet. An example program using a future is shown below.Future f = new Future() {@Overridepublic String execute() {// …long running computation…return data;};// …String result = f.get(); // blocks if execute() unfinishedUse wait() and notifyAll() to provide an implementation of the Future classthat would work with the example program above. [10 marks](c) Give one potential advantage and one potential disadvantage of using notify()instead of notifyAll(). [2 marks](d) Would it have been beneficial to use notify() instead of notifyAll() in yourimplementation? Justify your answer. [3 marks]7 (TURN OVER)CST.2016.3.87 PrologIn this question you should ensure that your predicates behave appropriately withbacktracking and avoid over-use of cut. You should provide an implementation of anylibrary predicates used. You may not make use of extra-logical built-in predicatessuch as findAll. Minor syntactic errors will not be penalised.(a) Explain the operation of cut (!) in a Prolog program. [2 marks](b) Rewrite choose without using cut. [2 marks]choose(0,_,[]) :- !.choose(N,[H|T],[H|R]) :- M is N-1, choose(M,T,R).choose(N,[_|T],R) :- choose(N,T,R).(c) Explain the operation of not (also written as +) in a Prolog program.[1 mark](d) Rewrite chooseAll without using not and cut (!). [10 marks]chooseAll(N,L,Res) :- chooseAll(N,L,[],Res).chooseAll(N,L,Seen,Res) :- choose(N,L,R),not(member(R,Seen)), !,chooseAll(N,L,[R|Seen],Res).chooseAll(,,Res,Res).(e) What is Last Call Optimisation and why is it beneficial? [3 marks](f ) Rewrite pos to enable Last Call Optimisation. [2 marks]pos([],[]).pos([H|T],[H|R]) :- H >= 0, pos(T,R).pos([H|T],R) :- H < 0, pos(T,R).8CST.2016.3.98 Software EngineeringDiscuss the contribution and the relative value of the following aspects of the moderndevelopment environment. Illustrate with examples from your group project, or fromexperience you gained working for a commercial software developer, or both. In eachcase, would you discard this feature if your employer let you, or insist on retaining it(even covertly) should your employer not value it? Explain your reasons.(a) Dividing a project into short development episodes or sprints.(b) Project progress visualisation tools such as PERT and GANTT charts.(c) Automated regression testing tools.(d) Source code management tools. Give a short portrayal of the three sections that make up the GlobalSituating System (GPS), and their fundamental programming, equipment and dataparts. [5 marks]? [5 marks](c) What information is communicated in the GPS signs, and how could it be utilized by collectors?[5 marks](d) Explain a portion of the manners by which an extra correspondence channel canbe utilized to help a GPS collector, and what benefits the client could notice.[5 marks]3 Digital Communication II(a) Describe the OSI (Open Systems Interconnections) reference model andtalk about instances of the systems administration works ordinarily connected with eachpart. [14 marks](b) What do we mean by layer infringement? Examine a portion of the reasons thatcould lead a logical convention implementer to participate in layer infringement andoutline with a model. [6 marks]4 Distributed Systems(a) You have been approached to plan an occasion arrangement and total assistanceto work above distribute/buy in middleware to be sent in differentnatural observing situations. Your administration is to publicize and distributeundeniable level occasions important to applications. It might buy into any distributedoccasions in the area of sending. Your administration may itself be dispersed.Recognize a rundown of specialized plan issues you would raise with your client earlierto indicating the help exhaustively. [12 marks](b) By method for an outline show the utilization of vector tickers to execute theconveyance in causal request of multicast messages among individuals from a shut,unstructured interaction bunch. Incorporate a clarification of the message conveyancecalculation.A few banks issue their Automatic Teller Machine (ATM) card clients withan arbitrarily chosen individual indentification number (PIN). Others issue theirclients with an underlying PIN just, and let the clients pick their own PIN thefirst time they utilize the card in an ATM. Portray the benefits and burdensof these methodologies. [5 marks]Once more, a few banks process the client PIN by encoding the record numberutilizing DES and a key known distinctly to their focal frameworks and ATMs, taking the firstfour hex digits of the outcome, supplanting the digits A, . . . , F with 0, . . . , 5 separately,lastly, in the event that the primary digit of the outcome is 0, supplanting it with a 1. What is thelikelihood that a crook can get the PIN right given three speculations? [5 marks]However different banks have utilized DES, and a key known distinctly to their focal frameworks andATMs, to scramble the PIN (whether haphazardly created or client chose); theythen, at that point, compose the outcome on the attractive strip on the client's card, so the ATMcan check it without reference to the focal framework. Portray the impedimentsof this course of action. [5 marks]To forestall assaults in view of controlling attractive strips, banks in somenations have moved to utilizing savvy cards. What impact would you expect such amove to have on the occurrence of card-based extortion? A certain computation using a non-deterministic Turing machine completesin T time-steps. The Turing machine has k states and uses an alphabet ofN symbols. A major theorem underpinning the concept of NP-completenessis based on a conversion of a description of such computations to booleanformulae which characterise them.Explain how, in such a reduction, boolean variables may be used to describestates that the Turing machine might be in. Show how to derive thosecomponents of the boolean formula that relate just to the way in whichthe Turing machine moves its read-write head. Your explanation shouldbe sufficiently complete and carefully explained that it could be used as aspecification of a program that would perform that part of the translation fromTuring machine descriptions to boolean formulae. You should not attempt toexplain the rest of the boolean formula or how it fits into a complete proof orprogram. [11 marks](d) In terms of T, k and N, about how many symbols does it take to write theboolean expression you generate? [3 marks]8CST.98.12.913 Numerical Analysis IILet n+ be the number of positive real roots of a polynomial pn(x). Let c be thenumber of changes of sign when the coefficients are taken in order. State Descartes'rule of signs. [2 marks]Ifp3(x) = x3 ? 8x2 + 11x + 20what does this rule say about the polynomials p3(x), p3(?x)? (a) For the two mystery Verilog modules below, what output sequences do theyproduce assuming that registers are initially reset to zero? Explain youranswer. [6 marks]module mystery0(input a, output reg [4:0] b);always @(posedge a) beginb[0] = !b[0];b[1] = b[0] ^ b[1];b[2] = &b[1:0] ^ b[2];b[3] = &b[2:0] ^ b[3];b[4] = &b[3:0] ^ b[4];endendmodulemodule mystery1(input c, output reg [4:0] d);always @(posedge c) d[0] <= !d[0];always @(posedge d[0]) d[1] <= !d[1];always @(posedge d[1]) d[2] <= !d[2];always @(posedge d[2]) d[3] <= !d[3];always @(posedge d[3]) d[4] <= !d[4];endmodule(b) If the modules were to be implemented in terms of two-input AND, OR andXOR gates, NOT gates, and D flip-flops, what would be the minimal circuits?[6 marks](c) Which module could be clocked most quickly if it were implemented on anFPGA with 4-input look-up tables (LUTs)? Explain your answer. [4 marks](d) What are the timing issues for any circuit looking at the outputs of the twomystery modules? [4 marks]2CST.2008.3.32 Floating-Point Computation(a) Write a function in a programming language of your choice that takes a (32-bitIEEE format) float and returns a float with the property that: given zero,infinity or a positive normalised floating-point number then its result is thesmallest normalised floating-point number (or infinity if this is not possible)greater than its argument. You may assume functions f2irep and irep2fwhich map between a float and the same bit pattern held in a 32-bit integer.[6 marks](b) Briefly explain how this routine can be extended also to deal with negativefloating-point values, remembering that the result should always be greaterthan the argument. [2 marks](c) Define the notions of rounding error and truncation error of a floating-pointcomputation involving a parameter h that mathematically should tend to zero.[2 marks](d) Given a function f implementing a differentiable function that takes a floatingpoint argument and gives a floating-point result, a programmer implements afunctionf0(x) ?f(x + h) ? f(x ? h)2hto compute its derivative. Using a Taylor expansion or otherwise, estimatehow rounding and truncation errors depend on h. You may assume that allmathematical derivatives of f are within an order of magnitude of 1.0.[8 marks](e) Suggest a good value for h given a double-precision floating-point format thatrepresents approximately 15 significant decimal figures. Write program to find fourth average of each column elements?Write program to convert base-n number to base-m number in C++ language and it can show invalid number A hardware engineer stores a FIFO queue of bits in an int on a platform with32-bit ints and 8-bit chars using the following C++ class:class BitQueue {int valid_bits; //the number of valid bits held in queueint queue; //least significant bit is most recent bit addedpublic:BitQueue(): valid_bits(0),queue(0) {}void push(int val, int bsize);int pop(int bsize);int size();};(a) Write an implementation of BitQueue::size, which should return the numberof bits currently held in queue. [1 mark](b) Write an implementation of BitQueue::push, which places the bsize leastsignificant bits from val onto queue and updates valid bits. An exceptionshould be thrown in cases where data would otherwise be lost. [5 marks](c) Write an implementation of BitQueue::pop, which takes bsize bits fromqueue, provides them as the bsize least significant bits in the return value,and updates valid bits. An exception should be thrown when any requesteddata is unavailable. [4 marks](d) The hardware engineer has built a communication device together with a C++library function send to transmit data with the following declaration:void send(char);Use the BitQueue class to write a C++ definition for:void sendmsg(const char* msg);Each of the characters in msg should be encoded, in index order, using thefollowing binary codes: 'a'=0, 'b'=10, 'c'=1100, and 'd'=1101. All othercharacters should be ignored. Successive binary codes should be bit-packedtogether and the code 111 should be used to denote the end of the message.Chunks of 8-bits should be sent using the send function and any remaining bitsat the end of a message should be padded with zeros. For example, executingsendmsg("abcd") should call the send function twice, with the binary values01011001 followed by 10111100. [10 marks] Computer Science Engineering & Technology C++ Programming ECON 111 Share QuestionEmailCopy link Comments (0)

© Copyright 2020 Online Freelancers Network.com