-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
125 lines (107 loc) · 2.7 KB
/
Copy pathmain.cpp
File metadata and controls
125 lines (107 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class SimpleBrowser
{
private:
string webposition[100]; //array
int currentweb;
int total_history;
public:
SimpleBrowser()
{
currentweb = 0;
total_history = 0;
webposition[0] = "Home Page";
}
void openNewPage(string name)
{
if (total_history >= 99)
{
cout << "\nALERT:\a History full!\n";
return;
}
if (name.length() < 8 || name.substr(0, 8) != "https://")
{
name = "https://" + name;
}
total_history++;
webposition[total_history] = name;
currentweb = total_history;
cout << "\nOPENED: " << webposition[currentweb] << "\n";
string command = "start \"\" \"" + name + "\"";
system(command.c_str());
}
void backButton()
{
if (currentweb == 0)
{
cout << "\nALERT:\a Already at Home Page!\n";
return;
}
cout << "\n " << webposition[currentweb] << " closed.\n ";
currentweb--;
cout << "Now at: " << webposition[currentweb] << "\n";
}
void showHistory()
{
cout << "\n--- BROWSER HISTORY ---\n";
for (int i = 0; i <= total_history; i++)
{
if (i == currentweb)
{
cout << i << ". " << webposition[i] << " <--- (Current Page)\n";
} else
{
cout << i << ". " << webposition[i] << "\n";
}
}
}
};
int main()
{
SimpleBrowser chrome;
int operation;
string userWebsite;
while (true)
{
cout << "\n press 1 for new website: ";
cout << "\n press 2 for back: ";
cout << "\n press 3 for search history: ";
cout << "\n Press 4 for exit: ";
cout << "\nPRESS: ";
if (!(cin >> operation))
{
cout << "\nInvalid Input! Please enter a number.\n";
cin.clear();
cin.ignore(10000, '\n');
continue;
}
cin.ignore();
if (operation == 1)
{
cout << "Enter Website URL: ";
getline(cin, userWebsite);
chrome.openNewPage(userWebsite);
}
else if (operation == 2)
{
chrome.backButton();
}
else if (operation == 3)
{
chrome.showHistory();
}
else if (operation == 4)
{
cout << "\nClosing browser!\n";
break;
}
else
{
cout << "\nIncorrect option!\n";
}
}
return 0;
}