As part of the development team at MumbleTech.com, Janet has written a list manipulation library for C that contains, among other things, the code in Figure 3.16. (a) Accustomed to Java, new team...
Consider the following program in Scheme: What does this programprint? What would it print if Scheme used dynamic scoping and shallow binding? Dynamic scoping and deep binding? Explain your answers....
A CFG-based attribute evaluator capable of handling non-L-attributed attribute flow needs to take a parse tree as input. Explain how to build a parse tree automatically during a top-down or bottom-up...
As noted, C# has unusually sophisticated support for firstclass subroutines. Among other things, it allows delegates to be instantiated from anonymous nested methods, and gives local variables and...
For certain values of x, (0.1 + x) * 10.0 and 1.0 + (x * 10.0) can differ by as much as 25%, even when 0.1 and x are of the same magnitude. Verify this claim. (Warning: If youre using an x86...
Languages that employ a reference model of variables also tend to employ automatic garbage collection. Is this more than a coincidence? Explain.
In Section 6.1.2 (Orthogonality), we noted that C uses = for assignment and == for equality testing. The language designers state: Since assignment is about twice as frequent as equality testing in...
Consider the following expression in C: a/b > 0 && b/a > 0. What will be the result of evaluating this expression when a is zero? What will be the result when b is zero? Would it make sense to try to...
Suppose that we want to translate constant expressions into the postfix, or reverse Polish notation of logician Jan ukasiewicz. Postfix notation does not require parentheses. It appears in...
As noted in Section 6.4.2, languages vary in how they handle the situation in which the controlling expression in a case statement does not appear among the labels on the arms. C and Fortran 90 say...
Repeat the previous exercise using the underlying CFG of Figure 4.3. Figure 4.3 1. T TT.st := T.val E.val := TT.val 2. Ti + T T. + T TT2 TT2.st := TT1.st + T.val TT1.val := TT2.val %3D 3. TTi - ...
In Section 7.2.2 we introduced the notion of a universal reference type (void * in C) that refers to an object of unknown type. Using such references, implement a poor mans generic queue in C, as...
As noted in Figure 6.1, Fortran and Pascal give unary and binary minus the same level of precedence. Is this likely to lead to nonintuitive evaluations of certain expressions? Why or why not? Figure...
In Example 6.9 we described a common error in Pascal programs caused by the fact that and and or have precedence comparable to that of the arithmetic operators. Show how a similar problem can arise...
In Lisp, most of the arithmetic operators are defined to take two or more arguments, rather than strictly two. Thus (* 2 3 4 5) evaluates to 120, and (- 16 9 4) evaluates to 3. Show that parentheses...
Consider a language implementation in which we wish to catch every use of an uninitialized variable. In Section 6.1.3 we noted that for types in which every possible bit pattern represents a valid...
Write an attribute grammar, based on the following context-free grammar, that accumulates jump code for Boolean expressions (with short-circuiting) into a synthesized attribute code of condition, and...
(Difficult) Use call-with-current-continuation (call/cc) to implement the following structured nonlocal control transfers in Scheme. (This requires knowledge of material in Chapter 11.) You will...
Discuss the relative merits of classes and type extensions. Which do you prefer? Why?
In the spirit of Example 10.8, write a double-ended queue (deque) abstraction (pronounced deck), derived from a doubly linked list base class.
Suppose you are implementing an Ada compiler, and must support arithmetic on 32-bit fixed-point binary numbers with a programmer-specified number of fractional bits. Describe the code you would need...
When Sun Microsystems ported Berkeley Unix from the Digital VAX to the Motorola 680x0 in the early 1980s,many C programs stopped working, and had to be repaired. In effect, the 680x0 revealed certain...
Rewrite the code of Figure 7.3 in Ada, Java, or C#. Figure 7.3: template class queue { item items [max_items]; int next_free, next_full, num_items; public: queue () : next_free (0), next_full(0),...
Figure 7.3 passes integer max_items to the queue abstraction as a generic parameter. Write an alternative version of the code that makes max_items a parameter to the queue constructor instead. What...
Using the C# indexer mechanism, create a hash table class that can be indexed like an array. (In effect, create a simple version of the System.Collections.Hashtable container class.) Alternatively,...
Explain the meaning of the following C declarations: double *a[n]; double (*b)[n]; double (*c[n])(); double (*d())[n];
In Section 9.3.1 we noted that Ada 83 does not permit subroutines to be passed as parameters, but that some of the same effect can be achieved with generics. Suppose we want to apply a function to...
In Section 8.2.3 we discussed how to differentiate between the constant and variable portions of an array reference, in order to efficiently access the subparts of array and record objects. An...
Write an LL(1) parser generator in purely functional Scheme. If you consult Figure 2.24, remember that you will need to use tail recursion in place of iteration. Assume that the input CFG consists of...
Explain how to obtain the effect of Fortran 90s allocate statement for one-dimensional arrays using pointers in C. You will probably find that your solution does not generalize to multidimensional...
Pointers and recursive type definitions complicate the algorithm for determining structural equivalence of types. Consider, for example, the following definitions: type A = record x : pointer to B y...
Suppose A is a 1010 array of (4-byte) integers, indexed from [0][0] through [9][9]. Suppose further that the address of A is currently in register r1, the value of integer i is currently in register...
Suppose we are compiling for a machine with 1-byte characters, 2-byte shorts, 4-byte integers, and 8-byte reals, and with alignment rules that require the address of every primitive data element to...
Write the equivalent of Figure 6.5 in C# or Ruby. Write a second version that performs an in-order enumeration, rather than preorder. Figure 6.5: class BinTree: def -_init_ (self): # constructor...
Modify the solution to the postfix expression evaluation problem so that it checks for the validity of the expression that is entered by the user. Issue an appropriate error message when an erroneous...
Write an algorithm for the add method that will add at the end of the list instead of at the beginning. What is the time complexity of this algorithm?
Modify the maze problem in this chapter so that it can start from a user defined starting position (other than 0, 0) and search for a user-defined ending point (other than row-1, column-1).
In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozit followed by one or more Whatzits. A Whoozit is the character x followed by zero or more ys. A Whatzit is a q...
Write a recursive method that returns the value of N! (N factorial) using the definition given in this chapter. Explain why you would not normally use recursion to solve this problem.
There is a variation of the bubble sort algorithm called a gap sort that, rather than comparing neighboring elements each time through the list, compares elements that are i positions apart, where i...
What is the time complexity of a radix sort?
Calculate the time complexity of the find method.
Write some Java statements that use the String methods indexOf and substring to find the first word in a string. We define word to be a string of characters that does not include whitespace. For...
What changes to the ChangeMaker program in Listing 2.3 are necessary if it also accepts coins for one dollar and half a dollar? Listing 2.3 import java.util.Scanner; public class ChangeMaker { public...
Consider the following fragment of code: if (x > 5) System.out.println("A"); else if (x < 10) System.out.println("B"); else System.out.println("C"); What is displayed if x is a. 4; b. 5; c. 6; d. 9;...
What is the value of each of the following boolean expressions if x is 5,y is 10, and z is 15? a. (x < 5 && y > x) b. (x < 5 || y > x) c. (x > 3 || y < 10 && z == 15) d. (! (x > 3) && x!= z || x + y...
Every profession uses computers today. Use aWeb browser and a search engine like Google to find sites that relate your field of study with computer science or computing or computation. For example,...
You are running a bingo game where you want to tweet the winner of each round of the game.You want to announce the name of who won, and how much they won in dollars. Make a function that takes those...
Create a function like the pyramid function that does the upside-down version. Your function invertedPyramid should also take an input character and print an inverted pyramid.
You have written an essay for school, and it has to be at least five pages long. But your essay is only 4.5 pages long!You decide to use your new Python skills to make your essay longer by spacing...
Write a function to blend two pictures, starting with the top third of the first picture and then blend the two together in the middle third and then show the last third of the second picture. This...
One of the four functions below generated this picture. Which one is it? A. B. C. D. def flip1(picture): allpixels = getPixels(picture) In = len(allpixels)-1 address = In for index in range (0,1n/2):...
Write a function to draw a simple face with eyes and a mouth. on a picture.
Write a general crop function that takes a source picture, the start X value, the start Y value, the end X value, and the end Y value. Create and return the new picture and copy just the specified...
Create a CartoonPanel class that takes an array of Pictures and displays the pictures from left to right. It should also have a title and author, and display the title at the top left edge and the...
One of the below programs that when called like this (with the underscore representing a digit from 1 to 4) generates this output: >>> mixem_("we hold these truths") 'w.e. .h.o.l.d. .t.h.ese truths'...
Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows: :mmZ\dxZmx]Zpgy The message is...
Write a new class TruncatedDollarFormat that is the same as the class DollarFormat from Listing 6.14, except that it truncates rather than rounds to obtain two digits after the decimal point. When...
Write a JavaFx application that displays a series of pictures of a person with arms, legs, and of course a head. Use a happy face for the head. Use ovals for the body, arms, and legs. Draw a sequence...
Write a program that plays a simplified dice version of blackjack. Instead of selecting from a deck of cards a 14-sided die is rolled to represent a card. The rules of the game for one round, as...
Write a program that produces the following figure (which vaguely resembles the Seattle Space Needle) as its output using nested for loops. Use a class constant to make it possible to change the size...
Write a Java program called Lanterns that generates the following output. Use static methods to show structure and eliminate redundancy in your solution. ** ***** **** ***** ********* ***** **...
Write a recursive method that will count the number of vowels in a string. Each time you make a recursive call, use the String method substring to construct a new string consisting of the second...
Add a method bubbleSort to the class ArraySorter, as given in Listing 7.10, that performs a bubble sort of an array. The bubble sort algorithm examines all adjacent pairs of elements in the array...
Add a method insertionSort to the class ArraySorter, as given in Listing 7.10, that performs an insertion sort of an array. To simplify this project, our insertion sort algorithm will use an...
The class TimeBook in Listing 7.14 is not really finished. Complete the definition of this class in the way described in the text. In particular, be sure to add a default constructor, as well as set...
Sudoku is a popular logic puzzle that uses a 9 by 9 array of squares that are organized into 3 by 3 subarrays. The puzzle solver must fill in the squares with the digits 1 to 9 such that no digit is...
Write a program that shows the total number of presents that the person in the song The Twelve Days of Christmas received on each day, as indicated in Table 3.5. Table 3.5 Twelve Days of Christmas
Write a piece of code that prints an array of integers in reverse order, in the same format as the print method from Section 7.2. Consider putting your code into a method called printBackwards that...
Students are often asked to write term papers containing a certain number of words. Counting words in a long paper is a tedious task, but the computer can help. Write a program that counts the number...
Write a constructor for the UndergraduateStudent class that accepts a name as a parameter and initializes the UnderGraduateStudent s state with that name, an age value of 18, and a year value of 0.
Write a program that produces the following figure (which vaguely resembles a textbook) as its output using nested for loops. Use a class constant to make it possible to change the size of the figure...
Write a program that produces as output the words of The Twelve Days of Christmas. (Static methods simplify this task.) Here are the first two verses and the last verse of the song: On the first day...
Write a complete Java program called WellFormed that prints the following output:
For this project, we will create a data structure known as a queue. A queue can be thought of as a line. Items are added at the end of the line and are taken from the front of the line. You will...
Why is recursion an effective way to implement a backtracking algorithm?
What characteristic does Ruby share with Smalltalk?
Write a JavaFX application that uses a text field to get the name of a file, reads the file byte by byte, and displays the bytes as characters. (Exercise 15 describes how to convert a byte value to a...
Write the state of the elements of each of the following arrays after each pass of the outermost loop of the selection sort algorithm has occurred (after each element is selected and moved into...
The following program contains 7 mistakes! What are they? What output is produced for each of the following calls? a. IfElseMystery1(3, 20); b. IfElseMystery1(4, 5); c. IfElseMystery1(5, 5); d....
Modify your program from the previous exercise to draw the figure by a method called drawFigure . The method should accept three parameters: the Graphics g of the DrawingPanel on which to draw, and a...
An element can be inserted at the beginning, middle, or end of an array list. Which of the three insertion points is the most computationally expensive, and why? Which is the most expensive location...
Write a program that reads a file containing data about the changing popularity of various baby names over time and displays the data about a particular name. Each line of the file stores a name...
Define ordinal, enumeration, and subrange types.
Write a class called Date that represents a date consisting of a year, month, and day. A Date object should have the following methods: public Date(int year, int month, int day) Constructs a new Date...
Write a class named Dodecagon whose objects represent regular dodecagons (12-sided polygons). Your class should implement the Shape interface defined in this chapter. A Dodecagon object is defined by...
Analyze and write a comparison of using C++ pointers and Java reference variables to refer to fixed heap- dynamic variables. Use safety and convenience as the primary considerations in the comparison.
Describe three specific programming situations that require a posttest loop.
Suppose you want to write a method that prints a heading on a new output page, along with a page number that is 1 in the first activation and that increases by 1 with each subsequent activation. Can...
The Sierpinski carpet is a fractal that is defined as follows: The construction of the Sierpinski carpet begins with a square. The square is cut into nine congruent subsquares in a 3-by-3 grid, with...
Write a method called reverse that accepts a map from strings to strings as a parameter and returns a new map that is the reverse of the original. The reverse of a map is a new map that uses the...
To which complexity class does the following algorithm belong? public static void mystery2 (int [] list) { for (int i = 0; i < list.length / 2; i++) { int j = list.length 1 i; int temp = list[i];...
To which complexity class does the following algorithm belong? public static void mystery4 (List list) { for (int i = 0; i < list.size () 1; i += 2) { %3D String first list.get (i); !! list.set (i,...
How can the parent version of an inherited method that is overridden in a subclass be called in that subclass in C#?
A URL is a type of _________. a. Web page b. URI c. Link d. Network
How would the results of the following two statements differ?
What type of error occurs when the interpreter fails to recognize code? a. Debugging b. Syntax c. Run-time d. Logic
Which API provides access to data from a devices gyroscope and accelerometer? a. Geolocation API b. Battery Status API c. Device Orientation API d. WebRTC API
Consider the following C program: What is the value of x after the assignment statement in main, assuming a. Operands are evaluated left to right. b. Operands are evaluated right to left. int fun...
What number is displayed by this program? Set Number1 = 4 Set Number1 = Number1 + 1 Set Number2 = 3 Set Number2 = Number1 * Number2 Write Number2