I'm posting this to anyone who can do it, I'm not really having any problems with it... I just can 't even begin to get what I need to do in the question... If you can't do it or think I'm just lazy, please don't leave your angry comments, I'm just looking for an answer to this very difficult question.
Design a class Mailbox that stores mail messages, using the Message class “Message.h” and “Message.cpp” included as part of the assignment. You don't yet know how to store a collection of message objects. Instead, use the following brute force approach: The mailbox contains one very long string, which is the concatenation of all messages. You can tell where a new message starts by searching for a From: at the beginning of a line. This may sound like a dumb strategy, but surprisingly, many e-mail systems do just that. Implement the following member functions:
void Mailbox::add_message(Message m);
Message Mailbox::get_message(int i) const;
void remove_message(int i) const;
What do you do if the message body happens to have a line starting with "From:"? Then the to_string function of the Message class should really insert a > in front of the From: so that it reads >From:. Again, this sounds dumb, but it is a strategy used by real e-mail systems.
the two codes that are given are:
Message.cpp
Code:
#include <iostream>
#include <string>
#include "Message.h"
using namespace std;
Message::Message()
{
}
Message::Message(string r, string s)
{
recipient = r;
sender = s;
}
void Message::append(string t)
{
string from = "From: ";
if (t.substr(0, from.length()) == from)
text = text + ">" + t + "\n";
else
text = text + t + "\n";
}
string Message::to_string() const
{
return "From: " + sender + "\n" +
"To: " + recipient + "\n" + text;
}
void Message::print() const
{
cout << to_string();
}
and the header Message.h
Code:
#ifndef MESSAGE_H
#define MESSAGE_H
#include <iostream>
#include <string>
using namespace std;
class Message
{
public:
Message();
Message(string r, string s);
void append(string t);
string to_string() const;
void print() const;
private:
string recipient;
string sender;
string text;
};
#endif
Thankyou for taking the time to read my question.