Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

//browser_history.h #ifndef BROWSERHISTORY_H #define BROWSERHISTORY_H #include #include using namespace std; class BrowserHistory { public: BrowserHistory(string default_url); string current_url(); void go_to_url(string url); void back(); bool can_go_back();

//browser_history.h

#ifndef BROWSERHISTORY_H #define BROWSERHISTORY_H

#include #include

using namespace std;

class BrowserHistory { public: BrowserHistory(string default_url); string current_url(); void go_to_url(string url);

void back(); bool can_go_back(); int past_url_count(); void forward(); bool can_go_forward(); int future_url_count();

private: stack past; stack future; };

#endif

//********************************************************************************************

//main.cpp

#include #include #include #include "browser_history.h"

int main() { // Back: [] // Current: google // Forward: [] BrowserHistory bh("http://google.com"); assert(bh.current_url() == "http://google.com"); assert(!bh.can_go_back() && !bh.can_go_forward()); assert(bh.past_url_count() == 0 && bh.future_url_count() == 0); cout << "30% earned." << endl;

// Back: [google, netflix, amazon] // Current: utrgv // Forward: [] bh.go_to_url("http://netflix.com"); bh.go_to_url("http://amazon.com"); bh.go_to_url("http://utrgv.edu"); assert(bh.current_url() == "http://utrgv.edu"); cout << "40% earned." << endl; assert(bh.can_go_back() && !bh.can_go_forward()); cout << "50% earned." << endl; assert(bh.past_url_count() == 3 && bh.future_url_count() == 0); cout << "55% earned." << endl; // Back: [google] // Current: netflix // Forward: [amazon, utrgv] bh.back(); bh.back(); assert(bh.current_url() == "http://netflix.com"); cout << "65% earned." << endl; assert(bh.can_go_back() && bh.can_go_forward()); cout << "70% earned." << endl; assert(bh.past_url_count() == 1 && bh.future_url_count() == 2); cout << "75% earned." << endl;

// Back: [google, netflix] // Current: amazon // Forward: [utrgv] bh.forward(); assert(bh.current_url() == "http://amazon.com"); cout << "80% earned." << endl; assert(bh.can_go_back() && bh.can_go_forward()); cout << "85% earned." << endl; assert(bh.past_url_count() == 2 && bh.future_url_count() == 1); cout << "90% earned." << endl;

// Back: [google, netflix, amazon] // Current: youtube // Forward: [] bh.go_to_url("http://youtube.com"); assert(bh.current_url() == "http://youtube.com"); assert(bh.can_go_back() && !bh.can_go_forward()); assert(bh.past_url_count() == 3 && bh.future_url_count() == 0); bh.forward(); // Can't go forward any more, so do nothing assert(bh.current_url() == "http://youtube.com"); cout << "95% earned." << endl; bh.back(); bh.back(); bh.back(); // Back: [] // Current: google // Forward: [netflix, amazon, youtube] assert(bh.current_url() == "http://google.com"); bh.back(); // Can't go back any more, so do nothing assert(bh.current_url() == "http://google.com"); cout << "100% earned." << endl; }

//Objective

/*

Every modern web browser has the backward/forward feature that enables users to traverse the sequence of webpages visited. Pressing the Back button revisits the previous webpage, while pressing the Forward button returns to the most recently visited webpage. Implement this feature using just two stacks.

Create a new C++ source file named browser history.cpp that implements the class declared in browser history.h, so that main.cpp and browser history.cpp compile into a program that runs with no failed assertions.

*/

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions