Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- struct HistoryEntry {
- int date;
- char* URL;
- };
- class BrowserHistory {
- public:
- BrowserHistory();
- BrowserHistory(int N);
- BrowserHistory operator= (BrowserHistory const&);
- ~BrowserHistory();
- void addSite();
- void addSite(const HistoryEntry&);
- void printAll();
- int countSitesMonth(int month);
- int mostVisitedMonth();
- void DeleteLastSite();
- BrowserHistory concat2(BrowserHistory, BrowserHistory);
- private:
- HistoryEntry* history;
- int siteCounter;
- int siteLimit;
- };
- BrowserHistory::BrowserHistory() {
- history->date = NULL;
- history->URL = NULL;
- }
- BrowserHistory::BrowserHistory(int N) {
- history = new HistoryEntry[N];
- for (int i = 0; i < N; i++) {
- history[i].date = 0;
- history[i].URL = NULL;
- siteCounter = 0;
- }
- siteLimit = N;
- }
- BrowserHistory BrowserHistory::operator=(BrowserHistory const &other) {
- if (this != &other) {
- for (int i = 0; i < other.siteCounter; i++) {
- history[i] = other.history[i];
- siteCounter = other.siteCounter;
- }
- }
- return *this;
- }
- BrowserHistory::~BrowserHistory() {
- delete[] history;
- }
- void BrowserHistory::addSite() {
- if (++siteCounter < siteLimit) {
- cout << "Month: ";
- cin >> history[siteCounter].date;
- cout << "URL: ";
- cin >> history[siteCounter].URL;
- siteCounter++;
- }
- else {
- cout << "The history is full!" << endl;
- }
- }
- void BrowserHistory::addSite(const HistoryEntry& x) {
- if (++siteCounter < siteLimit) {
- history[siteCounter].date = x.date;
- history[siteCounter].URL = x.URL;
- siteCounter++;
- }
- else {
- cout << "The history is full!" << endl;
- }
- }
- void BrowserHistory::printAll() {
- for (int i = 0; i < siteCounter; i++) {
- cout << history[i].date << " " << history[i].URL << endl;
- }
- }
- int BrowserHistory::countSitesMonth(int month) {
- int localCount = 0;
- for (int i = 0; i < siteCounter; i++) {
- if (history[i].date == month) {
- localCount++;
- }
- }
- return localCount;
- }
- int BrowserHistory::mostVisitedMonth() {
- int months[12] = { 0,0,0,0,0,0,0,0,0,0,0,0 };
- for (int i = 0; i < siteCounter; i++) {
- months[history[i].date - 1]++;
- }
- int max = 0;
- for (int i = 0; i < 12; i++) {
- if (months[i] > max) {
- max = i+1;
- }
- }
- return max;
- }
- void BrowserHistory::DeleteLastSite() {
- siteCounter--;
- }
- BrowserHistory BrowserHistory::concat2(BrowserHistory left, BrowserHistory right) {
- BrowserHistory newHistory(left.siteCounter+right.siteCounter);
- for (int i = 0; i < left.siteCounter; i++) {
- newHistory.history[i] = left.history[i];
- }
- int j = 0;
- for (int i = left.siteCounter; i < left.siteCounter + right.siteCounter; i++){
- newHistory.history[i] = right.history[j];
- j++;
- }
- return newHistory;
- }
- int main()
- {
- BrowserHistory mine;
- mine.addSite();
- //mine.addSite(5, "google.bg");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement