|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. I've been tring for the past week nad have gotten no where.
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: [code] Message.cpp Code: 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
Last edited by WingedPanther; 03-08-2008 at 11:12 AM. Reason: add code blocks |
| Sponsored Links |
|
|
|
|||||
|
I guess my real question is: where are you having difficulty. Are you not sure what your strategy should be, or having issues with the code?
Also, please use code blocks with your code.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unique & Complex Sorting Program | ryan.devani | C and C++ | 3 | 01-17-2008 01:28 PM |
| Help with Square root and calculator program!!! | 123456789asdf | C and C++ | 10 | 12-02-2007 05:35 PM |
| PHP:Tutorial - Email Verification | John | PHP Tutorials | 3 | 09-19-2007 01:19 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |