EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 6E
Program Plan Intro
Abstract Base Class:
- At least a single pure virtual function is present in an Abstract class. For sub classes interface is provided by Abstract class.
- The instantiation of Abstract class is not possible whereas refrences and pointers could be created.
- Abstract class contains a pure virtual function along with normal functions and variables
- The purpose of Abstract class is to for up cast. So that its interface could be used by derived class.
- The implementation of all of pure virtual functions is necessary for all classes that inherit an Abstract class. Otherwise they would also become Abstract.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You can use inheritance or composition to design the data structures for stacks and queues. Discuss the pros and cons of these two approaches.
Consider the data structure stack's implementation. If we make an integer stack, the push and pop actions will only work with integer items. When we construct a character stack, the push and pop operations will only handle components of the character type. However, making so many copies of the implementation makes the code difficult to maintain. As a result, the genericity principle is applied, and a template class may be constructed. At runtime, this container class can handle any data type element. Explain the significance of modeling in object oriented programming using the same comparison.
Modify the C++ class for the abstract stack type shown belowto use a linked list representation and test it with the same code thatappears in this chapter.
#include <iostream.h>class Stack {private: //** These members are visible only to other//** members and friends (see Section 11.6.4)int *stackPtr;int maxLen;int topSub;public: //** These members are visible to clientsStack() { //** A constructorstackPtr = new int [100];maxLen = 99;topSub = -1;}~Stack() {delete [] stackPtr;}; //** A destructorvoid push(int number) {if (topSub == maxLen)cerr << "Error in push--stack is full\n";else stackPtr[++topSub] = number;}void pop() {if (empty())cerr << "Error in pop--stack is empty\n";else topSub--;}int top() {if (empty())cerr << "Error in top--stack is empty\n";elsereturn (stackPtr[topSub]);}int empty() {return (topSub == -1);}
}
Chapter 4 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
Knowledge Booster
Similar questions
- Write an abstract data type for a queue whose elements include both a 20-character string and an integer priority. This queue must have the following methods: enqueue, which takes a string and an integer as parameters; dequeue, which returns the string from the queue that has the highest priority; and empty. The queue is not to be maintained in priority order of its elements, so the dequeue operation must always search the whole queue.arrow_forwardUsing an example of a component that implements an abstract data type such as a stack or a list, show why it is usually necessary to extend and adapt components for reuse.arrow_forwardConsider the implementation of the data structure stack. If we create an integer stack then the push and pop operations will handle only integer elements. If we create a character stack then the push and pop operations will handle only character type elements. But creating so many copies of implementation makes the code complex to maintain. Hence the principle of genericity is used and a template class can be created. This container class can handle any data type element at run time.In the same contrast explain the importance of modeling in object oriented programming. Plagiarized answer will be given thumbsdown.arrow_forward
- A deque (pronounced "deck") is an abstract data type that combines what a stack can do and what a queue can do. Thus, users are allowed to add items to either end of a deque and inspect/remove them from either end. Thus, a deque can act as stack or queue. Given the following ADT specification, implement the behavior of deque based on a circular array as the one discussed for an array-based implementation of the queue. Template<class T> Class Deque { Public: int size(); Boolean isEmpty(); // similar to push Void insertFirst(T e); // similar to enqueue Void insertLast(T e); // similar to dequeue T removeFirst(); // similar to pop T removeLast(); // returns the first element of deque without removing it T first(); // returns the last of deque without removing it T last(); }arrow_forwardWrite an abstract data type for queues whose elements store 10-characternames. The queue elements must be dynamically allocated from theheap. Queue operations are enqueue, dequeue, and empty. Use eitherC++, Java, C#, or Rubyarrow_forwardCan you please help me with these three questions? 1) A designator used to give a non-member function in C++ access to the private data members of a class, even though the function is not technically part of the class, is called ______ 2) The stack operation that is required when using an array implementation, but is not required when using a linked list implementation, is ___ . isFull() push() pop() peek() 3) A mechanism in C++ that interrupts program execution when errors occur and signals the rest of the program that something unexpected has happened is a(n) ___ . exception logic error catch phrase interceptionarrow_forward
- (In java please)A LinkNode structure or class which will have two attributes - a data attribute, and a pointer attribute to the next node. The data attribute of the LinkNode should be a reference/pointer of the Currency class of Lab 2. Do not make it an inner class or member structure to the SinglyLinkedList class of #2 below. A SinglyLinkedList class which will be composed of three attributes - a count attribute, a LinkNode pointer/reference attribute named as and pointing to the start of the list and a LinkNode pointer/reference attribute named as and pointing to the end of the list. Since this is a class, make sure all these attributes are private. The class and attribute names for the node and linked list are the words in bold in #1 and #2. For the Linked List, implement the following linked-list behaviors as explained in class - getters/setters/constructors/destructors, as needed, for the attributes of the class. createList method in addition to the constructor - this is optional…arrow_forwardImplement a program in C++ that has the following three parts and each does the following: Implements in C++ a Stack ADT (save the file as StackADT.h) Implements all the necessary methods (behavior) of a Stack (save the file as StackADT.cpp) Implements in C++ a main function (the client or application program) that creates and uses Stack objects (save the file as StackMain.cpp). This main function should be able to do the following: It should be able to read a given text file as input, It should be able to get each input value from the input file (one word at a time) and store it (push) on the Stack object until it stores all the words from the input file. It should be able to retrieve an item from the stack and display it on the screen, and then delete (pop) that item from the stack, and repeat until it retrieves all the items from the stack object. NOTE: Please make sure you debug, run, test and see the program working correctly before submitting. Submit the files…arrow_forwardWrite an abstract data type for a queue whose elements can be anyprimitive type. Use Java 5.0, C# 2005, or C++.arrow_forward
- Complete the implementation of the class LinkedSortedList, and write a driver program to fully test it. (Ch. 12, Programming Problems 1, pg. 392 of Data Abstraction and Problem Solving with C++ (7th Edition) ) Name the program sortedlist.cpp. Make sure the following requirements are met. Program must compile and run. Must use the Sorted List ADT SortedListInterface.h For LinkSortedList pg. 376 has the code for insertSorted. You must complete the implementation. Image shown below: Therefore the LinkedSortedList is not based on a LinkedList but uses its own link-based implementation. Do not use throw on function declarations as it is obsolete. Driver program should: create a sorted list insert 21 random numbers (1-100) using the STL random library Display the numbers as they are inserted. Then remove the first number inserted. Last of all display the sorted list of 20 numbers. No user input for driver program. SortedListInterface.h: //Â Created by Frank M. Carrano and Timothy…arrow_forwardin java, Two abstract data types are the ordered list and the unordered list. Explain how these two ADTs are similar and how they differ. To answer this question, assume that you do not know how they are implemented (that is, whether they are implemented using an array or a linked list).arrow_forwardJavaWrite a program that implements the methods of a list using the operations of each ADT. Making use of Inheritance and Polymorphism. Create the stack (STACK) and queue (QUEUE) derived classes and implement their methods as indicated in the book.In the main program place a main menu with three options 1. List, 2. Stack and 3. Queue and in each option show the use of the operations of each ADTarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning