SlideShare a Scribd company logo
1 of 6
Download to read offline
C++. Please, test your program before you submit the answer.
Background:
Circular Linked List: A circular linked list is a linked list where a non-empty list has no null pointers.
Unless empty, each node has a pointer to the next node, and the last node points back to the first
node.
Assigment:
Write a cpp program that will serve the purpose of a test driver for previously written CLinkedList.h
file. Your program will:
1) Create a choice menu and prompt the user for input. Must be case insensitive!
2) Read the input and call for functions outside of main, in order to perform operations chosen by
the user. These functions involve: Inserting Interger, Removing Interger, Forward Print and
Backward Print.
Requirements and Notes:
1. Forwards Print does not require a subfunction in order to produce output. All the other
operations must call corresponding subfunctions.
2. Nodes of the circular list must be arranged in ascending order.
3. User Input must be processed case insensitive, and implemented using the loop.
4. Document your code completely.
5. CLinkedList.h file contains 3 classes.
- Circular linked lists class with following member functions: constructor, copy constructor,
destructor, assignment operator, insert and remove.
- Node class included in the file header.
- A list iterator class provides a public interface to the list. The pointer points at nodes in the linked
list. Its member functions are as follows:
Constructor: Assigns the linked list data member to the parameter, a reference to a circular linked
list.
begin() sets the iterator to the first node of the linked list (or NULL if the list is empty)
isEmpty() returns whether or not the wrapped linked list is empty
isFirstNode() returns whether the present node is the first node of the linked list
isLastNode() returns whether the present node is the last node of the linked list
operator*() returns the data of the node currently pointed at. (You need 2)
operator++() pre-increment operator advances the pointer to the next node in the list, if there is
one
operator++(int) post-increment operator advances the pointer to the next node in the list, if there
is one
6. Insert function must give feedback where it says the position of where the int was inserted for
example: "Inserting 25 in the middle."
7. Remove function must give either one of these types of feedback:
- "Removing 25" if the int given by the user was found in the list
-"Cannot find 25" if it was not. The program will then move the user back to the choice menu.
Files:
// File: Node.h
// Singly-linked list node definition/implementation (also good for circular)
#ifndef NODE_H
#define NODE_H
// Need to prototype template classes if they are to be friends
template <typename eltType> class CLinkedList;
template <typename eltType> class CListItr;
template <typename eltType> class Node
{ private:
Node(eltType info, Node* link = NULL ) :
data(info), next(link)
{};
eltType data;
Node *next;
friend class CLinkedList<eltType>;
friend class CListItr<eltType>;
};
#endif
// File: CLinkedList.h
// Circular Linked List class with List Iterator class
#ifndef CLINKEDLIST_H
#define CLINKEDLIST_H
#include "Node.h"
#include <iostream>
template<class T>
class ListIterator;
template<class T>
class CLinkedList {
private:
Node<T> *last;
public:
CLinkedList() : last(nullptr) {}
CLinkedList(const CLinkedList<T>& other);
~CLinkedList();
CLinkedList<T>& operator=(const CLinkedList<T>& other);
void insert(const T& value);
void remove(const T& value);
friend class ListIterator<T>;
};
template<class T>
CLinkedList<T>::CLinkedList(const CLinkedList<T>& other) {
if (other.last == nullptr) {
last = nullptr;
}
else {
last = new Node<T>(other.last->data);
Node<T>* current = other.last->next;
while (current != other.last) {
insert(current->data);
current = current->next;
}
insert(current->data);
}
}
template<class T>
CLinkedList<T>::~CLinkedList() {
if (last != nullptr) {
Node<T>* current = last->next;
last->next = nullptr;
delete current;
}
}
template<class T>
CLinkedList<T>& CLinkedList<T>::operator=(const CLinkedList<T>& other) {
if (this != &other) {
CLinkedList<T> temp(other);
std::swap(last, temp.last);
}
return *this;
}
template<class T>
void CLinkedList<T>::insert(const T& value) {
Node<T>* newNode = new Node<T>(value);
if (last == nullptr) {
newNode->next = newNode;
last = newNode;
}
else {
Node<T>* current = last->next;
Node<T>* prev = last;
while (current != last && current->data < value) {
prev = current;
current = current->next;
}
if (current == last && current->data < value) {
last = newNode;
}
prev->next = newNode;
newNode->next = current;
}
}
template<class T>
void CLinkedList<T>::remove(const T& value) {
if (last != nullptr) {
Node<T>* current = last->next;
Node<T>* prev = last;
while (current != last && current->data < value) {
prev = current;
current = current->next;
}
if (current->data == value) {
if (current == last && current->next == last) {
last = nullptr;
}
else {
prev->next = current->next;
if (current == last) {
last = prev;
}
}
current->next = nullptr;
delete current;
}
}
}
template<class T>
class ListIterator {
private:
const CLinkedList<T>& list;
Node<T>* current;
public:
ListIterator(const CLinkedList<T>& _list) : list(_list), current(list.last) {}
bool hasNext() const { return current != nullptr && current->next != list.last->next; }
void next() { current = current->next; }
T& value() const { return current->data; }
};
#endif
The program so far. It shows the basics of what it is supposed to do. You may use it as you wish.
//File testLL.cpp
/*! Test Driver for the file CLinkedList.h */
#include <iostream>
#include <string>
#include "Node.h"
#include "CLinkedList.h"
using namespace std;
//Function to insert an interger to the list in the ascending order
void intInsert(){}
//Functiion to remove an interger from the list
void intRemove(){}
//Function to print the list backwards
void printBackwards(){}
//Function to print out the menu choices,
//Created in order to make the main function more readable
//Function type: Export
void printOptions(){
cout<<"-------------------------"<<endl;
cout<<"I - Insert Interger"<<endl;
cout<<"R - Remove Interger"<<endl;
cout<<"F - Forward Print"<<endl;
cout<<"B - Backword Print"<<endl;
cout<<"E - Exit"<<endl;
cout<<"--------------------------"<<endl;
}
int main(){
string choice = "";
int interger = 0;
string exit = "False";
cout<<"This program is a test driver for the file CLinkedList.h"<<endl;
cout<<"Please select one of the following operations on a Circular Linked List"<<endl;
cout<<"------------------------------------------------------------"<<endl;
printOptions();
cout<<"Your Choice: ";
cin>>choice;
cout<<endl<<endl;
while (exit != "True"){
if (choice == "I" or choice == "i"){
cout<<"Iterger to insert: ";
cin>>interger;
intInsert();
cout<<endl<<"Inserting "<< interger << endl<<endl;
}
else if (choice == "R" or choice == "r"){
cout<<"Iterger to remove: ";
cin>>interger;
intRemove();
cout<<endl<<"Removing "<< interger << endl<<endl;
}
else if (choice == "F" or choice =="f"){
cout<<"Printing Forwards"<<endl<<endl;
}
else if (choice == "B" or choice == "b"){
cout<<"Printing Backwords"<< endl<<endl;
printBackwords();
}
else if (choice == "E" or choice == "e"){
cout<<"Exitting the program..."<<endl;
return 0;
}
else{
cout<<"Wrong input format"<<endl<<endl;}
cout<<"Please enter another operation: "<<endl;
printOptions();
cin>>choice;
cout<<endl;
}
}

More Related Content

Similar to C++ Please test your program before you submit the answer.pdf

C++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfC++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfaashkaahm
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdfaathmaproducts
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdfaathiauto
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfstopgolook
 
A circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfA circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfaayushmaany2k14
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfinfomalad
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematicakrasul
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within MathematicaShoaib Burq
 
Create a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docxCreate a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docxrajahchelsey
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answersAkash Gawali
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfeyeonsecuritysystems
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfarracollection
 

Similar to C++ Please test your program before you submit the answer.pdf (20)

C++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdfC++ Please make sure that your answer is fully submitted .pdf
C++ Please make sure that your answer is fully submitted .pdf
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdfIn C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
In C++ please, do not alter node.hStep 1 Inspect the Node.h file.pdf
 
A circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdfA circular linked list is a linked list where a nonempty li.pdf
A circular linked list is a linked list where a nonempty li.pdf
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
File name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdfFile name a2.cppTaskFor this assignment, you are required to ei.pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdf
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Using CUDA Within Mathematica
Using CUDA Within MathematicaUsing CUDA Within Mathematica
Using CUDA Within Mathematica
 
Using Cuda Within Mathematica
Using Cuda Within MathematicaUsing Cuda Within Mathematica
Using Cuda Within Mathematica
 
Create a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docxCreate a Queue class that implements a queue abstraction. A queue is.docx
Create a Queue class that implements a queue abstraction. A queue is.docx
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers1183 c-interview-questions-and-answers
1183 c-interview-questions-and-answers
 
I need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdfI need help completing this C++ code with these requirements.instr.pdf
I need help completing this C++ code with these requirements.instr.pdf
 
Implement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdfImplement a function called getElements() that takes in two lists. T.pdf
Implement a function called getElements() that takes in two lists. T.pdf
 
Python Basics
Python BasicsPython Basics
Python Basics
 

More from aashisha5

An economic model is useful only if it Group of answer choi.pdf
An economic model is useful only if it Group of answer choi.pdfAn economic model is useful only if it Group of answer choi.pdf
An economic model is useful only if it Group of answer choi.pdfaashisha5
 
Caso de estudio Terror en el Taj Bombay liderazgo centrado.pdf
Caso de estudio  Terror en el Taj Bombay liderazgo centrado.pdfCaso de estudio  Terror en el Taj Bombay liderazgo centrado.pdf
Caso de estudio Terror en el Taj Bombay liderazgo centrado.pdfaashisha5
 
Caroline es una persona popular con un gran ego Se mete en .pdf
Caroline es una persona popular con un gran ego Se mete en .pdfCaroline es una persona popular con un gran ego Se mete en .pdf
Caroline es una persona popular con un gran ego Se mete en .pdfaashisha5
 
Bonnie Morgen primer da de trabajo y un dilema tico INTR.pdf
Bonnie Morgen primer da de trabajo y un dilema tico  INTR.pdfBonnie Morgen primer da de trabajo y un dilema tico  INTR.pdf
Bonnie Morgen primer da de trabajo y un dilema tico INTR.pdfaashisha5
 
Answer the following a What is meant by the rounding unit.pdf
Answer the following   a What is meant by the rounding unit.pdfAnswer the following   a What is meant by the rounding unit.pdf
Answer the following a What is meant by the rounding unit.pdfaashisha5
 
Are global teams necessary for a multinational corporation t.pdf
Are global teams necessary for a multinational corporation t.pdfAre global teams necessary for a multinational corporation t.pdf
Are global teams necessary for a multinational corporation t.pdfaashisha5
 
ABC company is expecting an ebit of rs 100000 whose equity .pdf
ABC company is expecting an ebit of rs 100000 whose equity .pdfABC company is expecting an ebit of rs 100000 whose equity .pdf
ABC company is expecting an ebit of rs 100000 whose equity .pdfaashisha5
 
Aadaki sahne oyununu dnn ki periyotta tekrarlanr Oyuncu.pdf
Aadaki sahne oyununu dnn  ki periyotta tekrarlanr Oyuncu.pdfAadaki sahne oyununu dnn  ki periyotta tekrarlanr Oyuncu.pdf
Aadaki sahne oyununu dnn ki periyotta tekrarlanr Oyuncu.pdfaashisha5
 
A Question Briefly define what we mean by Uninsured B Q.pdf
A Question Briefly define what we mean by Uninsured  B Q.pdfA Question Briefly define what we mean by Uninsured  B Q.pdf
A Question Briefly define what we mean by Uninsured B Q.pdfaashisha5
 
assume your team is developing a WBS to renovate a dorm at y.pdf
assume your team is developing a WBS to renovate a dorm at y.pdfassume your team is developing a WBS to renovate a dorm at y.pdf
assume your team is developing a WBS to renovate a dorm at y.pdfaashisha5
 
5 Ha sido contratado como director de marketing de DoorDash.pdf
5 Ha sido contratado como director de marketing de DoorDash.pdf5 Ha sido contratado como director de marketing de DoorDash.pdf
5 Ha sido contratado como director de marketing de DoorDash.pdfaashisha5
 
A Company is planning to undertake a project requiring initi.pdf
A Company is planning to undertake a project requiring initi.pdfA Company is planning to undertake a project requiring initi.pdf
A Company is planning to undertake a project requiring initi.pdfaashisha5
 
A cafetery carefully monitors customer orders and discovered.pdf
A cafetery carefully monitors customer orders and discovered.pdfA cafetery carefully monitors customer orders and discovered.pdf
A cafetery carefully monitors customer orders and discovered.pdfaashisha5
 
70 of all students at a college still need to take another .pdf
70 of all students at a college still need to take another .pdf70 of all students at a college still need to take another .pdf
70 of all students at a college still need to take another .pdfaashisha5
 
31 Soru metni Aadaki ifadelerden hangisi dorudur A Derin.pdf
31 Soru metni Aadaki ifadelerden hangisi dorudur  A Derin.pdf31 Soru metni Aadaki ifadelerden hangisi dorudur  A Derin.pdf
31 Soru metni Aadaki ifadelerden hangisi dorudur A Derin.pdfaashisha5
 
353 Use multifactor authentication for local and network .pdf
353 Use multifactor authentication for local and network .pdf353 Use multifactor authentication for local and network .pdf
353 Use multifactor authentication for local and network .pdfaashisha5
 
Developing and developed economies use a range of industrial.pdf
Developing and developed economies use a range of industrial.pdfDeveloping and developed economies use a range of industrial.pdf
Developing and developed economies use a range of industrial.pdfaashisha5
 
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdf
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdfA Laura y Len se les concedi el divorcio en 2019 De acuer.pdf
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdfaashisha5
 
A veces una empresa antigua en una industria puede construi.pdf
A veces una empresa antigua en una industria puede construi.pdfA veces una empresa antigua en una industria puede construi.pdf
A veces una empresa antigua en una industria puede construi.pdfaashisha5
 
What are the formulas or relationship options 17 creating.pdf
What are the formulas or relationship options 17 creating.pdfWhat are the formulas or relationship options 17 creating.pdf
What are the formulas or relationship options 17 creating.pdfaashisha5
 

More from aashisha5 (20)

An economic model is useful only if it Group of answer choi.pdf
An economic model is useful only if it Group of answer choi.pdfAn economic model is useful only if it Group of answer choi.pdf
An economic model is useful only if it Group of answer choi.pdf
 
Caso de estudio Terror en el Taj Bombay liderazgo centrado.pdf
Caso de estudio  Terror en el Taj Bombay liderazgo centrado.pdfCaso de estudio  Terror en el Taj Bombay liderazgo centrado.pdf
Caso de estudio Terror en el Taj Bombay liderazgo centrado.pdf
 
Caroline es una persona popular con un gran ego Se mete en .pdf
Caroline es una persona popular con un gran ego Se mete en .pdfCaroline es una persona popular con un gran ego Se mete en .pdf
Caroline es una persona popular con un gran ego Se mete en .pdf
 
Bonnie Morgen primer da de trabajo y un dilema tico INTR.pdf
Bonnie Morgen primer da de trabajo y un dilema tico  INTR.pdfBonnie Morgen primer da de trabajo y un dilema tico  INTR.pdf
Bonnie Morgen primer da de trabajo y un dilema tico INTR.pdf
 
Answer the following a What is meant by the rounding unit.pdf
Answer the following   a What is meant by the rounding unit.pdfAnswer the following   a What is meant by the rounding unit.pdf
Answer the following a What is meant by the rounding unit.pdf
 
Are global teams necessary for a multinational corporation t.pdf
Are global teams necessary for a multinational corporation t.pdfAre global teams necessary for a multinational corporation t.pdf
Are global teams necessary for a multinational corporation t.pdf
 
ABC company is expecting an ebit of rs 100000 whose equity .pdf
ABC company is expecting an ebit of rs 100000 whose equity .pdfABC company is expecting an ebit of rs 100000 whose equity .pdf
ABC company is expecting an ebit of rs 100000 whose equity .pdf
 
Aadaki sahne oyununu dnn ki periyotta tekrarlanr Oyuncu.pdf
Aadaki sahne oyununu dnn  ki periyotta tekrarlanr Oyuncu.pdfAadaki sahne oyununu dnn  ki periyotta tekrarlanr Oyuncu.pdf
Aadaki sahne oyununu dnn ki periyotta tekrarlanr Oyuncu.pdf
 
A Question Briefly define what we mean by Uninsured B Q.pdf
A Question Briefly define what we mean by Uninsured  B Q.pdfA Question Briefly define what we mean by Uninsured  B Q.pdf
A Question Briefly define what we mean by Uninsured B Q.pdf
 
assume your team is developing a WBS to renovate a dorm at y.pdf
assume your team is developing a WBS to renovate a dorm at y.pdfassume your team is developing a WBS to renovate a dorm at y.pdf
assume your team is developing a WBS to renovate a dorm at y.pdf
 
5 Ha sido contratado como director de marketing de DoorDash.pdf
5 Ha sido contratado como director de marketing de DoorDash.pdf5 Ha sido contratado como director de marketing de DoorDash.pdf
5 Ha sido contratado como director de marketing de DoorDash.pdf
 
A Company is planning to undertake a project requiring initi.pdf
A Company is planning to undertake a project requiring initi.pdfA Company is planning to undertake a project requiring initi.pdf
A Company is planning to undertake a project requiring initi.pdf
 
A cafetery carefully monitors customer orders and discovered.pdf
A cafetery carefully monitors customer orders and discovered.pdfA cafetery carefully monitors customer orders and discovered.pdf
A cafetery carefully monitors customer orders and discovered.pdf
 
70 of all students at a college still need to take another .pdf
70 of all students at a college still need to take another .pdf70 of all students at a college still need to take another .pdf
70 of all students at a college still need to take another .pdf
 
31 Soru metni Aadaki ifadelerden hangisi dorudur A Derin.pdf
31 Soru metni Aadaki ifadelerden hangisi dorudur  A Derin.pdf31 Soru metni Aadaki ifadelerden hangisi dorudur  A Derin.pdf
31 Soru metni Aadaki ifadelerden hangisi dorudur A Derin.pdf
 
353 Use multifactor authentication for local and network .pdf
353 Use multifactor authentication for local and network .pdf353 Use multifactor authentication for local and network .pdf
353 Use multifactor authentication for local and network .pdf
 
Developing and developed economies use a range of industrial.pdf
Developing and developed economies use a range of industrial.pdfDeveloping and developed economies use a range of industrial.pdf
Developing and developed economies use a range of industrial.pdf
 
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdf
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdfA Laura y Len se les concedi el divorcio en 2019 De acuer.pdf
A Laura y Len se les concedi el divorcio en 2019 De acuer.pdf
 
A veces una empresa antigua en una industria puede construi.pdf
A veces una empresa antigua en una industria puede construi.pdfA veces una empresa antigua en una industria puede construi.pdf
A veces una empresa antigua en una industria puede construi.pdf
 
What are the formulas or relationship options 17 creating.pdf
What are the formulas or relationship options 17 creating.pdfWhat are the formulas or relationship options 17 creating.pdf
What are the formulas or relationship options 17 creating.pdf
 

Recently uploaded

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 

C++ Please test your program before you submit the answer.pdf

  • 1. C++. Please, test your program before you submit the answer. Background: Circular Linked List: A circular linked list is a linked list where a non-empty list has no null pointers. Unless empty, each node has a pointer to the next node, and the last node points back to the first node. Assigment: Write a cpp program that will serve the purpose of a test driver for previously written CLinkedList.h file. Your program will: 1) Create a choice menu and prompt the user for input. Must be case insensitive! 2) Read the input and call for functions outside of main, in order to perform operations chosen by the user. These functions involve: Inserting Interger, Removing Interger, Forward Print and Backward Print. Requirements and Notes: 1. Forwards Print does not require a subfunction in order to produce output. All the other operations must call corresponding subfunctions. 2. Nodes of the circular list must be arranged in ascending order. 3. User Input must be processed case insensitive, and implemented using the loop. 4. Document your code completely. 5. CLinkedList.h file contains 3 classes. - Circular linked lists class with following member functions: constructor, copy constructor, destructor, assignment operator, insert and remove. - Node class included in the file header. - A list iterator class provides a public interface to the list. The pointer points at nodes in the linked list. Its member functions are as follows: Constructor: Assigns the linked list data member to the parameter, a reference to a circular linked list. begin() sets the iterator to the first node of the linked list (or NULL if the list is empty) isEmpty() returns whether or not the wrapped linked list is empty isFirstNode() returns whether the present node is the first node of the linked list isLastNode() returns whether the present node is the last node of the linked list operator*() returns the data of the node currently pointed at. (You need 2) operator++() pre-increment operator advances the pointer to the next node in the list, if there is one operator++(int) post-increment operator advances the pointer to the next node in the list, if there is one 6. Insert function must give feedback where it says the position of where the int was inserted for example: "Inserting 25 in the middle." 7. Remove function must give either one of these types of feedback: - "Removing 25" if the int given by the user was found in the list -"Cannot find 25" if it was not. The program will then move the user back to the choice menu. Files:
  • 2. // File: Node.h // Singly-linked list node definition/implementation (also good for circular) #ifndef NODE_H #define NODE_H // Need to prototype template classes if they are to be friends template <typename eltType> class CLinkedList; template <typename eltType> class CListItr; template <typename eltType> class Node { private: Node(eltType info, Node* link = NULL ) : data(info), next(link) {}; eltType data; Node *next; friend class CLinkedList<eltType>; friend class CListItr<eltType>; }; #endif // File: CLinkedList.h // Circular Linked List class with List Iterator class #ifndef CLINKEDLIST_H #define CLINKEDLIST_H #include "Node.h" #include <iostream> template<class T> class ListIterator; template<class T> class CLinkedList { private: Node<T> *last; public: CLinkedList() : last(nullptr) {} CLinkedList(const CLinkedList<T>& other); ~CLinkedList(); CLinkedList<T>& operator=(const CLinkedList<T>& other); void insert(const T& value); void remove(const T& value); friend class ListIterator<T>; }; template<class T> CLinkedList<T>::CLinkedList(const CLinkedList<T>& other) { if (other.last == nullptr) {
  • 3. last = nullptr; } else { last = new Node<T>(other.last->data); Node<T>* current = other.last->next; while (current != other.last) { insert(current->data); current = current->next; } insert(current->data); } } template<class T> CLinkedList<T>::~CLinkedList() { if (last != nullptr) { Node<T>* current = last->next; last->next = nullptr; delete current; } } template<class T> CLinkedList<T>& CLinkedList<T>::operator=(const CLinkedList<T>& other) { if (this != &other) { CLinkedList<T> temp(other); std::swap(last, temp.last); } return *this; } template<class T> void CLinkedList<T>::insert(const T& value) { Node<T>* newNode = new Node<T>(value); if (last == nullptr) { newNode->next = newNode; last = newNode; } else { Node<T>* current = last->next; Node<T>* prev = last; while (current != last && current->data < value) { prev = current; current = current->next; }
  • 4. if (current == last && current->data < value) { last = newNode; } prev->next = newNode; newNode->next = current; } } template<class T> void CLinkedList<T>::remove(const T& value) { if (last != nullptr) { Node<T>* current = last->next; Node<T>* prev = last; while (current != last && current->data < value) { prev = current; current = current->next; } if (current->data == value) { if (current == last && current->next == last) { last = nullptr; } else { prev->next = current->next; if (current == last) { last = prev; } } current->next = nullptr; delete current; } } } template<class T> class ListIterator { private: const CLinkedList<T>& list; Node<T>* current; public: ListIterator(const CLinkedList<T>& _list) : list(_list), current(list.last) {} bool hasNext() const { return current != nullptr && current->next != list.last->next; } void next() { current = current->next; } T& value() const { return current->data; } };
  • 5. #endif The program so far. It shows the basics of what it is supposed to do. You may use it as you wish. //File testLL.cpp /*! Test Driver for the file CLinkedList.h */ #include <iostream> #include <string> #include "Node.h" #include "CLinkedList.h" using namespace std; //Function to insert an interger to the list in the ascending order void intInsert(){} //Functiion to remove an interger from the list void intRemove(){} //Function to print the list backwards void printBackwards(){} //Function to print out the menu choices, //Created in order to make the main function more readable //Function type: Export void printOptions(){ cout<<"-------------------------"<<endl; cout<<"I - Insert Interger"<<endl; cout<<"R - Remove Interger"<<endl; cout<<"F - Forward Print"<<endl; cout<<"B - Backword Print"<<endl; cout<<"E - Exit"<<endl; cout<<"--------------------------"<<endl; } int main(){ string choice = ""; int interger = 0; string exit = "False"; cout<<"This program is a test driver for the file CLinkedList.h"<<endl; cout<<"Please select one of the following operations on a Circular Linked List"<<endl; cout<<"------------------------------------------------------------"<<endl; printOptions(); cout<<"Your Choice: "; cin>>choice; cout<<endl<<endl; while (exit != "True"){ if (choice == "I" or choice == "i"){ cout<<"Iterger to insert: "; cin>>interger;
  • 6. intInsert(); cout<<endl<<"Inserting "<< interger << endl<<endl; } else if (choice == "R" or choice == "r"){ cout<<"Iterger to remove: "; cin>>interger; intRemove(); cout<<endl<<"Removing "<< interger << endl<<endl; } else if (choice == "F" or choice =="f"){ cout<<"Printing Forwards"<<endl<<endl; } else if (choice == "B" or choice == "b"){ cout<<"Printing Backwords"<< endl<<endl; printBackwords(); } else if (choice == "E" or choice == "e"){ cout<<"Exitting the program..."<<endl; return 0; } else{ cout<<"Wrong input format"<<endl<<endl;} cout<<"Please enter another operation: "<<endl; printOptions(); cin>>choice; cout<<endl; } }