-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternet Service Provider Package Suggestion Program.cpp
294 lines (253 loc) · 5.18 KB
/
Internet Service Provider Package Suggestion Program.cpp
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include<iostream>
#include <string>
using namespace std;
class customer
{
protected:
int i_hrs;
float i_cost;
string c_name;
float diskspace;
float add_hrs_rate;
int add_hrs;
public:
virtual float computebill();
virtual void display();
customer();
~customer();
customer(string n, float hrs);
};
void customer::display()
{
system("cls");
cout << "\ndear " << c_name << ", customer plan is most suitable for you.";
cout << "\n--------details of customer plan--------";
cout << "\ninitial hrs:" << i_hrs;
cout << "\ninitial cost:" << i_cost;
cout << "\n additional rate(dollars per hour):" << add_hrs_rate;
cout << "\n disk space limit(mb):" << diskspace;
cout << "\n charge per dialup connection: none";
cout << "\n expected bill:" << this->computebill();
}
customer::customer()
{
i_hrs = 0;
i_cost = 0;
add_hrs_rate = 0;
diskspace = 0;
c_name = "";
add_hrs = 0;
}
customer::~customer()
{
cout << "\n customer deleted...\n";
}
customer::customer(string n, float hrs)
{
i_hrs = 4;
i_cost = 10;
add_hrs_rate = 4.00;
diskspace = 1;
c_name = n;
int temp = hrs - i_hrs;
if (temp > 0)
{
add_hrs = temp;
}
else
{
add_hrs = 0;
}
}
float customer::computebill()
{
float bill;
bill = (add_hrs * add_hrs_rate) + i_cost;
return bill;
}
class hacker :public customer
{
public:
hacker(string n, float hrs);
~hacker();
virtual float computebill() override;
virtual void display() override;
};
void hacker::display()
{
system("cls");
cout << "\ndear " << c_name << ", hacker plan is most suitable for you.";
cout << "\n--------details of hacker plan--------";
cout << "\ninitial hrs:" << i_hrs;
cout << "\ninitial cost:" << i_cost;
cout << "\n additional rate(dollars per hour):" << add_hrs_rate;
cout << "\n disk space limit(mb):" << diskspace;
cout << "\n charge per dialup connection: none";
cout << "\n expected bill:" << this->computebill();
}
hacker::hacker(string n, float hrs)
{
i_hrs = 10;
i_cost = 20;
add_hrs_rate = 2.50;
diskspace = 50;
c_name = n;
int temp = hrs - i_hrs;
if (temp > 0)
{
add_hrs = temp;
}
else
{
add_hrs = 0;
}
}
hacker::~hacker()
{
cout << "\n hacker deleted";
}
float hacker::computebill()
{
float bill;
bill = (add_hrs * add_hrs_rate) + i_cost;
return bill;
}
class chatroom :public customer
{
int conns;
float cpc;
public:
chatroom(string n, int con);
~chatroom();
virtual float computebill()override;
virtual void display();
};
chatroom::chatroom(string n, int con)
{
c_name = n;
conns = con;
cpc = 0.10;
i_cost = 50;
}
void chatroom::display()
{
system("cls");
cout << "\ndear " << c_name << ", chatroom plan is most suitable for you.";
cout << "\n--------details of chatroom plan--------";
cout << "\ninitial hrs: unlimited";
cout << "\ninitial cost:" << i_cost;
cout << "\n additional rate(dollars per hour):none";
cout << "\n disk space limit(mb):none";
cout << "\n charge per dialup connection: none";
cout << "\n expected bill:" << this->computebill();
}
float chatroom::computebill()
{
float bill;
bill = i_cost + (conns * cpc);
return bill;
}
chatroom::~chatroom() {
cout << "\nchatroom deleted";
}
int main()
{
string name;
float hrs;
int conns;
float memory;
cout << "\n------------------baltimore on-line package suggestion program------------------------";
cout << "\nenter your good name:";
getline(cin, name);
while (cin.fail())
{
cout << "\ninvalid input...";
cin.clear();
cin.ignore(256, '\n');
cout << "\nenter your good name:";
getline(cin, name);
}
system("cls");
cout << "\n hey " << name << "! welcome.\n how many hours you spend on-line?\n";
cin >> hrs;
while (cin.fail() || hrs < 0 || hrs>730)
{
cout << "\ninvalid input...";
cin.clear();
cin.ignore(256, '\n');
cout << "\n how many hours you spend on-line?\n";
cin >> hrs;
}
cout << "\n how many times you dial up?\n";
cin >> conns;
while (cin.fail() || conns < 0)
{
cout << "\ninvalid input...";
cin.clear();
cin.ignore(256, '\n');
cout << "\n how many times you dial up?\n";
cin >> conns;
}
customer** cus = new customer * [3];
int s;
cout << "\n how many memory you use for webpages or pictures?(in mbs)\n";
cin >> memory;
while (cin.fail() || memory < 0)
{
cout << "\ninvalid input...";
cin.clear();
cin.ignore(256, '\n');
cout << "\n how many memory you use for webpages or pictures?(in mbs)\n";
cin >> memory;
}
if (memory <= 1)
{
s = 3;
customer c(name, hrs);
cus[0] = &c;
hacker h(name, hrs);
cus[1] = &h;
chatroom chatt(name, conns);
cus[2] = &chatt;
float min = cus[0]->computebill();
int ind = 0;
for (int i = 0; i < 3; i++)
{
if (cus[i]->computebill() < min)
{
min = cus[i]->computebill();
ind = i;
}
}
cus[ind]->display();
}
else if (memory >= 1 && memory <= 50)
{
s = 2;
hacker h(name, hrs);
cus[0] = &h;
chatroom chatt(name, conns);
cus[1] = &chatt;
float min = cus[0]->computebill();
int ind = 0;
for (int i = 0; i < 2; i++)
{
if (cus[i]->computebill() < min)
{
min = cus[i]->computebill();
ind = i;
}
}
cus[ind]->display();
}
else if (memory >= 50)
{
s = 1;
chatroom h(name, conns);
cus[0] = &h;
float min = cus[0]->computebill();
cus[0]->display();
}
delete[]cus;
return 0;
}