Question: 2. Write the basic clerical methods given the partial class definition below: class rational { private: int numerator; int denominator; public: static const int DivBy0
2. Write the basic clerical methods given the partial class definition below:
class rational { private: int numerator; int denominator; public: static const int DivBy0 = -100; // your clerical methods go here // remember to define constructors, inspectors, and mutators };
Linear data structures like linked lists, stacks, and queues represent useful programming techniques. The next few questions will deal with them and how to implement them in C++.
Linked Lists There are many variations on linked lists that are used in programming. We will consider a singly linked list with insertion at the head. Recall: a singly linked list is a chain of nodes each of which contains the data being stored and a link to the next node in the chain. All linked lists should support add, delete, and find operations.
3. If we presume that our linked list stores an integer, complete the following implementation of the node class. class node { // this is the one of the few times I deviate from hiding data elements in my class // the node is already hidden by the list class that will be calling it // so we will declare every member of the node class as public public: // define a data member that stores an integer // define a pointer to the next instance of class node // define the necessary constructors for class node // I recommend that you define both the default constructor // and a specific constructor that takes both the data and the next pointer };
4. Now that we have defined class node, lets define a class for the linked list itself. Complete the following implementation of class list. class list { private: // yep, private is back // define the necessary data members to make the list work // that would be a pointer to the head of the list // and the number of elements in the list public: // define the necessary constructors // define the required operations // 1. Insert a new node at the head of the list // 2. Find a node containing the requested information // 3. Delete a node containing the requested information // 4. Print the contents of the linked list
// Define the necessary destructor yep, new concept. What you create you must delete // and we are creating new nodes so we need to create a method known as the destructor // that cleans up our mess. The destructor for class list will be named ~list(). // Complete the code for ~list(); };
Queue The basic queue is a FIFO (first in, first out). The operations are different, but the structure of its classes is like the linked list. The basic queue should support enQueue, deQueue, peek, and isEmpty operations.
5. Using the linked list and the deck classes as models, write the class structures for class node and class queue. Assume that the queue stores integers.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
