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

Simple C++ Browser Simulation Code

The document contains a C++ implementation of a simple web browser class that manages browsing history using two stacks: one for the history of visited pages and another for pages that can be navigated forward to. The browser allows users to visit pages, go back and forth in their history, view their browsing history, and clear it. The main function creates an instance of the browser and runs it, providing a user interface for 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

Simple C++ Browser Simulation Code

The document contains a C++ implementation of a simple web browser class that manages browsing history using two stacks: one for the history of visited pages and another for pages that can be navigated forward to. The browser allows users to visit pages, go back and forth in their history, view their browsing history, and clear it. The main function creates an instance of the browser and runs it, providing a user interface for 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

\\DAS\Stack\Practice\code

#include <iostream>
#include <stack>

using namespace std;

class Browser
{
private:
stack<string> historyStack;
stack<string> forwardStack;
string currentPage;
public:
Browser() {currentPage = "";}

void visitPage(string page)


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

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

void gotoPreviousPage()
{
if(![Link]())
{
[Link](currentPage);
currentPage = [Link]();
[Link]();
}
else{
cout << "\nCannot go back to page. No page available.\n";
}
}

void gotoNextPage()
{
if(![Link]())
{
[Link](currentPage);
currentPage = [Link]();
[Link]();
}
else{
cout << "\nCannot next page. No page available.\n";
}
}

void displayBrowsingHistory()
{
cout << "\nBrowsing History:\n";
stack<string> browsingHistory = historyStack;
while(![Link]())
{
cout << [Link]() << endl;
[Link]();
}
}

void clearBrowsingHistory()
{
if([Link]() && [Link]())
{
cout << "\nNo Browsing History........\n";
}
else{
while(![Link]())
{
[Link]();
}
while(![Link]())
{
[Link]();
}
currentPage = "";
cout << "\nHistory cleared.\n";
}
}

void displayCurrentPage()
{
cout << currentPage << endl;
}

void displayHomeBrowser()
{
cout << "\n***********WEB BROWSER**************\n";
cout << "\nCurrent Page: " << currentPage << endl;
cout << "\n1. Visit Page\n2. Go back to Previous Page\n3. Go to Next Page\
n4. View Browsing History\n5. Clear Browsing History\n6. Exit Browser\n";
}

void runBrowser()
{
bool condi = true;
while(condi){
displayHomeBrowser();
int choice;
string URL;
cout << "\nEnter Choice: ";
cin >> choice;
[Link]();
switch(choice)
{
case 1:
cout << "\nEnter URL or Page Name:\n";
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..........\n";
condi = false;
break;
default:
cout << "\nInvalid Choice. Enter a number between 1-6.\n";
}
}
}
};

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

You might also like