SUBMIT HANDWRITTEN Further Modula-3 A Modula-3 library module is…

QuestionAnswered step-by-stepSUBMIT HANDWRITTEN Further Modula-3 A Modula-3 library module is…Image transcription textProblem 1: Array of Test Scores Write a C++ program that declares an array myList of 50 components of typeinteger. Initialize the array so that the first 25 components are equal to the square of the index variable and thelast 25 components equal to doubles the index variable. The program then calculates the sum an… Show moreSUBMIT HANDWRITTEN Further Modula-3 A Modula-3 library module is required to provide a buffered stream of characters between two threads, with appropriate synchronization. Buffer interface defining an opaque object type, T, with the following methods: init: taking an argument specifying the buffer size and returning a suitably initialized object put: inserting a single character into the buffer get: extracting a single character from the buffer  Sketch a correspondi  ng implementation giving (a) the concrete revelation of the types  (b) the three default methodsCompiler Construction Describe what is meant by a phrase structured grammar and a context free grammar. [3 marks] Describe an algorithm to calculate the set LT (P) of all terminal symbols that can start a string derived from the non-terminal P using one or more productions of a given context free grammar. Illustrate your answer by calculating LT sets for the following grammar: S -> U V V -> + U V | U -> X W W -> * X W | X -> ( S ) | n [6 marks] Describe an algorithm to calculate the set FOLLOW(P) of terminal and non-terminal symbols for a given context free grammar, where * FOLLOW(P) = { X | S => … P X … } i.e. all symbols that can follow P in a sentential form derived from the sentence symbol S. Illustrate your answer by calculating the FOLLOW sets for the grammar given above. [6 marks] Outline possible ways in which the space used by the Action and Goto matrices of an SLR(1) parser can be reduced. 9 Professional Practice and Ethics(a) The British Computer Society Code of Conduct has four sections. What kindof professional conduct does each section cover, and how does each of thesekinds of conduct benefifit the profession and its members? [8 marks](b) True or False questions:(i) A User can provide occasional use of the University computer system fora friend who is a temporary visitor.(ii) Circumstances that mitigate minor infractions of the rules promulgatedby the Information Technology Syndicate include, among other things,inebriation.(iii) Appropriate use of the Cambridge University Data Network (CUDN)means bona fifide academic activity plus a low level for private purposes.(iv) Small amounts of commercial activity are acceptable as long as the Useris acting in a private capacity.[4 marks](c) The IT industry is increasingly aware of its own environmental impact.Describe at least one environmental problem to which the industry contributesand how, as an IT professional, you can help to solve this problem. [4 marks](d) “Social engineering is a greater threat to computer security than computercracking software.” What is social engineering and what measures can betaken to guard against it? [2 marks](e) What is copyleft and how is it used to protect free, open-source, software?(a) Brieflfly explain the difffferences between combinational and sequential logic.[2 marks](b) With the aid of appropriate diagrams, brieflfly explain the operation of Mooreand Mealy fifinite state machines and highlight their difffferences. [6 marks](c) The state sequence for a binary counter is as follows: The counter is to be implemented using four synchronously clocked D-typeflflip-flflops.(i) Draw a state table for the counter, showing the required D inputs.[4 marks](ii) Find expressions for the D inputs, making use of unused states ifappropriate. [6 marks](iii) What problem could occur when the counter circuit is powered-up? Givetwo possible general methods for overcoming the problem. [2 marks]2CST.2008.2.32 Digital Electronics(a) With the aid of relevant diagrams, show the effffect on the output of acombinational logic circuit of a:(i) static hazard;(ii) dynamic hazard. [3 marks](b) Simplify the following expressions using Boolean algebra:(i) X = (A + B + A . B).(A + B). A . B(ii) Y = (A + B + A . B). C[4 marks](c) Given:F = A . B . C . D + A . C + B . C . D + B . C + A . C . D + A . B . C . D(i) Show using a Karnaugh map that F can be simplifified toF1 = A . B + A . B + A . C + B . C . D[2 marks](ii) Show that there are a total of four possible expressions for F. [3 marks](iii) Show how F1 can be implemented using NAND gates and draw the circuitdiagram. Assume that complemented input variables are available.[2 marks](iv) Show how the static 1 hazard in F1 can be eliminated using a Karnaughmap-based approach. [2 marks](v) Now implement F1 assuming that only 2-input NAND gates are available.[4 marks]3 (TURN OVER)CST.2008.2.4SECTION B3 Discrete MathematicsLet X and Y be sets. You are reminded that a relation from X to Y is a subset ofthe product X × Y .(a) Explain what it means for a relation f from X to Y to be a function, aninjection and a surjection from X to Y . [4 marks](b) A bijection from X to Y is defifined to be a function from X to Y which isboth an injection and a surjection. Prove that a function f from X to Y is abijection iffff it has an inverse function g, i.e. g is a function from Y to X suchthat g ◦ f = idX and f ◦ g = idY .[Remember to prove both the “if” and “only if” parts of the assertion.][12 marks](c) Describe, without proof, a bijection from P(X × Y ) to (X → P(Y )) and itsinverse. [4 marks]4CST.2008.2.54 Discrete MathematicsLet I be a non-empty subset of the natural numbers N = {1, 2, 3, · · ·}.The set S is defifined to be least subset of N such thatI ⊆ S, andif m, n ∈ S and m < n, then (n − m) ∈ S.Defifine h to be the least member of S. This question guides you through to a proofthat h coincides with the highest common factor of I, written hcf (I), and defifinedto be the natural number with the properties thathcf (I) divides n for every element n ∈ I, andif k is a natural number which divides n for every n ∈ I, then kdivides hcf (I).[Throughout this question you may assume elementary facts about division.](a) The set S may also be described as the least subset of N closed under certainrules. Describe the rules. Write down a principle of rule induction appropriatefor the set S. [4 marks](b) Show by rule induction that hcf (I) divides n for every n ∈ S. [3 marks](c) Let n ∈ S. Establish thatif p.h < n then (n − p.h) ∈ Sfor all non-negative integers p. [5 marks](d) Show that h divides n for every n ∈ S. [Hint: suppose otherwise and derive acontradiction.] [5 marks](e) Explain very brieflfly why the results of parts (b) and (d) imply that h = hcf (I).[3 marks]5 (TURN OVER)CST.2008.2.6SECTION C5 Probability(a) Suppose that X is a random variable whose value r is distributed Geometric(p).Write down the expression for the probability P(X = r). [3 marks](b) By using a suitable generating function or otherwise, show that the expectationE(X) = (1 − p)/p. [5 marks]The University Computing Service defifine a serious power outage as a power cut thatlasts for longer than their Uninterruptable Power Supply equipment can maintainpower. During the course of an academical year the number of serious power outagesis a random variable whose value is distributed Geometric(2/5). Accordingly, theprobability of having no serious power outages during the course of a year is 2/5.(c) The University is investigating a compensation scheme which would make nopayment over the year if the number of serious power outages were zero orone but which would pay the Computing Service £1000 for every such outage(including the fifirst) if the total number of serious power outages in a year weretwo or more. Determine the expected annual sum that the Computing Servicewould receive. [8 marks](d) To what value would the parameter of the Geometric Distribution have to bechanged (from 2/5) for the expected annual sum to be £750? [4 marks]6 Probability(a) Give a brief account of the Trinomial Distribution and include in yourexplanation an expression that is equivalent to n!r!(n−r)! prqn−r for the BinomialDistribution. [5 marks](b) An indicator light can be in one of three states: OFF, FLASHING and ON, withprobabilities 1/2, 2/5 and 1/10 respectively. A test panel has fifive such lightswhose states are mutually independent.(i) What is the probability that all fifive lights are OFF? [3 marks](ii) What is the probability that three lights are OFF, one light is FLASHINGand one light is ON? [3 marks](iii) What is the probability that three or more lights are OFF and at most oneis ON? [9 marks]All results must be expressed as fractions.6CST.2008.2.7SECTION D7 Software DesignSoftware systems often incorporate structural representations of the applicationdomain in which they operate. For example, a vehicle control system should beaware of the fact that the car has precisely four wheels. This kind of informationmust be captured, encoded and tested at each stage of the software design process.Using the number of wheels in a car as a simple example, describe relevant designactivities and products at each of the following phases of a software project:(a) inception; [4 marks](b) elaboration; [4 marks](c) construction; [4 marks](d) transition; [4 marks](e) system operation. [4 marks]8 Regular Languages and Finite Automata(a) Explain what is a context-free grammar and the language it generates.[4 marks](b) What does it mean for a context-free grammar to be regular? Given anydeterministic fifinite automaton M, describe a regular context-free grammarthat generates the language of strings accepted by M. [4 marks](c) Construct a non-deterministic fifinite automaton with ε-transitions whoselanguage of accepted strings is equal to the language over the alphabet {a, b, c}generated by the context-free grammar with non-terminals q0 and q1, whosestart symbol is q0 and whose productions are q0 → abq1, q1 → ε, q1 → q0 andq1 → abc. [4 marks](d) Is every language generated by a context-free grammar equal to theset of strings accepted by some non-deterministic fifinite automaton withε-transitions? Justify your answer. (Any standard results about regularlanguages you use should be carefully stated, but need not be proved.)[8 marks]7 (TURN OVER)CST.2008.2.89 Professional Practice and Ethics(a) The British Computer Society Code of Conduct has four sections. What kindof professional conduct does each section cover, and how does each of thesekinds of conduct benefifit the profession and its members? [8 marks](b) True or False questions:(i) A User can provide occasional use of the University computer system fora friend who is a temporary visitor.(ii) Circumstances that mitigate minor infractions of the rules promulgatedby the Information Technology Syndicate include, among other things,inebriation.(iii) Appropriate use of the Cambridge University Data Network (CUDN)means bona fifide academic activity plus a low level for private purposes.(iv) Small amounts of commercial activity are acceptable as long as the Useris acting in a private capacity.[4 marks](c) The IT industry is increasingly aware of its own environmental impact.Describe at least one environmental problem to which the industry contributesand how, as an IT professional, you can help to solve this problem. [4 marks](d) "Social engineering is a greater threat to computer security than computercracking software." What is social engineering and what measures can betaken to guard against it? [2 marks](e) What is copyleft and how is it used to protect free, open-source, software?(a) Write brief notes on polymorphism in ML, using lists and standard list functionssuch as @ (append) and map. [4 marks](b) Explain the meaning of the following declaration and describe the correspondingdata structure, including the role of polymorphism.datatype 'a se = Void | Unit of 'a | Join of 'a se * 'a se;[4 marks](c) Show that ML lists can be represented using this datatype by writing thefunctions encode_list of type 'a list -> ‘a se and decode_list of type’a se -> ‘a list, such that decode_list (encode_list xs) = xs for everylist xs. [3 marks](d) Consider the following function declaration:fun cute p Void = false| cute p (Unit x) = p x| cute p (Join(u,v)) = cute p u orelse cute p v;What does this function do, and what is its type? [4 marks](e) Consider the following expression:fn p => cute (cute p)What does it mean, and what is its type? Justify your answer carefully.[5 marks]2CST.2014.1.32Foundations of Computer Science(a) Write brief notes on the queue data structure and how it can be implementedeffiffifficiently in ML. In a precise sense, what is the cost of the main queueoperations? (It is not required to present ML code.) [6 marks](b) Run-length encoding is a way of compressing a list in which certain elementsare repeated many times in a row. For example, a list of the form [a, a, a, b, a, a]is encoded as [(3, a),(1, b),(2, a)]. Write a polymorphic function rl_encode toperform this encoding. What is the type of rl_encode? [6 marks](c) The simple task of testing whether two lists are equal can be generalised to allowa certain number of errors. We consider three forms of error:• element mismatch, as in [1,2,3] versus [1,9,3] or [1,2,3] versus [0,2,3]• left deletion, as in [1,3] versus [1,2,3] or [1,2] versus [1,2,3]• right deletion, as in [1,2,3] versus [1,3] or [1,2,3] versus [1,2]Write a function genEquals n xs ys that returns true if the two lists xs andys are equal with no more than n errors, and otherwise false. You may assumethat n is a non-negative integer. [8 marks]All ML code must be explained clearly and should be free of needless complexity.3 (TURN OVER)CST.2014.1.4SECTION B3Object-Oriented Programming(a) (i) Explain the purpose of access modififiers in OOP languages. [2 marks](ii) Copy and complete the table below to show the access restrictions for thefour access modififiers in Java. [2 marks]Access ModififierDefifining classClass in same packageSubclass in difffferent packageNon-subclass in difffferent package(b) A Java game designer wishes to store all the game preferences (e.g., player name,screen size, music volume, etc.) within a custom Preference class.(i) Assuming each preference is stored as a unique String key mapping toa String value, give a simple implementation of Preference that allowsfor effiffifficiently setting or updating preferences and retrieving previously setones. Your implementation should defifine an exception that is thrown whena preference key is requested but not present. [5 marks](ii) It is important that only one Preference object exists in a running game.Show how to apply access modififiers and the Singleton design pattern toensure this. Your implementation should lazily instantiate the object. Is itnecessary to make your class final or Cloneable? Explain your answer.[6 marks](c) The designer also implements other Singleton classes in the game and proposesto create a SingletonBase base class from which all such classes would inheritthe singleton behaviour. By providing example Java code, explain why this isnot viable. [5 marks]4CST.2014.1.54Object-Oriented ProgrammingA Lecturer wishes to create a program that lists his students sorted by the numberof practical assignments they have completed. The listing should be greatest numberof assignments fifirst, sub-sorted by name in lexicographical order (A to Z).A class StudentInfo stores the name and number of assignments completed for astudent. Amongst other methods, it contains a void setCompleted(int n) methodthat allows changes to the number of completed assignments.(a) Provide a defifinition of StudentInfo with an equals() method and a naturalordering that matches the given requirement. [9 marks](b) A TreeSet is used to maintain the StudentInfo objects in appropriate order.When setCompleted(…) is called on a StudentInfo object it is necessaryto remove the object from the set, change the value and then reinsert it toensure the correct ordering. This is to be automated by applying the Observerdesign pattern via classes UpdatableTreeSet and SubscribableStudentInfo.A partial defifinition of UpdatableTreeSet is provided below.public class UpdatableTreeSet extendsTreeSet {// To be called just before the StudentInfo object is updatedpublic void beforeUpdate(SubscribableStudentInfo s) {remove(s);Computer ScienceEngineering & TechnologyC++ ProgrammingCOMPTA comptaShare Question