Introduction Modern browsers keep track of browsing history which allows users t
ID: 3597320 • Letter: I
Question
Introduction
Modern browsers keep track of browsing history which allows users to recall previously visited web pages using the back arrow button.. When a user navigates back to a previous web page, they also have the option to navigate forward in the navigation history using the forward arrow button. However, if the user navigates back to a previous page and then goes to a new web page, all web pages that previously could be accessed with the forward arrow button are discarded. This behavior is well suited for Linked Lists. In this project you will write C++ code to model this behavior.
For a good video overview of this, check out this link.
In addition, when asked, your program should respond with every web page visited and when it was visited. Since we do not know how many sites the user will visit, we will have a second Linked List that will keep track of every site visited.
You are given a simple text file of a user’s browsing history containing their actions: back, forward, or new. If their action is listed as new, it will be followed with a web address. Simulate their browsing history based on this text file.
Objective
You are given partial implementations of two classes. Webpage is a class that holds both the web page url as well as the time it was first visited. The time visited is the number of seconds from the UNIX epoch, 00:00 Jan 1, 1970 UTC. C++ has a variable type that can handle this, named time_t.
BrowserHistory is where the bulk of your work will be done. BrowserHistory stores both a linked list representation of the user’s navigation history, as well as an overall history of all sites they’ve visited. It will be able to read the history from a text file.
The text file will have 3 basic commands: new, back, and forward. Back and forward will simulate the user pressing the back and forward arrow buttons of their browser. New will be followed by the web page’s url and the time the site was visited.
You are to complete the implementations of these classes, adding public/private member variables and functions as needed.
You are encouraged to use the C++ Standard Library containers (such as std::list, and std::list::iterator) for this project.
Your code is tested in the provided main.cpp.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Can someone please help me with browserhistory.h it is completed using a stringnode. but i cannot finish CPP
I need help on the browserHistory.h and browserHistory.cpp the code for these two are given just need to fill in the misssing things in the code. This is what i have--------------------------------
//webPage.h
#pragma once
#include
#include
using namespace std;
class Webpage {
public:
Webpage();
Webpage(const string& webpageURL, const time_t& timeVisited);
string getURL();
time_t getTime();
private:
string URL;
time_t timer;
};
======================================================================
//webPage.cpp
#include "Webpage.h"
Webpage::Webpage() {
URL= "";
timer = time(NULL);
}
Webpage::Webpage(const string& webpageURL, const time_t& timeVisited) {
URL = webpageURL;
timer = timeVisited;
}
string Webpage::getURL() {
return(URL);
}
time_t Webpage::getTime() {
return timer;
}
============================================================================
//browserHistory.h
#pragma once
#include
#include
#include
#include
#include
#include "Webpage.h"
using namespace std;
class StringNode {
private:
string data;
StringNode *next;
StringNode *prev;
friend class BrowserHistory;
};
public:
class BrowserHistory {
public:
BrowserHistory();
~BrowserHistory();
void visitSite(Webpage newSite);
string back();
string forward();
void readHistory(string fileName);
string getURL();
size_t getNavSize();
void printBackSites();
void printForwardSites();
void printFullHistory();
private:
int n;
string URL;
size_t NavSize;
StringNode *head; //a pointer that points to the head
StringNode *tailr;
StringNode *cursor;
// Add private member variables for your class along with any
// other variables required to implement the public member functions
// TO BE COMPLETED
};
================================================================================
//browserHistory.cpp
#include "BrowserHistory.h"
BrowserHistory::BrowserHistory() {
// TO BE COMPLETED
I need help to completed this file. i need the default completed.
}
BrowserHistory::~BrowserHistory() {
// TO BE COMPLETED
what am i supposed to delete?
}
void BrowserHistory::visitSite(Webpage newSite) {
// TO BE COMPLETED
once files are opened in readHistory i load data here.
}
string BrowserHistory::getURL() {
// TO BE COMPLETED
return URL; is that correct or do i put return this->URL;
}
size_t BrowserHistory::getNavSize() {
// TO BE COMPLETED
}
string BrowserHistory::back() {
what do i need to do here? back();
// TO BE COMPLETED
}
string BrowserHistory::forward() {
// TO BE COMPLETED
}
void BrowserHistory::readHistory(string fileName) {
// TO BE COMPLETED
}
void BrowserHistory::printBackSites() {
how do i print the data?
// TO BE COMPLETED
}
void BrowserHistory::printForwardSites() {
// TO BE COMPLETED
}
void BrowserHistory::printFullHistory() {
// TO BE COMPLETED
}
=====================================================================
//main.cpp
#include
#include
#include
#include
#include
#include "Webpage.h"
#include "BrowserHistory.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT THIS FILE (except for your own testing)
// CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS
////////////////////////////////////////////////////////////////////////////////
template
bool testAnswer(const string &nameOfTest, const T& received, const T& expected) {
if (received == expected) {
cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;
return true;
}
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
template
bool testArrays(const string& nameOfTest, const T& received, const T& expected, const int& size) {
for (int i = 0; i < size; i++) {
if (received[i] != expected[i]) {
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
}
cout << "PASSED " << nameOfTest << ": expected and received matching arrays" << endl;
return true;
}
int main() {
// Test only Webpage class
Webpage testPage01("http://www.google.com", 1506134400);
testAnswer("Webpage01.getURL() test", testPage01.getURL(), string("http://www.google.com"));
testAnswer("Webpage01.getTime() test", testPage01.getTime(), time_t(1506134400));
Webpage testPage02("http://twitter.com", 1506134420);
testAnswer("Webpage02.getURL() test", testPage02.getURL(), string("http://twitter.com"));
testAnswer("Webpage02.getTime() test", testPage02.getTime(), time_t(1506134420));
Webpage testPage03("http://stackoverflow.com", 1506134440);
testAnswer("Webpage03.getURL() test", testPage03.getURL(), string("http://stackoverflow.com"));
testAnswer("Webpage03.getTime() test", testPage03.getTime(), time_t(1506134440));
// Test BrowserHistory class
BrowserHistory testHistory;
testHistory.visitSite(testPage01);
testAnswer("BrowserHistory.getNavSize()", testHistory.getNavSize(), size_t(1));
testAnswer("BrowserHistory.getURL()", testHistory.getURL(), string("http://www.google.com"));
testHistory.visitSite(testPage02);
testAnswer("BrowserHistory.getNavSize()", testHistory.getNavSize(), size_t(2));
testAnswer("BrowserHistory.getURL()", testHistory.getURL(), string("http://twitter.com"));
// Test BrowserHistory navigation
testAnswer("BrowserHistory.back()", testHistory.back(), string("http://www.google.com"));
testAnswer("BrowserHistory.getURL()", testHistory.getURL(), string("http://www.google.com"));
testAnswer("BrowserHistory.forward()", testHistory.forward(), string("http://twitter.com"));
testHistory.back();
testHistory.visitSite(testPage03);
testAnswer("BrowserHistory.getNavSize()", testHistory.getNavSize(), size_t(2));
testAnswer("BrowserHistory.getURL()", testHistory.getURL(), string("http://stackoverflow.com"));
// Test BrowserHistory reading from a file
BrowserHistory desktop;
desktop.readHistory("desktop.txt");
testAnswer("BrowserHistory.getNavSize()", desktop.getNavSize(), size_t(3));
testAnswer("BrowserHistory.getURL()", desktop.getURL(),
string("https://en.wikipedia.org/wiki/International_Space_Station"));
desktop.readHistory("mobile.txt");
testAnswer("BrowserHistory.getNavSize()", desktop.getNavSize(), size_t(7));
testAnswer("BrowserHistory.getURL()", desktop.getURL(), string("http://www.binomial.info/"));
// Test Back and Forward Again
testAnswer("BrowserHistory.back() 02", desktop.back(), string("https://twitter.com/sehulrburt"));
desktop.forward();
testAnswer("BrowserHistory.forward() 02", desktop.forward(), string("https://sites.google.com/site/richgel99/"));
desktop.back();
// Test BrowserHistory full history
cout << " Printing Back Sites: ";
desktop.printBackSites();
cout << " Printing Forward Sites: ";
desktop.printForwardSites();
cout << " Printing Full History: ";
desktop.printFullHistory();
system("pause ");
return 0;
}
Explanation / Answer
#pragma once
#include
#include
using namespace std;
class Webpage {
public:
Webpage();
Webpage(const string& webpageURL, const time_t& timeVisited);
string getURL();
time_t getTime();
private:
string URL;
time_t timer;
};
======================================================================
//webPage.cpp
#include "Webpage.h"
Webpage::Webpage() {
URL= "";
timer = time(NULL);
}
Webpage::Webpage(const string& webpageURL, const time_t& timeVisited) {
URL = webpageURL;
timer = timeVisited;
}
string Webpage::getURL() {
return(URL);
}
time_t Webpage::getTime() {
return timer;
}
============================================================================
//browserHistory.h
#pragma once
#include
#include
#include
#include
#include
#include "Webpage.h"
using namespace std;
class StringNode {
private:
string data;
StringNode *next;
StringNode *prev;
friend class BrowserHistory;
};
public:
class BrowserHistory {
public:
BrowserHistory();
~BrowserHistory();
void visitSite(Webpage newSite);
string back();
string forward();
void readHistory(string fileName);
string getURL();
size_t getNavSize();
void printBackSites();
void printForwardSites();
void printFullHistory();
private:
int n;
string URL;
size_t NavSize;
StringNode *head; //a pointer that points to the head
StringNode *tailr;
StringNode *cursor;
// Add private member variables for your class along with any
// other variables required to implement the public member functions
// TO BE COMPLETED
};
================================================================================
//browserHistory.cpp
#include "BrowserHistory.h"
BrowserHistory::BrowserHistory() {
// TO BE COMPLETED
I need help to completed this file. i need the default completed.
}
BrowserHistory::~BrowserHistory() {
// TO BE COMPLETED
what am i supposed to delete?
}
void BrowserHistory::visitSite(Webpage newSite) {
// TO BE COMPLETED
once files are opened in readHistory i load data here.
}
string BrowserHistory::getURL() {
// TO BE COMPLETED
return URL; is that correct or do i put return this->URL;
}
size_t BrowserHistory::getNavSize() {
// TO BE COMPLETED
}
string BrowserHistory::back() {
what do i need to do here? back();
// TO BE COMPLETED
}
string BrowserHistory::forward() {
// TO BE COMPLETED
}
void BrowserHistory::readHistory(string fileName) {
// TO BE COMPLETED
}
void BrowserHistory::printBackSites() {
how do i print the data?
// TO BE COMPLETED
}
void BrowserHistory::printForwardSites() {
// TO BE COMPLETED
}
void BrowserHistory::printFullHistory() {
// TO BE COMPLETED
}
=====================================================================
//main.cpp
#include
#include
#include
#include
#include
#include "Webpage.h"
#include "BrowserHistory.h"
using namespace std;
////////////////////////////////////////////////////////////////////////////////
// DO NOT EDIT THIS FILE (except for your own testing)
// CODE WILL BE GRADED USING A MAIN FUNCTION SIMILAR TO THIS
////////////////////////////////////////////////////////////////////////////////
template
bool testAnswer(const string &nameOfTest, const T& received, const T& expected) {
if (received == expected) {
cout << "PASSED " << nameOfTest << ": expected and received " << received << endl;
return true;
}
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
template
bool testArrays(const string& nameOfTest, const T& received, const T& expected, const int& size) {
for (int i = 0; i < size; i++) {
if (received[i] != expected[i]) {
cout << "FAILED " << nameOfTest << ": expected " << expected << " but received " << received << endl;
return false;
}
}
cout << "PASSED " << nameOfTest << ": expected and received matching arrays" << endl;
return true;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.