The attaced files are the starter code that presents some of the concepts needed
ID: 3741352 • 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
Given below is the completed .cpp files for the question. You the .cpp files along with the .h files provided by you in the question.
Please do rate the answer if it was helpful. Thank you
address.cpp
=========
#include "address.h"
address::address(void)
{
name = "";
zip = "";
}
address::address(const address &other)
{
*this = other;
}
address::address(const string & theName, const string & theZip)
{
name = theName;
zip = theZip;
}
address::~address(void)
{
}
string address::getName(void) const
{
return name;
}
string address::getZip(void) const
{
return zip;
}
address & address::setName(const string & theName)
{
name = theName;
return *this;
}
address & address::setZip(const string & theZip)
{
zip = theZip;
return *this;
}
const address & address::operator=(const address & right)
{
name = right.name;
zip = right.zip;
return *this;
}
void address::print(ostream &out) const
{
out << name << endl;
out << zip << endl;
}
letter.cpp
=========
#include "letter.h"
letter::letter(void)
{
}
letter::letter(const letter &other)
{
*this = other;
}
letter::letter(const address & sentBy, const address & sentTo, double theWeight)
{
from = sentBy;
to = sentTo;
weight = theWeight;
}
letter::letter(const string & senderName, const string & senderZip,
const string & toName, const string & toZip,
double theWeight)
{
from = address(senderName, senderZip);
to = address(toName, toZip);
weight = theWeight;
}
letter::~letter(void)
{
}
address letter::getSender(void) const
{
return from;
}
address letter::getTo(void) const
{
return to;
}
double letter::getWeight(void) const
{
return weight;
}
string letter::getSenderName(void) const
{
return from.getName();
}
string letter::getSenderZip(void) const
{
return from.getZip();
}
string letter::getToName(void) const
{
return to.getName();
}
string letter::getToZip(void) const
{
return to.getZip();
}
letter & letter::setSender(const address &f)
{
from = f;
return *this;
}
letter & letter::setTo(const address &t)
{
to = t;
return *this;
}
letter & letter::setWeight(double w)
{
weight = w;
return *this;
}
const letter & letter::operator = (const letter & right)
{
from = right.from;
to = right.to;
weight= right.weight;
return *this;
}
double letter::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
*/
{
if(weight <= 1)
return 0.44;
else if(weight <= 2)
return 0.61;
else if(weight <= 3)
return 0.78;
else
return 0.95;
}
void letter::print(ostream &out) const
{
out << "From:" << endl;
from.print(out);
out << "To:" << endl;
to.print(out);
out << "Cost: $" << getPostageCost();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.