C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2006, 10:05 PM   #1
Registered User
 
Join Date: Nov 2006
Posts: 13
Message class ** Need help befor 12am tonight**

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: 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
TransformedBG is offline   Reply With Quote
Old 11-29-2006, 11:03 PM   #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   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 02:02 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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