Message class ** Need help befor 12am tonight**

This is a discussion on Message class ** Need help befor 12am tonight** within the C++ Programming forums, part of the General Programming Boards category; Assignment: Implememnt the message class using a a header and implemtin a file name message.h and message.cpp respectively. In addition ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    13

    Message class ** Need help befor 12am tonight**

    Assignment:
    Implememnt the message class using a a header and implemtin a file name message.h and message.cpp respectively. In addition to the two message class files you must write a driver. The driver mus creat a message array that is capable of holding 1000 messages (make sure that you dont exceed the the maximum number of messages) It then must read all Messages from a file named Messages.txt; sort the messages based on the date, fand a message bassed on the messageID(value will be given by keyboard input), and print the first five messages and the message resulting from the search.

    Given:
    Memeber Functions :

    Message()
    - Default Constructor that increments the messageID

    Message(string, string string)
    - Constructor twith initiallization strings for sender, recipient, and body, it will also increment the messageID.

    ~Message()
    -Destructor

    void setSender(string)
    - Modifier that allows the user to set the sender string

    void setRecipient(string)
    - Modifier that allows the user to set the recipient

    void setBody(string)
    - Modifier that allows the user to set the Body

    void setDate(string)
    - Modifier that allows the user to set the date

    string getSender()
    - Accessor that allows the user to get the sender string

    string getRecipient()
    - Accessor that allows the user to get the recipient string

    string getBody()
    - Accessor that allows that user to get the Body string

    string getDate()
    - Accessor that allows the user to get the date string

    static in getMessageID()
    - Accessor that allows the user to get the value of message ID

    string toString()
    - Function that returns a string representation of a message object.

    exampel:
    messageID: 1
    date: 2006/11/20
    sender: bobbie@baylor.edu
    recipient: lilley@baylor.edu
    body: Hope your semester is going well!
    Currently i have:

    message.h:
    Code:
    #ifndef MESSAGE_H
    #define MESSAGE_H
    #include <iostream>
    #include <fstream>
    #include <sstream>
    using namespace std;
    
    
    /**************************************************************************
    *
    *	class: Message
    *	Discription: A class that stores incoming emails and sorts them 
    *
    ***************************************************************************/
    class Message
    { 
    	private:
    		string sender, recipient, body, date;  
    		static int messageIDGen;
    		int messageID;
    
        public:
    /**************************************************************************
    *
    *	class: Message
    *	Function: Message
    *   Description: Default constructor
    *
    ***************************************************************************/
    		Message(){ messageID = ++messageIDGen; }
    
    /**************************************************************************
    *
    *	class: Message
    *	Function: Message
    *   
    *
    ***************************************************************************/
    		Message(string, string, string, string);
    
    /**************************************************************************
    *
    *	class: Message
    *   Function: ~Message
    *	Description: Destructor
    *
    ***************************************************************************/
    		~Message();
    
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setSender
    *   Description: Modifier that allows the user to set the 
    *   sender string
    *
    ****************************************************************/
    		void setSender(string);
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setRecipient
    *   Description: Modifier that allows the user to set the 
    *   recipient
    *
    ****************************************************************/
    		void setRecipient(string);
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setBody
    *   Description: Modifier that allows the user to set the Body
    *
    ****************************************************************/
    		void setBody(string);
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setDate
    *   Description: Modifier that allows the user to set the date
    *
    ****************************************************************/
    		void setDate(string);
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getSender
    *   Description: Accessor that allows the user to get the 
    *   sender string
    *
    ****************************************************************/
    		string getSender();
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getRecipient
    *   Description: Accessor that allows the user to get the 
    *   recipient string
    *
    ****************************************************************/
    		string getRecipient();
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getBody
    *   Description: Accessor that allows that user to get the 
    *   Body string
    *
    ****************************************************************/
    		string getBody();
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getDate
    *   Description: Accessor that allows the user to get the
    *   date string
    *
    ****************************************************************/
    		string getDate();
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: toString
    *   Description: Function that returns a string representation 
    *   of a message object
    *
    ****************************************************************/
    		string toString();
    		
    /****************************************************************
    *
    *	Class: Message
    *   Function: getStringMessageID
    *   Description: We have no idea what this does lol
    *
    ****************************************************************/
    		string getStringMessageID();
    ;
    };
    #endif


    message.cpp:
    Code:
    #include "Message.h"
    
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: ~Message
    *   Description: Destructor
    *
    ****************************************************************/
    Message::~Message()
    {
    
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setSender
    *   Description: Modifier that allows the user to set the 
    *   sender string
    *
    ****************************************************************/
    void Message::setSender(string Sender)
    {
    	sender=Sender;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setSender
    *   Description: Modifier that allows the user to set the 
    *   recipient
    *
    ****************************************************************/
    void Message::setRecipient(string Recipient)
    {
    	recipient=Recipient;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setBody
    *   Description: Modifier that allows the user to set the Body
    *
    ****************************************************************/
    void Message::setBody(string Body)
    {
    	body=Body;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: setDate
    *   Description: Modifier that allows the user to set the date
    *
    ****************************************************************/
    void Message::setDate(string Date)
    {
    	date=Date;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getSender
    *   Description: Accessor that allows the user to get the 
    *   sender string
    *
    ****************************************************************/
    string Message::getSender()
    {
    	return sender;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getRecipient
    *   Description: Accessor that allows the user to get the 
    *   recipient string
    *
    ****************************************************************/
    string Message::getRecipient()
    {     
    	return recipient;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getBody
    *   Description: Accessor that allows that user to get the 
    *   Body string
    *
    ****************************************************************/
    string Message::getBody()
    {     
    	return body;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getDate
    *   Description: Accessor that allows the user to get the
    *   date string
    *
    ****************************************************************/
    string Message::getDate()
    {     
    	return date;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: toString
    *   Description: Function that returns a string representation 
    *   of a message object
    *
    ****************************************************************/
    string Message::toString()
    {
    	return 0;
    }
    
    /****************************************************************
    *
    *	Class: Message
    *   Function: getStringMessageID
    *   Description: We have no idea what this does lol
    *
    ****************************************************************/
    string Message::getStringMessageID()
    
    {
    	ostringstream temp;
    	temp << messageID;      
    	return temp.str();      
    }
    Mailbox.cpp <--driver file:
    Code:
    #include "Message.h"
    
    int main()
    {
    	int messageID;
    	string extra, date, sender, recipient, body;
    	Message inMessage;
    
    	//ask and promps user for a message to view
    	cout << "Which messageID would you like to view? "; 
    	cin >> messageID;
    	
    	//declares an instream file
    	ifstream inFile;
    	inFile.open("messages.txt"); //opens messsages.txt
    	
    	//checks to see if file is found, and displays error if not
    	if (!inFile)
    	{
    		cout << "File not found." << endl;
    		return 0;
    	}
    
    	//allows only 1000 messages to be entered
    	for(int messages = 0; messages <=999; messages++)
    	{
    
    	}
    	
    
    	inMessage.getDate();
    	inMessage.getSender();
    	inMessage.getRecipient();
    	inMessage.setBody();
    	
    	cout << endl << "Your message is:" << endl;
    	cout << endl << "messageID:" << "\t" << inMessage.getStringMessageID();
    	cout << endl << "date:" << "\t" << inMessage.getDate();
    	cout << endl << "sender:" << "\t" << inMessage.getSender();
    	cout << endl << "recipient:" << "\t" << inMessage.getRecipient();
    	cout << endl << "body:" << "\t" << inMessage.getBody();
    	return 0;
    }
    Okay i need help with the function toStream im not sure what i should do or need to do for that.

    and then the driver im having the hard part with i dont know what i need to do to get the message in and give it a message id. Any help or advice would be great please i have to turn this in in less that 2 hours or it wont be accepted

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,339
    >> Okay i need help with the function toStream
    Do you mean toString? Use a stringstream and do exactly what you did with cout at the end of your driver program except with the stringstream variable instead of cout. Then, get the string out of the stringstream with the str() function and return that string.

    BTW, consider editing your post and removing the emails, especially if either is not your own.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Making a script language?
    By Blackroot in forum Game Programming
    Replies: 10
    Last Post: 02-16-2006, 01:22 AM
  3. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM

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