Question
What will be browserhistory.cpp in order for the code to run? #ifndef browserhistory_h #define browserhistory_h #include #include using namespace std; class BrowserHistory { private :
What will be browserhistory.cpp in order for the code to run?
#ifndef browserhistory_h
#define browserhistory_h
#include
#include
using namespace std;
class BrowserHistory
{
private:
// A stack of strings - these are the only variables you need!
// See http://www.cplusplus.com/reference/stack/stack/ for class reference, methods, etc.
stack
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.
// so you should add the new link to the stack
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.
// check the stack methods and see if there is any method that can help you
int past_url_count();
};
#endif /* browserhistory_h */
main.cpp
#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)]
BrowserHistory bh("http://google.com");
cout << "Starting at " << bh.current_url() << "." << endl;
cout << "Choose (B)ack, 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.size() > 0)
{
bh.go_to_url(line);
cout << " Now at " << bh.current_url() << endl;
}
}
exit(0);
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started