Currently i have:Quote:
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: [email protected]
recipient: [email protected]
body: Hope your semester is going well!
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:
Mailbox.cpp <--driver file: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();
}
Okay i need help with the function toStream im not sure what i should do or need to do for that.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;
}
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