C++ Email Box Program

This is a discussion on C++ Email Box Program within the C++ Programming forums, part of the General Programming Boards category; I'm posting this to anyone who can do it, I'm not really having any problems with it... I just can ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    1

    Post C++ Email Box Program

    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.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,794
    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.
    Please read up on our homework policy.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Please review the homework policy of this site. Just because you say that we can do it or not, that doesn't make it not break the rules. We're volunteers, and we already have this option for every single thread.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Help with Combo Box that closes my program
    By Marcos in forum Windows Programming
    Replies: 3
    Last Post: 06-05-2005, 10:09 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. sending strings from program to email
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 04-09-2002, 06:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21