Ultimate Engineering Study Guide - Questions & Answers

2. Suppose we have the following C++ classes: Class Plant is the parent class for different kinds of living plants. It has the following members (destructors (if any) are excluded from this list): A private data field of type double called energy Capacity. A public constructor that takes as input argument a double and initializes energy Capacity to this data field. The default value for this argument is 100. This constructor does not allow automatic type conversion from a double to a Plant. A public get function called get Energy Capacity() that returns a Plant's energy Capacity. This function does not do dynamic dispatching. A public function called daily Energy Consumption () that takes no parameters and returns a double. Class Plant does not supply an implementation of this function; its implementations is to be supplied in subclasses.Class FloweringPlant is a subtype of Plant. It overrides function daily Energy Consumption (). Flowering Plant has a constructor that takes a double as its argument and calls Plant's constructor with this value. Class Food Producing Plant is a subtype of Plant. It overrides function daily Energy Consumption (). Food Producing Plant has a constructor that takes a double as its argument and calls Plant's constructor with this value. Class PeachTree is both a direct subtype of Flowering Plant and Food Producing Plant. It has a constructor that takes a double and calls its appropriate parent class constructors to set its energy Capacity to this double. It also overrides function daily Energy Consumption ().
QUESTION 1: Search --A* Variants [20 Marks]Queuing variants: Consider the following variants of the A tree search algorithm. In all cases, g is the cumulative path cost of a node n, h is a lower bound on the shortest path to a goal state, and no is the parent of n. Assume all costs are positive.i. Standard Aii. A*, but we apply the goal test before enqueuing nodes rather than after dequeuingiii. A*, but prioritize n by g (n) only (ignoring h (n))iv. A*, but prioritize n by h (n) only (ignoring g (n))v. A*, but prioritize n by g (n) + h (no)vi. A*, but prioritize n by g (no) + h (n)a) Which of the above variants are complete, assuming all heuristics are admissible?b) Which of the above variants are optimal, again assuming all heuristics are admissible? c) Assume you are required to preserve optimality. In response to n's insertion, can you ever delete any nodes m currently on the queue? If yes, state a general condition under which nodes m can be discarded, if not, state why not. Your answer should involve various path quantities (g, h, k) for both the newly inserted node n and another node m on the queue.d) In the satisficing case, in response to n's insertion, can you ever delete any nodes m currently on the queue? If yes, state a general condition, if not, state why not.Your answer involves various path quantities (g, h, k) for both the newly inserted node n and another nodes m on the queue.e) Is A with an e-admissible heuristic complete? Briefly explain.f) Assuming we utilize an e-admissible heuristic in standard A* search, how much worse than the optimal solution can we get? l.e. c is the optimal cost for a search problem, what is the worst cost solution an e-admissible heuristic would yield? Justify your answer.g) Suggest a modification to the A algorithm which will guaranteed to yield an optimal solution using an e-admissible heuristic with fixed, known e. Justify your answer.
Exercise 1:Computer Addresses Management Numeric addresses for computers on the wide area network Internet are composed of four parts separated by periods, of the form xx.yy.zz.mm, where xx, yy, zz, and mm are positive integers. Locally computers are usually known by a nickname as well.You are designing a program to process a list of internet addresses, identifying all pairs of computers from the same locality (ie, with matching xx and yy component).(a) Create a C structure called InternetAddress with fields for the four integers and a fifth component to store an associated nickname.(b) Define a function, ExtractinternetAddress, that extracts a list of any number of addresses and nicknames from a data file whose name is provide as argument, and returns a dynamically allocated array that holds the indicated number of internet addresses (represented in InternetAddress) objects) retrieved from the file. The first line of the file should be the number of addresses that follow. Here is a sample data set:113.22.3.44. plato555.66.7.88 gauss 111.22.5.88. mars234.45.44.88. ubuntu(c) Define a function CommonLocality that receives as arguments the array constructed in a) and the number of internet addresses, and displays a list of messages identifying each pair of computers from the same locality. In the messages. the computers should be identified by their nicknames. Here is a sample message: Machines plato and mars are on the same local network.(d) Define the main function that prompts the user to enter the name (computers,txt) of the file containing the Computer addresses as described in (b) and displays a list of messages identifying all pair of computers from the same locality.
Consider the following class definition:class ArithmeticSequence:def _init_(self, common_difference = 1, max_value = 5): self.max_value = max_valueself.common_difference-common_differencedef _iter_(self):return ArithmeticIterator(self.common_difference, self.max_value)The ArithmeticSequence class provides a list of numbers, starting at 1, in an arithmetic sequence. In an Arithmetic Sequence the difference between one term and the next is a constant. Forexample, the following code fragment:sequence = ArithmeticSequence (3, 10)for num in sequence:print(num, end =produces:147 10The above sequence has a difference of 3 between each number. The initial number is 1 and the last number is 10. The above example contains a for loop to iterate through the iterable object (i.e. ArithmeticSequence object) and prints numbers from the sequence. Define the ArithmeticIterator class so that the for-loop above works correctly. The ArithmeticIterator class containsthe following: An integer data field named common_difference that defines the common difference between two numbers. An integer data field named current that defines the current value. The initial value is 1. An integer data field named max_value that defines the maximum value of the sequence.A constructor/initializer that that takes two integers as parameters and creates an iterator object.The_next__(self) method which returns the next element in the sequence. If there are no more elements (in other words, if the traversal has finished) then a StopIteration exception israised.Note: you can assume that the ArithmeticSequence class is given.