![]() |
| | #1 | |
| Registered User Join Date: Nov 2006
Posts: 13
| Message class ** Need help befor 12am tonight** Quote:
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();
}
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 | |
| TransformedBG is offline | |
| | #2 |
| Registered User Join Date: Jan 2005
Posts: 7,139
| >> 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. |
| Daved is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| Making a script language? | Blackroot | Game Programming | 10 | 02-16-2006 02:22 AM |
| my wndProc is out of scope | Raison | Windows Programming | 35 | 06-25-2004 07:23 AM |
| Warnings, warnings, warnings? | spentdome | C Programming | 25 | 05-27-2002 06:49 PM |
| class member access denied | chiqui | C++ Programming | 2 | 05-27-2002 02:02 PM |