1 #include <sstream>
2 #include "mailbox.h"
3 #include "mailsystem.h"
4
5 using namespace std;
6
7 MailSystem::MailSystem(int mailbox_count)
8 {
9 for (int i = 0; i < mailbox_count; i++)
10 {
11 ostringstream passcode;
12 passcode << i;
13 ostringstream greeting;
14 greeting << "You have reached mailbox " << i
15 << ". \nPlease leave a message now.";
16 mailboxes.push_back(new Mailbox(passcode.str(), greeting.str()));
17 }
18 }
19
20 int string_to_int(string s)
21 {
22 istringstream instr(s);
23 int n;
24 instr >> n;
25 return n;
26 }
27
28 Mailbox* MailSystem::find_mailbox(string ext) const
29 {
30 int i = string_to_int(ext);
31 if (1 <= i && i <= mailboxes.size())
32 return mailboxes[i];
33 return NULL;
34 }