In this exercise, you will modify the tip program shown earlier in Figure 7-31. Follow the instructions for starting C++ and viewing the ModifyThis16.cpp file, which is contained in either the...
Create a JFrame that holds five buttons with the names of five different fonts. Include a sixth button that the user can click to make a font larger or smaller. Display a demonstration JLabel using...
Which of the following is true in a standard menu application? a. A JMenuItem holds a JMenu. b. A JMenuItem holds a JMenuBar. c. A JMenuBar holds a JMenu. d. A JMenu holds a JMenuBar
You developed an interactive GUI application for Carlys Catering. Now, design a JPanel that uses graphics to display a logo for the company, and modify the GUI application to include it. Save the...
a. Create aMine Field game in which the user attempts to click 10 panels of a grid before hitting the bomb. Set up a JFrame using BorderLayout, use the NORTH region for a congratulatory message, and...
Write an application that extends JPanel and uses the Graphics2D environment to create a GeneralPath object. Use the GeneralPath object to create the outline of your favorite state. Display the...
Suppose that you have created a program with only the following variables. int a = 5; int b = 6; Suppose that you also have a method with the following header: public static void mathMethod(int a)...
Suppose that you want to implement a bag class to hold non-negative integers, and you know that the biggest number in the bag will never be more than a few thousand. One approach for implementing...
What is meant by the term prompt?
Which operator do you use to read into a variable?
This project is a continuation of the previous project. For a quadratic expression such as ax 2 + bx + c, a real root is any double number x such that ax 2 + bx + c = 0. For example, the quadratic...
Implement the previous project with the following modification: All of the input numbers to the Statistician are required to be integers in the range from 0 to 100. This modification means that its...
Specify, design, and implement a class that can be used to simulate a lunar lander, which is a small spaceship that transports astronauts from lunar orbit to the surface of the moon. When a lunar...
Revise the Statistician with median (Programming Project 15 on page 172) so that it stores the input numbers on a doubly linked list using the doubly linked node class from the previous project....
Add a new method to the random number class of the previous project. The new method generates the next pseudorandom number but does not return the number directly. Instead, the method returns this...
Reimplement the bag class from Figure 4.17 so that the items of the bag are stored with a new technique. Heres the idea: Each node of the noefw linked list contains two integers. The first integer is...
This project is a continuation of the previous project. Many applications require pseudorandom number sequences that are not uniformly distributed. For example, a program that simulates the birth of...
Write a program that evaluates an arithmetic expression in infix notation, without full parentheses. Use the following algorithm: There are two stacks: a numbers stack and an operators stack. When a...
What terminates input into an integer?
This project requires a little understanding of velocity and gravity, but dont let that scare you away! Its actually an easy project. The assignment is to write a class in which each object...
Write a program that converts spelled-out numbers such as zero and two into digits, such as 0 and 2. When the user inputs a number, the program should print out the corresponding digit. Do it for the...
In this project, you will design and implement a class called Towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection...
Give five examples of legal names that you shouldnt use because they are likely to cause confusion.
Define a rule to help decide if a conversion from one type to another is safe or unsafe.
Another way to store a collection of items is called a keyed bag. In this type of bag, whenever an item is added, the programmer using the bag also provides an integer called the key. Each item added...
In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise, you will write a similar program to evaluate boolean expressions. Rather than arithmetic...
Do exercise 6, but with three string values. So, if the user enters the values Steinbeck, Hemingway, Fitzgerald, the output should be Fitzgerald, Hemingway, Steinbeck.
Starting with the regular expressions for integer and decimal, construct an equivalent NFA, the set-of-subsets DFA, and the minimal equivalent DFA. Be sure to keep separate the final states for the...
Give three concrete examples drawn from programming languages with which you are familiar in which a variable is live but not in scope.
Consider the design of a Fortran 77 compiler that uses static allocation for the local variables of subroutines. Expanding on the solution to the previous question, describe an algorithm to minimize...
Consider the following LL(1) grammar for a simplified subset of Lisp: P E $$ E atom E ( E Es ) Es E Es (a) What is FIRST(Es)? FOLLOW(E)? PREDICT(Es )? (b) Give a parse tree for the string...
Write a simple program in Scheme that displays three different behaviors, depending on whether we use let, let*, or letrec to declare a given set of names.
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...
Give two examples of reasonable semantic rules that cannot be checked at reasonable cost, either statically or by compiler-generated code at run time.
Rewrite Figures 3.6 and 3.7 in C. You will need to use separate compilation for name hiding. Figures 3.6 Figures 3.7 #include namespace rand_mod { unsigned int seed = time (0); // initialize from...
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....
Consider the following pseudocode: x : integer global procedure set x(n : integer) x := n procedure print x() write integer(x) procedure foo(S, P : function; n : integer) x : integer := 5 if n in...
One potential criticism of the obvious solution to the previous problem is that the values in internal nodes of the parse tree do not reflect the value, in context, of the fringe below them. Create...
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...
We noted in Section 6.1.1 that most binary arithmetic operators are left associative in most programming languages. In Section 6.1.4, however, we also noted that most compilers are free to evaluate...
Translate the following expression into postfix and prefix notation: [b + sqrt(b b 4 a c)]/(2 a) Do you need a special symbol for unary negation?
Describe a plausible scenario in which a programmer might wish to avoid short-circuit evaluation of a Boolean expression.
Write a C++ preorder iterator to supply tree nodes to the loop in Example 6.69. You will need to know (or learn) how to use pointers, references, inner classes, and operator overloading in C++. For...
In your favorite language with generics, write code for simple versions of the following abstractions: (a) A stack, implemented as a linked list (b) A priority queue, implemented as a skip list or a...
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...
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 Example 7.53 we mentioned three ways to make the need for comparisons more explicit when defining a generic sort routine in C++: make the comparison routine a method of the generic parameter class...
Revise the algorithm of Figure 6.6 so that it performs an in-order enumeration, rather than preorder. Figure 6.6: class BinTree implements Iterable { BinTree left; BinTree right; T val; // other...
Use iterators to construct a program that outputs (in some order) all structurally distinct binary trees of n nodes. Two trees are considered structurally distinct if they have different numbers of...
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...
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...
Consider the array indexing calculation of Example 8.25. Suppose that i, j, and k are already loaded into registers, and that As elements are integers, allocated contiguously in memory on a 32-bit...
Example 8.24, which considered the layout of a two-dimensional array of characters, counted only the space devoted to characters and pointers. This is appropriate if the space is allocated...
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...
Explain how to extend Figure 8.7 to accommodate subroutine arguments that are passed by value, but whose shape is not known until the subroutine is called at run time. sp- Ada: -- procedure foo (size...
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...
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):...
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'...
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...
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...
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 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:
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...
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...
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.
Why is recursion an effective way to implement a backtracking algorithm?
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...
What characteristic does Ruby share with Smalltalk?
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....
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...
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...
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...
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 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...