Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is a C++ Programming question. I am tasked with writing a mock web browser that runs with tabs. It will take a file that

This is a C++ Programming question. I am tasked with writing a mock web browser that runs with tabs. It will take a file that has a list of commands and URLs to show that new tabs are created, deleted or moved. In this case we are supposed to used classes and utilize linkedlists, i have several files: main.cpp, executive.cpp/executive.h, linkedlist.cpp/linkedlist.h, node.cppode.h, tab.cpp/tab.h and webbrowser.cpp/webbrowser.h. All are included in here, however I am having trouble trying to figure out how to write the webbroswer.cpp, the picture of the table outlines each command that needs a function. Please help, I am really at a lost.

1. Table of commands needed for WebBrowser.cpp

image text in transcribed2. Main.cpp

image text in transcribed3. Executive.cpp - This just starts a function to read in the data file NOTE i did not include entire file because those are the slots I am missing for webbroswer

image text in transcribed

4. Executive.h file

image text in transcribed

5. linkedlist.cpp

image text in transcribed

image text in transcribed

image text in transcribed

6. linkedlist.h

image text in transcribed7. Node.cpp

image text in transcribed8. node.h

image text in transcribed9. tab.cpp

image text in transcribedimage text in transcribed10. tab.h

image text in transcribed11. webbrowser.cpp - THIS is what I need help with

image text in transcribed

12. webbroswer.h

image text in transcribed

13. This is a sample of the text file that is used and a sample output

image text in transcribed

Browser Command NEW_TAB Focus-tab # here> Switches focus to the tab at position 1 to total-num-tabs. CLOSE Closes the tab at the indicated position. withfeets MOVE_LEFT camount Moves the tab with focus left amount times. If it reaches the front of the list it stops there. Focus remains on the moved tab. MOVE RIGHT Moves the tab with focus right amount times. If it reaches the back of the list it stops there. Focus remains on the moved tab. Description Creates a new tab at the end of the list of tab and immediately gives it focus. Prints the tab number and current URL history to the screen using the following format: Tab # URL> HISTORY Newest EXIT End the simulation. No more commands need to be read in. #include #include "executive . h" using namespace std; int main (int argc, char argv) if (argc > COMMAND if (COMMAND"NAVIGATE") inFile >URL mBROWSER->navigateTo (URL) ; - else if(COMMAND "HISTORY") LinkedList temp m_BROWSER-copycurrentHistory (temp) cout back else if (COMMAND"FORWARD") m BROWSER->forward ) else if (COMMAND "NEW TAB") else if (COMMAND"FOCUS") else if (COMMAND == "CLOSE " ) #include "linked!ist.h" template LinkedList::LinkedList headPtr (nullptr), itemcount (0) //Deep Copy template LinkedList: :LinkedList (const LinkedList& original) itemcount -original.itemcount; Node ) headPtr->setItem (origChainPtr->getItem)) Node* newChainPtr head?tr; origChainPtrorigchainPtr->getNext) while (origchainPtrnullptr) ItemType nextItemorigChainPtr->getItem Node * newNode Ptr = new Node 1 temType>(next!tem); newChainPtr->setNext (newNodePtr) newChain?tr - newChainPtr->getNext i origchainFtr - origChainPtr->getNext); newChain?tr->setNext (nullptr); //Deconstructor template LinkedList: :~LinkedList ) clear ( /loperator template class ItemType> LinkedList& LinkedList : :operator= (const LinkedList& rhs) if (this !- &rhs) this->clear Node* this->headPtrni this->itemcount++ n new Node(rhs.headPtr->ge t 1 ten()); = return (this); //get current getCurrentSize template int LinkedList::getcurrentsize) const return itemCount; / / isEmpty emplate bool LinkedList::isEmpty() const cpp Open with Drive return itemCount 0; template bool LinkedList: :add (const ItemType& newEntry) Node* newNodeptr = new Node(); newNodePtr->setitem (newEntry) newNodePtr->setNext (headPtr) headPtr newNode?tr; itemCount++; //get pointer to template Node* LinkedList<:getpointerto itemtype target const bool found="false;" node while nullptr if>getItem )) found - true; else cur Ptr curPtr->getNext () ; return curPtr //remove template bool LinkedList::remove (const ItemType&anEntry) Node entryNodePtr-getPointerTo (anEntry); bool canRemove 1 tem_ !isEmpty() && (entryNode Ptr != nullptr); if (canRemoveItem) entryNodePtr->setItem (headPtr->getItem ()) Node * nodeToDelete Ptr headPtr = headPtr->getNext () ; headPtr; nodeToDeletePtr->setNext (nullptr) delete nodeToDeletePtr; nodeToDeletePtr = nullptr; itemCount-- return canRemoveItem; //clear template void LinkedList: :clear ) Node ItemType>* nodeToDeletePtr headPtri while (headPtr != nullptr) head2tr = head2tr->getNext(); nodeToDeletePtr->setNext (nullptr)i delete nodeToDeletePtr; nodeToDeletePtr headPtr; //contains template bool LinkedList::contains (const ItemType& anEntry) const return (getPointerTo(anEntry) != nullptr); #lfnde f LINKE DLIST H #de fine LINKEDLIST H #include "node.h" template class LinkedList private: Node* headPtr; int itemCount; Node ItemType>* getPointerTo (const ItemType& target) const public: LinkedList ) LinkedList (const LinkedList& original); LinkedList); LinkedList& operator=(const LinkedList& original) ; int getCurrentSize () const; bool isEmpty () const; bool add (const ItemType& newEntry); bool remove (const ItemType& anEntry); void clear (); bool contains (const ItemType& anEntry) const; #include #endif "linkedlist.cpp" #include "node . h" template Node: :Node () next (nullptr) template Node: :Node (const ItemType& anItem) item (anItem), next (nullptr) template Node void Node: :setItem (const ItemType& anItem) item anItem; template class ItemType> void Node: : setNext (Node* nextNodePtr) next = nextNodePtr; template void Node: :getItem ) const return item; template Node #include using namespace std; template class Node private: ItemType item; Nodenext; public: Node ) Node (const ItemType& anItem); Node (const ItemType& anItem, Node* nextNodePtr); void setItem (const ItemType& anItem); void setNext (Node ItemType* nextNodePtr); ItemType getItem) const; Node ItemType> getNext() const; #include #endif "node.cpp" #include "tab . h" //constructor Tab: :Tab () m HISTORY = new LinkedList(); m CURRENT = 0; //Deconstructor /avigate to void Tab: :navigateTo (string URL) m HISTORY-add (m HISTORY-getCurrentSize m CURRENT = m HISTORY->getCurrentSize() ; URL) for(int i-0; igetCurrentSize() i++) cout getItem (i) ge t CurrentSize()) m CURRENT++ //back void Tab: :back () if (m CURRENT != 1) m CURRENT-- //current URL void Tab::currentURL ) const return m_HISTORY->getItem (m_CURRENT) //copy current history void Tab: :copyCurrentHistory (LinkedList& destination) for (int = 0 ; i class Tab public: Tab void navigateTo (string URL) void forward O void back) string currentURLO const; int copyCurrentHistory (LinkedList& destination); # endif #include "webbrowserh" WebBrowser::WebBrowser () m HISTORY = new LinkedList(); tab num = 0 //Deconstructor /ew tab nunm //focus //close //move move left //move move right //m_HISTORY //exit #lfndef WEBBROWSER H #define WEBBROWSER H #inc lude "linkedlist.h" #include "node"h" class WebBrowser public: WebBrowser (); /IWebBrowser (); void new tab (); void focus (int tab num); void close (int tab num); void move left (int move) void move right (int move) void history () void exit (); int tab num string m HISTORY ""; //int move #endIf Sample input file NEW_TAB NAVIGATE http://google.com NAVIGATE http://reddit.com NAVGATE http: //facebook. NAVGATE http://myspace.com HISTORY NEW TAB NAVIGATE http://ku.edu NAVIGATE http://youtube.com NAVIGATE http://bing.com BACK HISTORY MOVE LEFT 1 FOCUS 2 BACK NAVIGATE http://amazon.com HISTORY EXIT Output to screen Tab 1 http://google.com http://reddit.com http://facebook.com http://myspace.com Switches focus to the tab at position 1 to total-num-tabs. CLOSE Closes the tab at the indicated position. withfeets MOVE_LEFT camount Moves the tab with focus left amount times. If it reaches the front of the list it stops there. Focus remains on the moved tab. MOVE RIGHT Moves the tab with focus right amount times. If it reaches the back of the list it stops there. Focus remains on the moved tab. Description Creates a new tab at the end of the list of tab and immediately gives it focus. Prints the tab number and current URL history to the screen using the following format: Tab # URL> HISTORY Newest EXIT End the simulation. No more commands need to be read in. #include #include "executive . h" using namespace std; int main (int argc, char argv) if (argc > COMMAND if (COMMAND"NAVIGATE") inFile >URL mBROWSER->navigateTo (URL) ; - else if(COMMAND "HISTORY") LinkedList temp m_BROWSER-copycurrentHistory (temp) cout back else if (COMMAND"FORWARD") m BROWSER->forward ) else if (COMMAND "NEW TAB") else if (COMMAND"FOCUS") else if (COMMAND == "CLOSE " ) #include "linked!ist.h" template LinkedList::LinkedList headPtr (nullptr), itemcount (0) //Deep Copy template LinkedList: :LinkedList (const LinkedList& original) itemcount -original.itemcount; Node ) headPtr->setItem (origChainPtr->getItem)) Node* newChainPtr head?tr; origChainPtrorigchainPtr->getNext) while (origchainPtrnullptr) ItemType nextItemorigChainPtr->getItem Node * newNode Ptr = new Node 1 temType>(next!tem); newChainPtr->setNext (newNodePtr) newChain?tr - newChainPtr->getNext i origchainFtr - origChainPtr->getNext); newChain?tr->setNext (nullptr); //Deconstructor template LinkedList: :~LinkedList ) clear ( /loperator template class ItemType> LinkedList& LinkedList : :operator= (const LinkedList& rhs) if (this !- &rhs) this->clear Node* this->headPtrni this->itemcount++ n new Node(rhs.headPtr->ge t 1 ten()); = return (this); //get current getCurrentSize template int LinkedList::getcurrentsize) const return itemCount; / / isEmpty emplate bool LinkedList::isEmpty() const cpp Open with Drive return itemCount 0; template bool LinkedList: :add (const ItemType& newEntry) Node* newNodeptr = new Node(); newNodePtr->setitem (newEntry) newNodePtr->setNext (headPtr) headPtr newNode?tr; itemCount++; //get pointer to template Node* LinkedList<:getpointerto itemtype target const bool found="false;" node while nullptr if>getItem )) found - true; else cur Ptr curPtr->getNext () ; return curPtr //remove template bool LinkedList::remove (const ItemType&anEntry) Node entryNodePtr-getPointerTo (anEntry); bool canRemove 1 tem_ !isEmpty() && (entryNode Ptr != nullptr); if (canRemoveItem) entryNodePtr->setItem (headPtr->getItem ()) Node * nodeToDelete Ptr headPtr = headPtr->getNext () ; headPtr; nodeToDeletePtr->setNext (nullptr) delete nodeToDeletePtr; nodeToDeletePtr = nullptr; itemCount-- return canRemoveItem; //clear template void LinkedList: :clear ) Node ItemType>* nodeToDeletePtr headPtri while (headPtr != nullptr) head2tr = head2tr->getNext(); nodeToDeletePtr->setNext (nullptr)i delete nodeToDeletePtr; nodeToDeletePtr headPtr; //contains template bool LinkedList::contains (const ItemType& anEntry) const return (getPointerTo(anEntry) != nullptr); #lfnde f LINKE DLIST H #de fine LINKEDLIST H #include "node.h" template class LinkedList private: Node* headPtr; int itemCount; Node ItemType>* getPointerTo (const ItemType& target) const public: LinkedList ) LinkedList (const LinkedList& original); LinkedList); LinkedList& operator=(const LinkedList& original) ; int getCurrentSize () const; bool isEmpty () const; bool add (const ItemType& newEntry); bool remove (const ItemType& anEntry); void clear (); bool contains (const ItemType& anEntry) const; #include #endif "linkedlist.cpp" #include "node . h" template Node: :Node () next (nullptr) template Node: :Node (const ItemType& anItem) item (anItem), next (nullptr) template Node void Node: :setItem (const ItemType& anItem) item anItem; template class ItemType> void Node: : setNext (Node* nextNodePtr) next = nextNodePtr; template void Node: :getItem ) const return item; template Node #include using namespace std; template class Node private: ItemType item; Nodenext; public: Node ) Node (const ItemType& anItem); Node (const ItemType& anItem, Node* nextNodePtr); void setItem (const ItemType& anItem); void setNext (Node ItemType* nextNodePtr); ItemType getItem) const; Node ItemType> getNext() const; #include #endif "node.cpp" #include "tab . h" //constructor Tab: :Tab () m HISTORY = new LinkedList(); m CURRENT = 0; //Deconstructor /avigate to void Tab: :navigateTo (string URL) m HISTORY-add (m HISTORY-getCurrentSize m CURRENT = m HISTORY->getCurrentSize() ; URL) for(int i-0; igetCurrentSize() i++) cout getItem (i) ge t CurrentSize()) m CURRENT++ //back void Tab: :back () if (m CURRENT != 1) m CURRENT-- //current URL void Tab::currentURL ) const return m_HISTORY->getItem (m_CURRENT) //copy current history void Tab: :copyCurrentHistory (LinkedList& destination) for (int = 0 ; i class Tab public: Tab void navigateTo (string URL) void forward O void back) string currentURLO const; int copyCurrentHistory (LinkedList& destination); # endif #include "webbrowserh" WebBrowser::WebBrowser () m HISTORY = new LinkedList(); tab num = 0 //Deconstructor /ew tab nunm //focus //close //move move left //move move right //m_HISTORY //exit #lfndef WEBBROWSER H #define WEBBROWSER H #inc lude "linkedlist.h" #include "node"h" class WebBrowser public: WebBrowser (); /IWebBrowser (); void new tab (); void focus (int tab num); void close (int tab num); void move left (int move) void move right (int move) void history () void exit (); int tab num string m HISTORY ""; //int move #endIf Sample input file NEW_TAB NAVIGATE http://google.com NAVIGATE http://reddit.com NAVGATE http: //facebook. NAVGATE http://myspace.com HISTORY NEW TAB NAVIGATE http://ku.edu NAVIGATE http://youtube.com NAVIGATE http://bing.com BACK HISTORY MOVE LEFT 1 FOCUS 2 BACK NAVIGATE http://amazon.com HISTORY EXIT Output to screen Tab 1 http://google.com http://reddit.com http://facebook.com http://myspace.com

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

More Books

Students also viewed these Databases questions

Question

Identify the interacting elements of cost-volume-profit analysis.

Answered: 1 week ago

Question

What does this public think about this issue?

Answered: 1 week ago

Question

What benefits can you offer this public?

Answered: 1 week ago

Question

How free does this public see itself to act on this issue?

Answered: 1 week ago