How many times will the computer process the cout statement in the following code? for (int numTimes = 1; numTimes < 10; numTimes += 2) cout < < numTimes < < endl; //end for a. 0 b. 5 c. 6 d. 9
Write an assignment statement that updates an accumulator variable named totalPay by the value in the grossPay variable.
Write an assignment statement that updates a counter variable named quantity by 5.
Which of the following updates the total accumulator variable by the value in the sales variable? a. total = total + sales; b. total = sales + total; c. total += sales; d. All of the above
Write the C++ code to display the integers 15, 12, 9, 6, 3, and 0 on separate lines on the computer screen. Use the for statement and an int variable named num.
Modify the solution shown earlier in Figure 7-2. The solution should now keep track of the number of times Sahirahs laser beam missed the spider. After saying You are safe now. The spider is dead.,...
If necessary, create a new project named Intermediate25 Project and save it in the Cpp8\Chap13 folder. Also create a new source file named Intermediate25.cpp. Write a program that accepts a string of...
If necessary, create a new project named Introductory21 Project and save it in the Cpp8\Chap13 folder. Also create a new source file named Introductory21.cpp. Write a program that allows the user to...
Allenton Water Department wants a program that calculates a customers monthly water bill. The clerk will enter the current and previous meter readings. The program should calculate and display the...
Use the nums array to answer. The array was declared using the int nums[4] = {10, 5, 7, 2}; statement. The x and total variables are int variables and are initialized to 0. The avg variable is a...
In this exercise, you will create a program that allows the user to enter an employees gross pay amount as well as his or her filing status and number of withholding allowances. The program should...
A message that asks a user for input is a(n) ___________. a. Eomment b. Echo c. Prompt d. Declaration
Explain why each of the following names does or does not seem like a good variable name to you.
Your downloadable files for Chapter 2 include DEBUG02-01.txt, DEBUG02-02. txt, and DEBUG02-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with...
Your downloadable files for Chapter 2 include a file named DEBUG02-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart and then find and correct all the bugs.
Draw the hierarchy chart and design the logic for a program for Arnies Appliances. Design a program that prompts the user for a refrigerator model name and the interior height, width, and depth in...
In the following pseudocode, what percentage raise will an employee in Department 8 receive? if department < 5 then raise = SMALL_RAISE else if department < 14 then raise = MEDIUM_RAISE else if...
A programmers most important task before planning the logic of a program is to ____________. a. Decide which programming language to use b. Code the problem c. Train the users of the program d....
A program contains a seven-element array that holds the names of the days of the week. At the start of the program, you display the day names using a subscript named dayNum. You display the same...
Trainers at Toms Athletic Club are encouraged to enroll new members. Write an application that allows Tom to enter the names of each of his 25 trainers and the number of new members the trainer has...
a. Design an application in which the number of days for each month in the year is stored in an array. (For example, January has 31 days, February has 28, and so on. Assume that the year is not a...
Your downloadable files for Chapter 6 include a file named DEBUG06-04.jpg that contains a flowchart with syntax and/or logical errors. Examine the flowchart, and then find and correct all the bugs.
Which of the following is true regarding the data hierarchy? a. Fields contain records. b. Characters contain fields. c. Fields contain files. d. Files contain records.
Gimme Shelter Roofers maintains a file of past customers, including a customer number, name, address, date of job, and price of job. It also maintains a file of estimates given for jobs not yet...
Three-dimensional arrays _____. a. Are supported in many modern programming languages b. Always contain at least nine elements c. Are used only in object-oriented languages d. All of the above
Student records are stored in ID number order, but accessed by grade point average for a report. Grade point average order is a(n) _____ order. a. Imaginary b. Physical c. Logical d. Illogical
When you store a list of key fields paired with the storage address for the corresponding data record, you are creating _____. a. A directory b. A three-dimensional array c. A linked list d. An index
Assume you have written a method with the header void myMethod(num a, string b). Which of the following is a correct method call? a. MyMethod(12) b. MyMethod("Goodbye") c. MyMethod(12, "Hello") d. It...
Assume you have written a method with the header num yourMethod(string name, num code). The methods type is _____. a. Num b. String c. Num and string d. Void
Create the logic for a program that prompts a user for 20 numbers and stores them in an array. Pass the array to a method that calculates the arithmetic average of the numbers and returns the value...
Your downloadable files for Chapter 9 include DEBUG09-01.txt, DEBUG09-02.txt, and DEBUG09-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with two...
Design a class named TermPaper that holds an authors name, the subject of the paper, and an assigned letter grade. Include methods to set the values for each data field and display the values for...
A file named MAINTENANCE10-01.txt is included with your downloadable student files. Assume that this program is a working program in your organization and that it needs modifications as described in...
Employing inheritance reduces errors because _________. a. The new classes have access to fewer data fields b. The new classes have access to fewer methods c. You can copy and paste methods that you...
Which of the following is true? a. A classs methods usually are public. b. A classs data fields usually are public. c. Both of the above d. None of the above
Write a formal description of the following graph. 1 4 2 3 6
Let = {1, 2, 3, 4} and C = {w * | in w, the number of 1s equals the number of 2s, and the number of 3s equals the number of 4s}. Show that C is not context free.
Say that a language is prefix-closed if all prefixes of every string in the language are also in the language. Let C be an infinite, prefix-closed, context-free language. Show that C contains an...
Modify the proof of Theorem 3.16 to obtain Corollary 3.19, showing that a language is decidable iff some nondeterministic Turing machine decides it. (You may assume the following theorem about trees....
Use the construction in the proof of Theorem 1.47 to give the state diagrams of NFAs recognizing the concatenation of the languages described in a. Exercises 1.6g and 1.6i. b. Exercises 1.6b and...
Use the construction in the proof of Theorem 1.49 to give the state diagrams of NFAs recognizing the star of the languages described in a. Exercise 1.6b. b. Exercise 1.6j. c. Exercise 1.6m. Exercise...
Review the way that we define sets to be the same size inDefinition 4.12 (page 203). Show that is the same size is an equivalence relation.
Read the informal definition of the finite state transducer given in Exercise 1.24. Give a formal definition of this model, following the pattern in Definition 1.5. Assume that an FST has an input...
This exercise concerns TM M 2 , whose description and state diagram appear in Example 3.7. In each of the parts, give the sequence of configurations that M 2 enters when started on the indicated...
Show that EQ CFG is undecidable.
Read the informal definition of the finite state transducer given in Exercise 1.24. Give the state diagram of an FST with the following behavior. Its input and output alphabets are {0,1}. Its output...
Prove that there exists an undecidable subset of {1} * .
Show that P is closed under union, concatenation, and complement.
Show that NP is closed under union and concatenation.
In Theorem 3.21, we showed that a language is Turing-recognizable iff some enumerator enumerates it. Why didnt we use the following simpler algorithm for the forward direction of the proof? As...
Show that ALL DFA is in P.
Jacob Weinstein wants a program that displays his savings account balance at the end of the month, given the beginning balance, total deposits, and total withdrawals. a. Using the chart shown earlier...
Create a program that allows the user to enter the ages (in years) of five people. The program should display the average age. Use the for statement. Display the average age with one decimal place....
Karlton Learning wants a program that displays the amount of money a company owes for a seminar. The fee per person is based on the number of people the company registers, as shown in Figure 6-42....
Rewrite the code from Pencil and Paper Exercise 4 using the do while statement in the outer loop and the while statement in the nested loop.
Rewrite the code from Pencil and Paper Exercise 2 using the replace function.
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...
What is the output of the following code? b = 1; while(b < 4) { System.out.print(b + " "); b = b + 1; } a. 1 b. 1 2 3 c. 1 2 3 4 d. 1 1 1 1 1...
What does the following statement output? for(a = 0; a < 5; ++a) System.out.print(a + " "); a. 0 0 0 0 0 b. 0 1 2 3 4 c. 0 1 2 3 4 5 d. Nothing
What does the following statement output? for(b = 1; b > 3; ++b) System.out.print(b + " "); a. 1 1 1 b. 1 2 3 c. 1 2 3 4 d. Nothing
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)...
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...
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...
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...
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...
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...
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....
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. Many applications require pseudorandom number sequences that are not uniformly distributed. For example, a program that simulates the birth of...
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 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...
What terminates input into an integer?
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...
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...
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...
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...
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.
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.
Write regular expressions to capture the following. (a) Strings in C. These are delimited by double quotes ("), and may not contain newline characters. They may contain double-quote or backslash...
Build a regular expression that captures all nonempty sequences of letters other than file, for, and from. For notational convenience, you may assume the existence of a not operator that takes a set...
(a) Show the NFA that results from applying the construction of Figure 2.7 to the regular expression letter ( letter | digit )*. (b) Apply the transformation illustrated to create an equivalent DFA....
Build a nested-case-statements finite automaton that converts all letters in its input to lower case, except within Pascal-style comments and strings. A Pascal comment is delimited by { and }, or by...
Give a grammar that captures all levels of precedence for arithmetic expressions in C.
Write top-down and bottom-up grammars for the language consisting of all well-formed regular expressions. Arrange for all operators to be left associative. Give Kleene closure the highest precedence...
Suppose that the expression grammar in Example 2.8 were to be used in conjunction with a scanner that did not remove comments from the input, but rather returned them as tokens. How would the grammar...
Extend the grammar of Figure 2.25 to include if statements and while loops, along the lines suggested by the following examples: abs := n if n < 0 then abs := 0 - abs fi sum := 0 read count while...
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...
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.
The dangling else problem of Pascal was not shared by its predecessor Algol 60. To avoid ambiguity regarding which then is matched by an else, Al-gol 60 prohibited if statements immediately inside a...
Give two examples of reasonable semantic rules that cannot be checked at reasonable cost, either statically or by compiler-generated code at run time.
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...