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

COMPOSTION #ifndef ADDRESS_H #define ADDRESS_H #include <string> #include <iostr

ID: 645886 • Letter: C

Question

COMPOSTION

#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

#include "address.h"

address::address(void)
{
setName("").setZip(0);
}

address::address( const address & r )
{
setName(r.getName()).setZip(r.getZip());

}
address::address( const string & theName, const string & theZip )
{
setName(theName.getName()).setZip(theZip.getZip());
  
}
address::~address(void)
{
  
}

string address::getName(void) const
{
return name;

}
string address::getZip(void) const
{
return zip;

}

address & address::setName( const string & theName )
{
(*this).theName = theName;
// theName = name;
return *this;

}
address & address::setZip( const string & theZip )
{
(*this).theZip = theZip;
return *this;
  

}

const address & operator=(const address & right)
{
if (this == & right) return * this;
name = right.name;
zip = right.zip;

return *this;

}

void address::print(ostream & outs ) const
{
outs << ' ' << getName() << '' << getZip() << endl;

return *this;


}

#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

   void print(ostream &, const string & creditCardNumber, ofstream & chargeFile) const;
       // output will be of the form: NOTE .44 will vary, depending on
   // the weight of the letter
   // .44   
   // From:
   // John Wilson
   // 66210

   // To:
   // Mary Jones
   // 66212

   // and also an entry will be made in the chargeFile
   // creditCardNumber cost -- where cost is 90% of the postage cost
   // -- we are giving a 10% discount for online postage


private:

address from;
address to;
double weight; // weight in ounces

};

#endif

#include "letter.h"
using namespace std;
#include<iostream>

letter::letter(void)
{
setSender(0).setTo(0).setWeight(0.0);


}

letter::letter( const letter & let )
{
setSender(let.getSenderName()).setTo(let.getToName()).setWeight(let.getWeight());

}

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

}
letter::letter( const string & senderName, const string & senderZip,
       const string & toName , const string & toZip,
   double theWeight)
{
setSender(senderName.getSenderName()).setZip(senderZip.getSenderZip().setToName(toName.getToName().setZip(toZip.getToZip()).setWeight(theWeight.getWeight());


}
  
~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 string("From");


}
string letter::getSenderZip(void) const
{
return string("Zip");


}
string letter::getToName(void) const
{
return string(" Sender Name");


}
string letter::getToZip(void) const
{
return string("To");


}

letter & letter::setSender( const address & send)
{
from = send;
return *this;

}
letter & letter::setTo( const address & addr)
{
to = addr;
return *this;


}
letter & letter::setWeight( double w )
{
weight = w;
return *this;


}

const letter & operator = ( const letter & right)
{
if (this == & right) return *this;
from = right.from;
to = right.to;
weight = right.weight;

return *this;


}

double letter::getPostageCost(void) const
{
return to;

}

void letter::print(ostream & outs) const
{
outs << "From: " << getSenderName() << "TO: "<<getToName() <<
<<" Sender Zip code: " << getSenderZip() << "Reciver Zip Code: " <<
<<getToZip() << "Weight: " <<getWeight() << endl;
  
return *this;


}
  

void letter::print(ostream &, const string & creditCardNumber, ofstream & chargeFile) const
{
  


}

#include "address.h"
#include "letter.h"

#include <iostream>
#include <string>
using namespace::std;

int main()
{
   // include code to test your member functions as you go along

   // after you have tested your functions, execute the following
   ofstream creditChargeFile;
   creditChargeFile.open("c:\charges.txt");

   letter saleNotice("The Bookstore","66210","Mike Smith","64114", 3.1);
   saleNotice.print(cout,"5401 8211 4567 9912",creditChargeFile);

creditChargeFile.close();
   return 0;
}

Explanation / Answer

#include
#include
using namespace::std;

class address
{
public:
    address(void);
    address( const address & );
    address( const string & theName, const string & theZip );
  
    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);
  

    string getName(void) const;
    string getZip(void) const;
    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;

    address & setName( const string & theName );
    address & setZip( const string & theZip );
    letter & setSender( const address & );
    letter & setTo(     const address & );
    letter & setWeight( double );

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

    void print(ostream & ) const;
    const letter & operator = ( const letter & right);

    double getPostageCost(void) const;
    void print(ostream &, const string & creditCardNumber, ofstream & chargeFile) const;
    void print(ostream &) const;
  


private:
    string name;
    string zip;
   address from;
   address to;
   double weight;
};
address::address(void)
{
setName("").setZip(0);
}

address::address( const address & r )
{
setName(r.getName()).setZip(r.getZip());

}
address::address( const string & theName, const string & theZip )
{
setName(theName.getName()).setZip(theZip.getZip());

}
address::~address(void)
{

}

string address::getName(void) const
{
return name;

}
string address::getZip(void) const
{
return zip;

}


address::letter( const letter & let )
{
setSender(let.getSenderName()).setTo(let.getToName()).setWeight(let.getWeight());

}

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

}
address::letter( const string & senderName, const string & senderZip,
            const string & toName    , const string & toZip,
    double theWeight)
{
setSender(senderName.getSenderName()).setZip(senderZip.getSenderZip().setToName(toName.getToName().setZip(toZip.getToZip()).setWeight(theWeight.getWeight());


}

address :: getSender(void)     const
{
return from;


}
address ::getTo(void)         const
{
return to;

}
double   address::getWeight(void)     const
{
return weight;

}
string   address::getSenderName(void) const
{
return string("From");


}
string   address::getSenderZip(void) const
{
return string("Zip");


}
string   address::getToName(void)     const
{
return string(" Sender Name");


}
string   address::getToZip(void)      const
{
return string("To");


}

address & address::setSender( const address & send)
{
from = send;
return *this;

}
address & address::setTo(     const address & addr)
{
to = addr;
return *this;


}
address & address::setWeight( double w )
{
weight = w;
return *this;


}

address & address::setName( const string & theName )
{
(*this).theName = theName;
    return *this;

}
address & address::setZip( const string & theZip )
{
(*this).theZip = theZip;
return *this;

}

const address & operator=(const address & right)
{
if (this == & right) return * this;
name = right.name;
zip = right.zip;

return *this;

}
const address & operator = ( const letter & right)
{
if (this == & right) return *this;
from = right.from;
to = right.to;
weight = right.weight;

return *this;


}

double address::getPostageCost(void) const
{
return to;


}


  
void address::print(ostream & outs ) const
{
outs << ' ' << getName() << '' << getZip() << endl;

outs << "From: " << getSenderName() << "TO: "<        <<" Sender Zip code: " << getSenderZip() << "Reciver Zip Code: " <<
       <  
return *this;


}
int main()
{
  
    ofstream creditChargeFile;
    creditChargeFile.open("c:\charges.txt");
    :
    :
    letter saleNotice("The Bookstore","66210","Mike Smith","64114", 3.1);
    saleNotice.print(cout,"5401 8211 4567 9912",creditChargeFile);

    creditChargeFile.close();
    return 0;
}

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