Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Class Message1 1.1 Class declaration . This is the first step towards implemen

ID: 3918244 • Letter: 1

Question

1 Class Message1 1.1 Class declaration . This is the first step towards implementing an "Email project" for a simple model of an "Email account" with a list of email messages. The first step is to create a class to contain an email message. . Even to do that requires formalism which we have not studied yet. - Hence here we shall write a simple class "Message1" which is the first step towards a full "email message" class. . We shall build on the Message1 class in later assignments to write Message2, etc., until at the end we write the final Message" class. . The class has the following private data members: class Message1 ( public: // to do private string from; string .to; string subject; string text; int _date; 7: . We shall write public and private methods for the class below. . In real life we can send an email message to multiple recipients (including mail groups), but . For now the "date is an int. We shall replace it by a date object later in later versions of for the names of we shall keep the design simple and have only one recipient. the class. We shall follow a common industry practice and attach an underscore class data members.

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


Message1.h
---------

#ifndef Message1_h
#define Message1_h

#include <iostream>
using namespace std;

class Message1{
public:
Message1();
Message1(string f);
Message1(string f, string t);
Message1(string f, string t, string s);
Message1(string f, string t, string s, string txt);

string from() const;
string to() const;
string subject() const;
string text() const;
string date() const;


void setRecipient(string t);
void setSubject(string s);
void setText(string txt);
void prependText(string t);
void appendText(string t);

void print() const;

private:
string addDomain(string s);

string _from;
string _to;
string _subject;
string _text;
int _date;
};

ostream& operator << (ostream& os, const Message1 &m);
#endif /* Message1_h */


Message1.cpp
============


#include <sstream>
#include "Message1.h"
Message1::Message1(){
_date = 0;
}

Message1::Message1(string f){
_from = addDomain(f);
_date = 0;
}
Message1::Message1(string f, string t){
_from = addDomain(f);
_to = addDomain(t);
_date = 0;
}
Message1::Message1(string f, string t, string s){
_from = addDomain(f);
_to = addDomain(t);
_date = 0;
_subject = s;
}
Message1::Message1(string f, string t, string s, string txt){
_from = addDomain(f);
_to = addDomain(t);
_date = 0;
_subject = s;
_text = txt;
}

string Message1::from() const{
return _from;
}
string Message1::to() const{
return _to;
}
string Message1::subject() const{
return _subject;
}
string Message1::text() const{
return _text;
}

string Message1::date() const{
return string("n/a");
}

void Message1::setRecipient(string t){
_to = addDomain(t);
}

void Message1::setSubject(string s){
_subject = s;
}
void Message1::setText(string txt){
_text = txt;
}
void Message1::prependText(string t){
_text = t + " " + _text;
}
void Message1::appendText(string t){
_text = _text + " " + t;
}

void Message1::print() const{
cout << "From: " << _from << endl;
cout << "To: " << _to << endl;
cout << "Subject: " << _subject << endl;
cout << "Date: " << date() << endl;
cout << _text << endl;
cout << endl;
}

string Message1::addDomain(string s){
const string _domain = "@qc.cuny.edu";
istringstream iss(s);
iss >> s;
return s + _domain;
}


ostream& operator << (ostream& os, const Message1 &m)
{
os << "From: " << m.from() << endl;
os << "To: " << m.to() << endl;
os << "Subject: " << m.subject() << endl;
os << "Date: " << m.date() << endl;
os << m.text() << endl;
os << endl;
return os;
}