Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; class BrowserHistory { private: // Two stacks of strings - these are the only variables you need! // See http://www.cplusplus.com/reference/stack/stack/

#include  #include  using namespace std; class BrowserHistory { private: // Two stacks of strings - these are the only variables you need! // See http://www.cplusplus.com/reference/stack/stack/ for class reference. stack past; stack future; public: // Creates a new browser history with only one page visited: default_url BrowserHistory(string default_url); // Returns the current page. string current_url(); // Moves the browser to a new page url via, // e.g., clicking a link, typing into the address bar, etc. // I would suggest that you put the new urls in the past stack. // One thing you should notice, when the new url comes, all the future urls are gone. //For example, if past stack has  and future url has , // when I enter youtube, LinkedIn is not the youtube's future url anymore. Pressing forward should not return anything void go_to_url(string url); // Moves back (into the past) by one url. // // If there is no past url to move to, does nothing. void back(); // Returns whether there is a url in the past, // i.e. whether the back button can be pushed. // Hint: past.empty() returns a boolean which tell you if the stack is empty or not bool can_go_back(); // Returns how many urls are in the past, // i.e. how many times in a row the back button could be pushed. int past_url_count(); // Moves forward (into the future) by one url. // // If there is no future url to move to, does nothing. void forward(); // Returns whether there is a url in future, // i.e. whether the future button can be pushed. // Hint: future.empty() returns a boolean which tell you if the stack is empty or not bool can_go_forward(); // Returns how many urls are in the future, // i.e. how many times in a row the forward button could be pushed. int future_url_count(); };
#include  #include "browserhistory.h" int main() { // Comments below indicate the current (expected) state of the history. // Example: [url1, url2, url3, (url4), url5, url6] // The urls are listed oldest to newest from left to right, // and the url in parentheses is the current url. // History: [(google.com)] //Try the following command to check if your code is working properly: // Facebook , output: Facebook //LinkedIn , output: LinkedIn //B , outout: Facebook //F , output: LinkedIn //B, outout: Facebook // Youtube, output: youtube //B, output: Facebook (If you are getting LinkedIn here, check your go_to_url function. Make sure you empty the future stack) BrowserHistory bh("http://google.com"); cout << "Starting at " << bh.current_url() << "." << endl; cout << "Choose (B)ack, (F)orward, or enter a url to go to." << endl; string line; while (cin) { string line; getline(cin, line); if (line == "B") { if (bh.can_go_back()) { bh.back(); cout << " Now at " << bh.current_url() << endl; } else cout << " Cannot go back." << endl; } else if (line == "F") { if (bh.can_go_forward()) { bh.forward(); cout << " Now at " << bh.current_url() << endl; } else cout << " Cannot go forward." << endl; } else if (line.size() > 0) { bh.go_to_url(line); cout << " Now at " << bh.current_url() << endl; } } exit(0); } 

Please implement all the functions of BrowserHistory.h and submit BrowserHistory.cpp

MUST BE IN c++

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

OpenStack Trove

Authors: Amrith Kumar, Douglas Shelley

1st Edition

1484212215, 9781484212219

More Books

Students also viewed these Databases questions