Question
Using the given Page.h and Page.cpp, construct a main.cpp that does the following: ------------------Page.h------------------ using namespace std; class Page{ string url; int visits; Page* links[3];
Using the given Page.h and Page.cpp, construct a main.cpp that does the following:
------------------Page.h------------------
using namespace std;
class Page{ string url; int visits; Page* links[3]; int usedLinks; public: Page(); Page(string urlValue); string getURL(); int getNumLinks(); Page* getRandomLink(); void addLink(Page* other); void visit(); int getNumVisits(); };
------------------Page.cpp------------------
#include
using namespace std;
Page::Page(){ url = ""; visits = 0; usedLinks = 0; for(int i=0;i
Page::Page(string urlValue) : Page(){ url = urlValue; } string Page::getURL(){ return url; } int Page::getNumLinks(){ return usedLinks; } Page* Page::getRandomLink(){ if(usedLinks==0) return NULL; int i = (rand()%usedLinks); return links[i]; } void Page::addLink(Page* other){ if(usedLinks==3) return; links[usedLinks++] = other; } void Page::visit(){ visits++; } int Page::getNumVisits(){ return visits; }
Main.cpp (15%) Your main file should have code to run the following simulation: Build a group of 4 pages that are setup like the picture below. page1 url : http://page1 visits: 0 numLinks: 2 links: page4 page2 url : http://page2 visits: 0 numLinks: 1 links: 0 url : http://page4 visits: 0 numLinks: 2 links: 0 page3 url : http://page3 visits : 0 numLinks: 1 links: 0 Note that we are not using all the possible links within each page. Unused slots (nullptrs) are shown with ... Starting on page1, do the following 10,000 times: O Select a new current page by doing the following: Pick a random number between 1-100. . If the current page has no links, or the number if 15 or less, change the current page to one of the four pages selected at random (equal chance for each). Otherwise ask the current page for a random link and make that the new current page. o Visit that page After doing the random surfing, for each page, print out its name and what percentage of the 10,000 total visits that were to this page. Main.cpp (15%) Your main file should have code to run the following simulation: Build a group of 4 pages that are setup like the picture below. page1 url : http://page1 visits: 0 numLinks: 2 links: page4 page2 url : http://page2 visits: 0 numLinks: 1 links: 0 url : http://page4 visits: 0 numLinks: 2 links: 0 page3 url : http://page3 visits : 0 numLinks: 1 links: 0 Note that we are not using all the possible links within each page. Unused slots (nullptrs) are shown with ... Starting on page1, do the following 10,000 times: O Select a new current page by doing the following: Pick a random number between 1-100. . If the current page has no links, or the number if 15 or less, change the current page to one of the four pages selected at random (equal chance for each). Otherwise ask the current page for a random link and make that the new current page. o Visit that page After doing the random surfing, for each page, print out its name and what percentage of the 10,000 total visits that were to this pageStep 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