New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
programming language pragmatics
C++ Plus Data Structures 6th Edition Nell Dale, Chip Weems, Tim Richards - Solutions
The OOP phrase “message passing” is equivalent to what C++ construct?
Define responsibility and distinguish between an action responsibility and a knowledge responsibility.
What are the three ways that two classes can relate to one another?
How can you avoid including a header file multiple times?
Indicate whether a stack would be a suitable data structure for each of the following applications.1. A program to evaluate arithmetic expressions according to the specific order of operators 2. A bank simulation of its teller operation to see how waiting times would be affected by adding another
Describe the accessing protocol of a stack at the abstract level.
Show what is written by the following segments of code, given that item1, item2, and item3 are int variables. 1. StackType stack; item1 = 1; item2 = 0; item3 = 4; stack.Push(item2); stack.Push(item1); stack.Push(item1 + item3); item2 = stack.Top(); stack.Pop(); stack.Push(item3*item3);
The stack is implemented as a class containing an array of items, a data member indicating the index of the last item put on the stack(top), and two Boolean data members, underFlow and overFlow. The stack items are characters and MAX_ITEM is 5. In each exercise, show the result of the operation on
The stack is implemented as a class containing an array of items, a data member indicating the index of the last item put on the stack(top), and two Boolean data members, underFlow and overFlow. The stack items are characters and MAX_ITEM is 5. In each exercise, show the result of the operation on
The stack is implemented as a class containing an array of items, a data member indicating the index of the last item put on the stack(top), and two Boolean data members, underFlow and overFlow. The stack items are characters and MAX_ITEM is 5. In each exercise, show the result of the operation on
The stack is implemented as a class containing an array of items, a data member indicating the index of the last item put on the stack(top), and two Boolean data members, underFlow and overFlow. The stack items are characters and MAX_ITEM is 5. In each exercise, show the result of the operation on
Write a segment of code to perform each of the following operations. You may call any of the member functions of StackType. The details of the stack type are encapsulated; you may use only the stack operations in the specification to perform the operations. (You may declare additional stack
(Multiple choice) The statement(setting the top element equal to the second element) in a client program of the stack class 1. would cause a syntax error at compile time.2. would cause a run-time error.3. would not be considered an error by the computer, but would violate the encapsulation of the
(Multiple choice) The statementsin the client program 1. would cause a syntax error at compile time.2. would cause a run-time error.3. would be legal, but would violate the encapsulation of the stack.4. would be perfectly legal and appropriate. stack.Push(item1 + 1); stack.Pop(item1 + 1); A
Given the following specification of the Top operation:ItemType TopAssume Top is not a stack operation and Pop returns the item removed. Write this function as client code, using operations from the nontemplate version of the StackType class. Remember—the client code has no access to the private
Two stacks of positive integers are needed, one containing elements with values less than or equal to 1,000 and the other containing elements with values larger than 1,000. The total number of elements in the small-value stack and the large-value stack combined is not more than 200 at any time, but
A stack of integer elements is implemented as an array. The index of the top element is kept in position 0 in the array, and the stack elements are stored in stack[1].. stack[stack[0]}.1. How does this implementation fare when assessed against the idea of an array as a homogeneous collection of
Using one or more stacks, write a code segment to read a string of characters and determine whether it forms a palindrome. A palindrome is a sequence of characters that reads the same both forward and backward—for example: ABLE WAS I ERE I SAW ELBA.The character ‘.’ ends the string. Write a
Write the body for a function that replaces each copy of an item in a stack with another item. Use the following specification. (This function is in the client program.)ReplaceItem(StackType& stack, ItemType oldItem, ItemType newItem)You may use any of the member functions of the nontemplate
In each plastic container of Pez candy, the colors are stored in random order. Your little brother likes only the yellow ones, so he painstakingly takes out all the candies, one by one, eats the yellow ones, and keeps the others in order, so that he can return them to the container in exactly the
The specifications for the Stack ADT have been changed. The class representing the stack must now check for overflow and underflow and set an error flag (a parameter) to true if either occurs.1. Rewrite the specifications incorporating this change.2. What new data members must you add to the
Implement the following specification for a client Boolean function that returns true if two stacks are identical and false otherwise.Boolean Identical(StackType stack1, StackType stack2)You may use any of the member functions of StackType, but you may not assume any knowledge of the stack’s
Is a count-controlled loop going from 1 through 5. At each iteration, the loop counter is either printed or put on a stack depending on the result of the Boolean function RanFun(). (The behavior of RanFun() is immaterial.) At the end of the loop, the items on the stack are popped and printed.
Is a count-controlled loop going from 1 through 5. At each iteration, the loop counter is either printed or put on a stack depending on the result of the Boolean function RanFun(). (The behavior of RanFun() is immaterial.) At the end of the loop, the items on the stack are popped and printed.
Describe the accessing protocol of a queue at the abstract level.
Show what is written by the following segments of code, given that item1, item2, and item3 are int variables.1.2. Que Type queue; item1 = 1; item2 = 0; item3 = 4; queue. Enqueue (item2); queue. Enqueue (item1); queue. Enqueue (item1 + item3); queue. Dequeue (item2); queue. Enqueue (item3*item3);
The specifications for the Queue ADT have been changed. The class representing the queue must now check for overflow and underflow and set an error flag (a parameter) to true if either occurs.1. Rewrite the specifications incorporating this change.2. What new data members must you add to the
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
The queue is implemented as a class containing an array of items, a data member indicating the index of the last item put on the queue(rear), a data member indicating the index of the location before the first item put on the queue (front), and two Boolean data members, underFlow and overFlow, as
Write a segment of code to perform each of the following operations. You may call any of the member functions of QueType. The details of the queue are encapsulated; you may use only the queue operations in the specification to perform the operations. (You may declare additional queue objects.)1.
(Multiple choice) The statement(setting one element equal to the next element) in a client program of the queue class 1. would cause a syntax error at compile time.2. would cause a run-time error.3. would not be considered an error by the computer, but would violate the encapsulation of the queue
(Multiple choice) The statementsin the client program 1. would cause a syntax error at compile time.2. would cause a run-time error.3. would be legal, but would violate the encapsulation of the queue.4. would be perfectly legal and appropriate. queue. Enqueue (item1 1); + queue. Dequeue (item1 + 1);
Given the following specification of a Front operation:1. Write this function as client code, using operations from the QueType class. (Remember—the client code has no access to the private members of the class.)2. Write this function as a new member function of the QueType class. ItemType Front
Write the body for a function that replaces each copy of an item in a queue with another item. Use the following specification. (This function is in the client program.)You may use any of the member functions of QueType, but you may not assume any knowledge of the queue’s implementation.
Indicate whether each of the following applications would be suitable for a queue.1. An ailing company wants to evaluate employee records so as to lay off some workers on the basis of service time(the most recently hired employees are laid off first).2. A program is to keep track of patients as
Implement the following specification for a Boolean function in the client program that returns true if two queues are identical and false otherwise.You may use any of the member functions of QueType, but you may not assume any knowledge of the queue’s implementation. Boolean Identical(QueType
Implement the following specification for an integer function in the client program that returns the number of items in a queue.The queue is unchanged. int GetLength(QueType queue) Function: Precondition: Postconditions: Determines the number of items in the queue. queue has been initialized. queue
One queue implementation discussed in this chapter dedicated an unused cell before the front of the queue to distinguish between a full queue and an empty queue. Write another queue implementation that keeps track of the length of the queue in a data member length.1. Write the class definition for
Write a queue application that determines if two files are the same.
Discuss the difference between the MakeEmpty operation in the specification and a class constructor.The following code segment (used for Exercises 41 and 42) is a count-controlled loop going from 1 through 5. At each iteration, the loop counter is either printed or put on a queue depending on the
The following output is possible using a queue: 1 2 3 4 5 1. True 2. False 3. Not enough information to determine
The following output is possible using a queue: 1 3 5 4 2 1. True 2. False 3. Not enough information to determine
Change the code for the program Balanced on page 283 so that the calls to Push, Pop, and Top are embedded within a try clause. The catch clause should print an appropriate error message and halt.
Define and implement a counted stack, which inherits from StackType.
Create UML diagrams for the ADTs implemented in this chapter.
Dummy nodes are used to simplify list processing by eliminating some “special case.” 1. What special case is eliminated by a header node in a linear linked list? 2. What special case is eliminated by a trailer node in a linear linked list? 3. Would dummy nodes be useful in implementing a linked
Implement the class constructor, destructor, and copy constructor for the circular linked list class.
If you were going to implement the FIFO Queue ADT as a circular linked list, with the external pointer accessing the “rear” node of the queue, which member functions would you need to change?
Write a member function PrintReverse that prints the elements on a list in reverse order. For instance, for the list X Y Z, list.PrintReverse() would output Z Y X. The list is implemented as a circular list, with listData pointing to the first element in the list. You may assume that the list is
Can you derive a DLList type from the SpecializedList class that has a member function called PutItem that inserts the item into its proper place in the list? If so, derive the class and implement the function. If not, explain why not.
If you were to rewrite the implementation of the Sorted List ADT using a doubly linked list, would you have to change the class definition? If so, how?
Outline the changes to the member functions that would be necessary to implement the Sorted List ADT as a doubly linked list.
Write a member function Copy of the Stack ADT, assuming that the stack named in the parameter list is copied into self.
Write a Copy member function of the Stack ADT, assuming that self is copied into the stack named in the parameter list.
Using the circular doubly linked list shown here, give the expression corresponding to each of the following descriptions:(For example, the expression for the info member of Node 1, referenced from pointer A, would be A->info.) 1. The info member of Node 1, referenced from pointer C 2. The info
The text edited by a line editor is represented by a doubly linked list of nodes, each of which contains an 80-column line of text(type LineType). There is one external pointer (type LineType*)to this list, which points to the “current” line in the text being edited. The list has a header node,
Of the three variations of linked lists (circular, with header and trailer nodes, and doubly linked), which would be most appropriate for each of the following applications? 1. You want to search a list for a key and return the keys of the two elements that come before it and the keys of the two
What is the Big-O measure for initializing the free list in the arraybased linked implementation? For the GetNode and FreeNode functions?
An array of records (nodes) is used to contain a doubly linked list, with the next and back members indicating the indexes of the linked nodes in each direction. 1. Show how the array would look after it was initialized to an empty state, with all the nodes linked into the freespace list. (The
Discuss the changes that would be necessary if more than one digit is stored per node in the LargeInt class.
Distinguish between static and dynamic binding of functions.
Rewrite SortedType (array-based) using templates.
Rewrite SortedType (linked) using templates.
Rewrite StackType (linked) using templates.
Rewrite QueType (linked) using templates.
Replace the ComparedTo function in an array-based UnsortedList by assuming that member functions of the ItemType class overload the relational operators.
Create the Unified Modeling Language (UML) diagrams for class LargeInt.
True or False? A doubly linked list has two pointers in each node.
True or False? A header node is a placeholder node at the beginning of a list, which is used to simplify list processing.
True or False? A trailer node is not syntactically different from the other nodes in the list.
True or False? A trailer node is not logically different from the other nodes in the list.
True or False? A trailer node is a placeholder node at the end of a list, which is used to simplify list processing.
True or False? A programmer, using inheritance to specialize a class X, needs access to the source code for X’s implementation.
True or False? In C++, a derived class’s constructor is executed after its base class constructor is executed.
True or False? For a C++ derived class to override an inherited member function, the base class is required to declare the function to be virtual.
Explain what is meant by the following: 1. base case 2. general (or recursive) case 3. run-time stack 4. binding time 5. tail recursion
True or false? If false, correct the statement. Recursive functions: 1. often have fewer local variables than the equivalent nonrecursive routines. 2. generally use while or for statements as their main control structure. 3. are possible only in languages with static storage allocation. 4. should
Describe the Three-Question Method of verifying recursive routines in relation to an inductive proof.
Which data structure would you most likely see in a nonrecursive implementation of a recursive algorithm?
Using the recursive function RevPrint as a model, write the recursive function PrintList, which traverses the elements in the list in forward order. Does one of these routines constitute a better use of recursion? If so, which one? int Puzzle(int base, int limit) { } if (base > limit) return -1;
Identify the following: 1. the base case or cases of the function Puzzle 2. the general case or cases of the function Puzzle
Show what would be written by the following calls to the recursive function Puzzle: 1. cout int Puzzle(int base, int limit) { } if (base > limit) return -1; else if (base == limit) return 1; else return base*Puzzle(base+1, limit);
Given the following function:1. Is there a constraint on the values that can be passed as a parameter for this function to answer the Smaller-Caller Question? 2. Is Func(7) a good call? If so, what is returned from the function? 3. Is Func(0) a good call? If so, what is returned from the function?
Put comments on the following routines to identify the base and general cases and explain what each routine does. 1. 2. int Power (int base, int exponent) { } if (exponent == 0) return 1; } else return base * Power (base, exponent- int Factorial (int number) { if (num > 0) return num * Factorial
1. Fill in the blanks to complete the following recursive function: 2. Which is the base case and which is the general case? 3. Show how you would call this function to sum all the elements in an array called numbers, which contains elements indexed from 0 to MAX_ITEMS - 1. 4. What run-time
You must assign the grades for a programming class. The class is studying recursion, and students have been given this simple assignment: Write a recursive function SumSquares that takes a pointer to a linked list of integer elements and returns the sum of the squares of the
The Fibonacci sequence is the series of integersSee the pattern? Each element in the series is the sum of the preceding two items. There is a recursive formula for calculating the nth number of the sequence [the 0th number if Fib(0) = 0]:1. Write a recursive version of the function Fibonacci. 2.
The following defines a function that calculates an approximation of the square root of a number, starting with an approximate answer (approx), within the specified tolerance (tol).1. What limitations must be made on the values of the parameters if this method is to work correctly? 2. Write a
A sequential search member function of SortedType has the following prototype: void SortedType::Search(int value, bool& found); 1. Write the function definition as a recursive search, assuming a linked list implementation. 2. Write the function definition as a recursive search, assuming an
We want to count the number of possible paths to move from row 1, column 1 to row N, column N in a two-dimensional grid. Steps are restricted to going up or to the right, but not diagonally. The illustration that follows shows three of many paths, if N = 10:1. The following function, NumPaths, is
Given the following function: 1. What problems come up in verifying this function? 2. How many recursive calls are made by the following initial calls? int Ulam(int num) { } if (num < 2) return 1; else if (num % 2 == 0) return Ulam(num / 2); else return Ulam (3 * num + 1);
Explain the relationship between dynamic storage allocation and recursion.
What do we mean by binding time, and what does it have to do with recursion?
Given the following values in list:Show the contents of the run-time stack during the execution of this call to BinarySearch: list .length .info 10 2 [0] 6 [1] 9 [2] 14 [3] 23 [4] 65 [5] 92 [6] 699 [8] 96 [7] 100 [9]
The parameter to the following two recursive routines is a pointer to a singly linked list of numbers, whose elements are unique (no duplicates) and unsorted. Each node in the list contains two members, info (a number) and next (a pointer to the next node). 1. Write a recursive value-returning
True or false? If false, correct the statement. A recursive solution should be used when: 1. computing time is critical. 2. the nonrecursive solution would be longer and more difficult to write. 3. computing space is critical. 4. your instructor says to use recursion.
Showing 300 - 400
of 817
1
2
3
4
5
6
7
8
9
Step by Step Answers