0% found this document useful (0 votes)
5 views3 pages

Web Browser Stack and Queue Implementation

The document contains a C++ implementation of a simple web browser class that allows users to visit pages, navigate back and forth, view browsing history, and clear history. It utilizes a stack for the back navigation and a queue for the forward navigation. The main function creates an instance of the WebBrowser class and runs the browser interface for user interaction.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Web Browser Stack and Queue Implementation

The document contains a C++ implementation of a simple web browser class that allows users to visit pages, navigate back and forth, view browsing history, and clear history. It utilizes a stack for the back navigation and a queue for the forward navigation. The main function creates an instance of the WebBrowser class and runs the browser interface for user interaction.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//STACK&QUEUE

#include <iostream>
#include <stack>
#include <queue>

using namespace std;

class WebBrowser
{
private:
stack<string> gobackStack;
queue<string> forwardQueue;
string currentPage;
public:
WebBrowser()
{
currentPage = "";
}

void visitPage(string page)


{
if(![Link]())
{
[Link](currentPage);
}
currentPage = page;
while(![Link]())
{
[Link](currentPage);
}
}

void gotoPreviousPage()
{
if(![Link]())
{
[Link](currentPage);
currentPage = [Link]();
[Link]();
}
else{
cout << "\nCannot Go Back to Previous Page. No more pages available.\
n";
}
}

void gotoNextPage()
{
if(![Link]())
{
[Link](currentPage);
currentPage = [Link]();
[Link]();
}
else{
cout << "\nCannot Next Page. No more pages available.\n";
}
}
void displayBrowsingHistory()
{
cout << "\nBrowsing History:\n";
stack<string> browsingHistory = gobackStack;
while(![Link]())
{
cout << [Link]() << endl;
[Link]();
}
}

void clearBrowsingHistory()
{
if([Link]() && [Link]())
{
cout << "\nThere's nothing to clear.\nNo Browsing History.......\n";
}
else{
while(![Link]())
{
[Link]();
}
while(![Link]())
{
[Link]();
}
}
}

void displayCurrentPage()
{
if(![Link]())
{
cout << "\nCurrent Page: " << currentPage << endl;
}
else{
cout << "\nNo visited Pages available.\n";
}
}

void displayMenu()
{
cout << "\n---------------WEB BROWSER----------------\n";
displayCurrentPage();

cout << "\n1. Visit New Page\n2. Go to Previous Page\n3. Go to Next Page\
n4. View Browsing History\n5. Clear Browsing History\n6. Exit Browser\n";
}

void runBrowser()
{
int choice;
string URL;
bool condi = true;

while(condi){
displayMenu();
cout << "\nEnter Choice (1-6): ";
cin >> choice;
[Link]();

switch(choice)
{
case 1:
cout << "\nEnter URL or Page Name: ";
getline(cin, URL);
visitPage(URL);
break;
case 2:
gotoPreviousPage();
break;
case 3:
gotoNextPage();
break;
case 4:
displayBrowsingHistory();
break;
case 5:
clearBrowsingHistory();
break;
case 6:
cout << "\nLeaving Browser..........\nGoodbye........\n";
condi = false;
break;
default:
cout << "\nInvalid Input. Enter number from 1-6.\n";
}
}
}
};

int main()
{
WebBrowser browser;
[Link]();
return 0;
}

You might also like