Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm not sure what you mean by should be readable. I did not copy and paste all of the code in Chegg, because of how

I'm not sure what you mean by should be readable. I did not copy and paste all of the code in Chegg, because of how much space it would have taken to show all of the 9 files that are incorporated in the program. Honestly, it seems like my program should work, everything should be logically correct or very close, but nothing seems to work. There no more worries about the link I've copy/pasted every bit of the code and a screen shot of the errors the compiler throws. I am using Code::Blocks if that matters. The program is intended to read in a file that will look like....

NAVIGATE http://google.com NAVIGATE http://reddit.com NAVIGATE http://facebook.com NAVIGATE http://myspace.com BACK BACK HISTORY NAVIGATE http://bing.com HISTORY

and the output should match.....

Oldest =========== http://google.com http://reddit.com  

But I cannot figure out what is wrong with it or how to fix it, and it just feels like I've wasted a lot of time working on it. This is going to be very long so I apologize ahead of time....

//MAIN

#include #include #include

#include "LinkedList.h" #include "WebBrowser.cpp"

int main(int argc, char const *argv[]) { std::string command, website; std::ifstream file; WebBrowser* websites = new WebBrowser(); file.open("input.txt");

while(file){ file >> command; if(command == "NAVIGATE"){ file >> website; websites->navigateTo(website); } else if(command == "BACK"){ std::cout back(); } else if(command == "FORWARD"){ std::cout forward(); } else if(command == "HISTORY"){ websites->copyCurrentHistory(websites); } command = " "; }

//delete websites; return 0; }

//WEBBROWSERINTERFACE.H

#include #include #include

#include "LinkedList.h" #include "WebBrowser.cpp"

int main(int argc, char const *argv[]) { std::string command, website; std::ifstream file; WebBrowser* websites = new WebBrowser(); file.open("input.txt");

while(file){ file >> command; if(command == "NAVIGATE"){ file >> website; websites->navigateTo(website); } else if(command == "BACK"){ std::cout back(); } else if(command == "FORWARD"){ std::cout forward(); } else if(command == "HISTORY"){ websites->copyCurrentHistory(websites); } command = " "; }

//delete websites; return 0; }

//WEBBROWSER.H

#ifndef _WEB_BROWSER

#define _WEB_BROWSER

#include "WebBrowserInterface.h"

#include "ListInterface.h"

#include

class WebBrowser : public WebBrowserInterface

{

private:

LinkedList<:string>* browserHistory; // LinkedList which will hold history

public:

WebBrowser();

WebBrowser(const LinkedList<:string>& aList);

~WebBrowser();

void navigateTo(std::string url);

void forward();

void back();

std::string currentURL() const;

void copyCurrentHistory(LinkedList<:string>& destination);

}; // end WebBrowser

//#include "WebBrowser.cpp"

#endif

//WEBBROWSER.CPP

#include

#include "WebBrowser.h"

//#include "ListInterface.h"

#include "LinkedList.h"

WebBrowser::WebBrowser() //: browserHistory()

{

LinkedList<:string>* browserHistory = new LinkedList;

} // end default constructor

WebBrowser::WebBrowser(const LinkedList<:string>& aList)

{

LinkedList<:string>* browserHistory = aList;

}

WebBrowser::~WebBrowser()

{

// Don't know if anything needs to be destroyed or not

} // end destructor

void WebBrowser::navigateTo(std::string website)

{

browserHistory->insert(browserHistory->getCurPosition(), website);

} // end navigateTo

void WebBrowser::forward()

{

browserHistory->forward();

} // end forward

void WebBrowser::back()

{

browserHistory->back();

} // end back

std::string WebBrowser::currentURL() const

{

return browserHistory->getEntry(browserHistory->getCurPosition() - 1);

} // end currentURL

void WebBrowser::copyCurrentHistory(LinkedList<:string>& destination)

{

// Is this the print history function?

browserHistory->copyTo(destination);

} // end copyCurrentHistory

// end of Implementation file

//LISTINTERFACE.H

#ifndef LIST_INTERFACE_H #define LIST_INTERFACE_H

template class ListInterface {

public: ListInterface(); virtual ~ListInterface(){}

virtual bool isEmpty() const = 0; virtual int getLength() const = 0; virtual void insert(int position, T& website) throw (std::runtime_error) = 0; virtual void remove(int position) throw (std::runtime_error) = 0; virtual void clear() = 0; virtual int getCurPosition() const = 0; virtual T getEntry(int position) throw (std::runtime_error) = 0;

/** Here's an example of a doxygen comment block. Do this for all methods * @pre The position is between 1 and the list's length * @post The entry at the given position is replaced with the new entry * @param position: 1

#endif

//LINKEDLIST.H

#ifndef _LINKED_LIST

#define _LINKED_LIST

#include "ListInterface.h"

#include "Node.h"

#include

template

class LinkedList : public ListInterface

{

private:

Node* headPtr; // Pointer to first node in the chain;

// (contains the first entry in the list)

int itemCount; // Current count of list items

int curPosition; // Current position in list; this is actually always

// one higher than the url currently displayed.

// It's going to be one higher than the last insert

// position, ready to insert again

// Locates a specified node in this linked list.

// @pre position is the number of the desired node;

// position >= 1 and position

// @post The node is found and a pointer to it is returned.

// @param position The number of the node to locate.

// @return A pointer to the node at the given position.

T getNodeAt(int position) const;

public:

LinkedList();

//LinkedList(const LinkedList& aList);

~LinkedList();

bool isEmpty() const;

int getLength() const;

void insert(int newPosition, const T& website) throw (std::runtime_error);

void remove(int position) throw (std::runtime_error);

void clear();

void forward();

void back();

int getCurPosition() const;

void copyTo(LinkedList<:string>& destination) const;

T getEntry(int position) const throw (std::runtime_error);

void replace(int position, const T& newEntry);

}; // end LinkedList

#include "LinkedList.cpp"

#endif

//LINKEDLIST.CPP

#include

//#include "LinkedList.h" // Header file

//#include "ListInterface.h"

template

LinkedList::LinkedList()

{

headPtr = nullptr;

itemCount = 0;

curPosition = 1;

LinkedList* browserHistory = new LinkedList();;

} // end default constructor

template

LinkedList::~LinkedList()

{

clear();

} // end destructor

template

bool LinkedList::isEmpty() const

{

return itemCount == 0;

} // end isEmpty

template

int LinkedList::getLength() const

{

return itemCount;

} // end getLength

template

void LinkedList::insert(int newPosition, const T& website) throw (std::runtime_error)

{

// Insert - not Add - we are inserting a new node in an existing list

// That can only happen at a position in the list or the end

bool ableToInsert = (newPosition >= 1) && (newPosition

if (ableToInsert)

{

// Create a new node containing the new entry

Node* newNodePtr = new Node(website);

// Attach new node to chain

if (newPosition == 1)

{

// Insert new node at beginning of chain

newNodePtr->setNext(headPtr);

headPtr = newNodePtr;

}

else

{

// Find node that will be before new node

Node<:string>* prevPtr = getNodeAt(newPosition-1);

// Insert new node after node to which prevPtr points

newNodePtr->setNext(prevPtr->getNext());

prevPtr->setNext(newNodePtr);

} // end if

curPosition = newPosition + 1;

itemCount++; // Increase count of entries

}

else{}

throw std::runtime_error("Cannot insert element");

} // end insert

template

void LinkedList::remove(int position) throw(std::runtime_error)

{

bool ableToRemove = (position >= 1) && (position

if (ableToRemove)

{

Node* curPtr = nullptr;

if (position == 1)

{

// Remove the first node in the chain

curPtr = headPtr; // Save pointer to node

headPtr = headPtr->getNext();

}

else

{

// Find node that is before the one to delete

Node<:string>* prevPtr = getNodeAt(position - 1);

// Point to node to delete

curPtr = prevPtr->getNext();

// Disconnect indicated node from chain by connecting the

// prior node with the one after

prevPtr->setNext(curPtr->getNext());

} // end if

// Return node to system

curPtr->setNext(nullptr);

delete curPtr;

curPtr = nullptr;

curPosition = position;

itemCount--; // Decrease count of entries

}

else {}

throw std::runtime_error("Cannot remove item");

} // end remove

template

void LinkedList::clear()

{

while (!isEmpty())

remove(1);

} // end clear

template

void LinkedList::forward() //const throw(std::runtime_error)

{

if(curPosition

} // end forward

template

void LinkedList::back() //throw(std::runtime_error)

{

if(curPosition > 1) curPosition--;

} // end back

template

int LinkedList::getCurPosition() const //throw(std::runtime_error)

{

return curPosition;

} // end getCurPosition

template

void LinkedList::copyTo(LinkedList<:string>& destination) const //throw(std::runtime_error)

{

destination.insert(1, "Oldest");

destination.insert(2, "===========");

for(int index = 1; index

{

std::string curUrl = getEntry(index);

if(index == curPosition - 1)

{

curUrl = curUrl + "

}

destination.insert((itemCount+1), curUrl);

}

destination.insert((itemCount+1),"===========");

destination.insert((itemCount+1), "Newest");

}

template

T LinkedList::getEntry(int position) const throw(std::runtime_error)

{

// Enforce precondition

bool ableToGet = (position >= 1) && (position

if (ableToGet)

{

Node<:string>* nodePtr = getNodeAt(position);

return nodePtr->getItem();

}

else

{

std::string message = "getEntry() called with an empty list or ";

message = message + "invalid position.";

throw(std::runtime_error(message));

} // end if

} // end getEntry

template

T LinkedList::getNodeAt(int position) const

{

// Debugging check of precondition

assert( (position >= 1) && (position

// Count from the beginning of the chain

Node* curPtr = headPtr;

for (int skip = 1; skip

curPtr = curPtr->getNext();

return curPtr;

} // end getNodeAt

// End of implementation file.

//NODE.H

#ifndef _NODE #define _NODE

template class Node { private: T item; // A data item // Removed * here Node *next; // Pointer to next node

public: Node(); Node(const T& anItem); Node(const T& anItem, Node* nextNodePtr); void setItem(const T& anItem); void setNext(Node* nextNodePtr); T getItem() const ; T getNext() const ; // Added * here }; // end Node

#include "Node.cpp" #endif

//NODE.CPP

#include "Node.h"

#include

template

Node::Node()

{

next = nullptr;

} // end default constructor

template

Node::Node(const T& anItem)

{

item = anItem;

next = nullptr;

} // end constructor

template

Node::Node(const T& anItem, Node* nextNodePtr)

{

item = anItem;

next = nextNodePtr;

} // end constructor

template

void Node::setItem(const T& anItem)

{

item = anItem;

} // end setItem

template

void Node::setNext(Node* nextNodePtr)

{

next = nextNodePtr;

} // end setNext

template

T Node::getItem() const

{

return item;

} // end getItem

template

T Node::getNext() const

{

return next;

} // end getNext

image text in transcribed

File Line Message -Build file: "no target" in "no project" (compiler: unknown) C:\Users\Brian C:\UsersBrian. C:\Users\Brian :UseBrian.-15cannot convert const Linkediiststd:xil::basic stringccharto Linkedtistestd::cil::basic stringocharin initiaiia C:\Users\Brian C:Users Brian C:NUsers\Brsan.8 C:\Users\Brian... 45 C:Usexs Brian C:\Users\Brian.. 43 C:AUsersBrian C: Users Brian error: invalid use of template-name 'LinkedList' without an argument 1ist in constructor 'WebBrowser : :WebBrowser (const Linkedlist(std: : exall: :basic-stringc char"' : In function int main (int, const char* rror:invalid neu-expression of abstract class type WabBrowser note: because the foiloving vireual functions are pure within WebBrowser virtual void ilebBrowserInterface: copyCurrentkistory(Listinterface std::cxxll::basic-string:char > >6) exzor: no matching function for call to 'WebBrowser::copycurrentHistory (MebBrowser note: candidate: void HebBroser::copyCurrentHistory LinkedListstd:l: basic string char ) no known converson for argument 1 from .WebBrowser'. to .LinkedList&. In instantiation of 'void LinkedList::insert (int, oonat r6 ) vith r-std : : oxx11: :basistringcahar). : required from here error: cannot convert 'std:exx11::basic_stringseharco 'iode std::exx11::basie stringschar?in initialization rror no matching function for call to Nodestd:cll::basic stringcchar>setlext (std:cll::basic stringcchar) note : candidate : void KodeT>:: setNext (ModeT>*) [with T = sed : : exx11: :basic-stringsehar7] note: no known conversion for arguzent l rom 'stdx1l::basic_stringcchar>t'Nodecstd:el1::basic stringcchar In instantiation of 'T LinkedList::gtEntry (int) const with r= std ::exx1 1: :basicstring1': roquirod from horo error : In instantiation of 'T LinkedListT>::getNodeAt (int) required from .void LinkedList::nsert (Int, const required from here - C:NUsers\Brian53 C:\Users\Brian S6 C:\Users\Bria31 C:\Users\Brian... 31 C:AUsersBrian C: Usors\Brian 40 C:\Users\Bran 153 C:Users\Brian *" - - cannot convert 'std :: cxx11 ::basc stringehar>. to .tode-std:: cxx11: :bass.c strings char> >*. in ratialization oonat with T-std: : oxx11: :basiostring]": T4) [v1th T = std:: .cxx11: :bas c-stringeharJ' - C:Users Brian. 25 C:NUsers\Brian..- 173 COr: cannot convert "stdl1::basic string char>tode std:l1::basicstring char >in assignment C:Users\Brian 75 rror: could not convert curper' from liodesstd: exxii: :basie stringscharto td:cx11::basic stringschar> Build failed: 9 error (s), 7 warning(s) (0 minute(s), 1 second (s)) File Line Message -Build file: "no target" in "no project" (compiler: unknown) C:\Users\Brian C:\UsersBrian. C:\Users\Brian :UseBrian.-15cannot convert const Linkediiststd:xil::basic stringccharto Linkedtistestd::cil::basic stringocharin initiaiia C:\Users\Brian C:Users Brian C:NUsers\Brsan.8 C:\Users\Brian... 45 C:Usexs Brian C:\Users\Brian.. 43 C:AUsersBrian C: Users Brian error: invalid use of template-name 'LinkedList' without an argument 1ist in constructor 'WebBrowser : :WebBrowser (const Linkedlist(std: : exall: :basic-stringc char"' : In function int main (int, const char* rror:invalid neu-expression of abstract class type WabBrowser note: because the foiloving vireual functions are pure within WebBrowser virtual void ilebBrowserInterface: copyCurrentkistory(Listinterface std::cxxll::basic-string:char > >6) exzor: no matching function for call to 'WebBrowser::copycurrentHistory (MebBrowser note: candidate: void HebBroser::copyCurrentHistory LinkedListstd:l: basic string char ) no known converson for argument 1 from .WebBrowser'. to .LinkedList&. In instantiation of 'void LinkedList::insert (int, oonat r6 ) vith r-std : : oxx11: :basistringcahar). : required from here error: cannot convert 'std:exx11::basic_stringseharco 'iode std::exx11::basie stringschar?in initialization rror no matching function for call to Nodestd:cll::basic stringcchar>setlext (std:cll::basic stringcchar) note : candidate : void KodeT>:: setNext (ModeT>*) [with T = sed : : exx11: :basic-stringsehar7] note: no known conversion for arguzent l rom 'stdx1l::basic_stringcchar>t'Nodecstd:el1::basic stringcchar In instantiation of 'T LinkedList::gtEntry (int) const with r= std ::exx1 1: :basicstring1': roquirod from horo error : In instantiation of 'T LinkedListT>::getNodeAt (int) required from .void LinkedList::nsert (Int, const required from here - C:NUsers\Brian53 C:\Users\Brian S6 C:\Users\Bria31 C:\Users\Brian... 31 C:AUsersBrian C: Usors\Brian 40 C:\Users\Bran 153 C:Users\Brian *" - - cannot convert 'std :: cxx11 ::basc stringehar>. to .tode-std:: cxx11: :bass.c strings char> >*. in ratialization oonat with T-std: : oxx11: :basiostring]": T4) [v1th T = std:: .cxx11: :bas c-stringeharJ' - C:Users Brian. 25 C:NUsers\Brian..- 173 COr: cannot convert "stdl1::basic string char>tode std:l1::basicstring char >in assignment C:Users\Brian 75 rror: could not convert curper' from liodesstd: exxii: :basie stringscharto td:cx11::basic stringschar> Build failed: 9 error (s), 7 warning(s) (0 minute(s), 1 second (s))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

50 Tips And Tricks For MongoDB Developers Get The Most Out Of Your Database

Authors: Kristina Chodorow

1st Edition

1449304613, 978-1449304614

More Books

Students also viewed these Databases questions