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

The attaced files are the starter code that presents some of the concepts needed

ID: 3699162 • Letter: T

Question

The attaced files are the starter code that presents some of the concepts needed to complete Lab. Pay particular attention to M.I.L. - Member Initialization List

__________________________letter.h___________________________________

#ifndef LETTER_H

#define LETTER_H

#include "address.h"

#include <string>

#include <fstream>

using namespace::std;

class letter

{

public:

   letter(void);

   letter(const letter &);

   letter(const address & sentBy, const address & sentTo, double theWeight);

   letter(const string & senderName, const string & senderZip,

       const string & toName, const string & toZip,

       double theWeight);

   ~letter(void);

   address getSender(void) const;

   address getTo(void) const;

   double getWeight(void) const;

   string getSenderName(void) const;

   string getSenderZip(void) const;

   string getToName(void) const;

   string getToZip(void) const;

   letter & setSender(const address &);

   letter & setTo(const address &);

   letter & setWeight(double);

   const letter & operator = (const letter & right);

   double getPostageCost(void) const; // assume NO ERROR CONDITIONS

   /*

   Weight Not Over Rates

   (ounces)

   1 0.44

   2 0.61

   3 0.78

   3.5 0.95

   */

   void print(ostream &) const;

   // output will be of the form:

   // From:

   // John Wilson

   // 66210

   // To:

   // Mary Jones

   // 66212

   // Cost: $0.95

private:

   address from;

   address to;

   double weight; // weight in ounces

};

#endif

__________________________________address.h________________________

#ifndef ADDRESS_H

#define ADDRESS_H

#include <string>

#include <iostream>

using namespace::std;

class address

{

public:

   address(void);

   address(const address &);

   address(const string & theName, const string & theZip);

   ~address(void);

   string getName(void) const;

   string getZip(void) const;

   address & setName(const string & theName);

   address & setZip(const string & theZip);

   const address & operator=(const address & right);

   void print(ostream &) const;

   // output will be of the form:

   // John Wilson

   // 66210

private:

   string name;

   string zip;

};

#endif

Explanation / Answer

As per the given data wrote a program as shown below:

Program:

letter::letter(void)

{

cout<<"Contents in letter";

   this->weight=0.0;

   this->to=address();

   this->from=address();

}

letter::letter(const letter & obj)

{

   cout<<"copy of letter";

   this->weight=obj.weight;

   this->to=obj.to;

   this->from=obj.from;

}

letter::~letter(void)

{

   cout<<"Freeing memory";

}

letter::letter(const address & sentBy, const address & sentTo, double theWeight)

{

   this->weight=theweight;

   this->to=sentTo;

   this->from=sentBy;

}

letter ::letter(const string & senderName, const string & senderZip,

const string & toName, const string & toZip,

double theWeight);

{

   this->weight=theweight;

   this->to=address(toName,toZip);

   this->from=address(senderName,senderZip);

}

address letter::getSender(void) const

{

return this->from;

}

address letter ::getTo(void) const

{

   return this->to;

}

double letter::getWeight(void) const

{

   return this->weight;

}

string letter:: getSenderName(void) const

{

   return this->from.getName();

}

string letter ::getSenderZip(void) const

{

}

string letter :: getToName(void) const

{

return this->to.getName();

}

string letter :: getToZip(void) const

{

   return this->to.getZip();

}

letter & letter::setSender(const address &sender)

{

   this->from=sender;

   return *this;

}

letter & letter :: setTo(const address &to)

{

   this->to=to;

   return *this;

}

letter & letter::setWeight(double)

{

   this->weight=weight;

   return *this;

}

const letter & letter ::operator = (const letter & right)

{

   this->from=right.from;

   this->to=right.to;

   this->weight=right.weight;

    return *this;

}

double letter ::getPostageCost(void) const

{

   if(weight<1.0)

       return 0.44;

   elseif(weight < 2.0)

       return 0.61;

   elseif(weight < 3.0)

       return 0.78;

   else

       return 0.95;

}

void letter ::print(ostream &output) const

{

   output<<"FROM:"<<endl;

   this->from.print(output);

   output<<endl<<"TO:"<<endl;

   this->to.print(output);

   output<< endl;

}

address::address(void)

{

   this->name="";

   this->zip="";

}

address::address(const address &obj)

{

   this->name=obj.name;

   this->zip=obj.zip;

}

address:: address(const string & theName, const string & theZip);

{

   this->name=thename;

   this->zip=thezip;

}

address:: ~address(void)

{

cout<<"free ";

}

string address::getName(void) const

{

   return this->name;

}

string address:: getZip(void) const

{

   return this->zip;

}

address & address:: setName(const string & theName)

{

   this->name=theName;

   return *this;

}

address & address:: setZip(const string & theZip)

{

   this->zip=thezip;

   return *this;

}

const address & address :: operator=(const address & right)

{

   this->name=right.name;

   this->zip=right.zip;

   return *this;

}

void address ::print(ostream &output) const

{

   output << "Name :"<<endl;

   this->name.print(output);

   output<< "Zip:"<<endl;

this->zip.print(output);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote