I'm supposed to create a .h and a .cpp file called Package which should:
1. Package should include data members representing the name, address, city, state, and ZIP code for both the sender and the recipient of the package.
2. Package should include data members that store the weight (in ounces) and cost per ounce to ship the package.
3. Package’s constructor should initialize all of these data members. Ensure that the weight and cost per ounce contain positive values.
4. Package should provide a public member function calculateCost that returns a double indicating the cost associated with shipping the package. This is given by multiplying the weight of the package by the cost per ounce.
5. Package should overload the << operator to display the sender and receiver’s names and addresses on the screen.
Here is Package.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <string>
#include "Package.h"
using namespace std;
Package::Package(string a, b, c, d, int e, float f, g) {
nameR = a;
addressR = b;
cityR = c;
stateR = d;
ZIPR = e;
oz = f;
CPO = g;
}
ostream &operator<<(ostream &output, const Package &nameI) {
output<<"Sender: "nameI.nameS<< "\n Sending Address: "<< nameI.addressS<<"\n Receiver: "<<nameI.nameR<< "\n Receiver address: "<<nameI.addressR<<endl;
return output; //enables cout
}//end ostream
double calculateCost(double weight, double costPerOz) {
double price;
price = weight * costPerOz;
return price;
}//end calculateCost
|
Here is Package.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
//include gaurd
#ifndef PACKAGE_H
#define PACKAGE_H
#include <iostream>
using namespace std;
class Package;
class TwoDayPackage;
class OvernightPackage;
class Package {
private:
string nameS;
string addressS;
string cityS;
string stateS;
int ZIPS;
float oz; //weight in ounces of package
float CPO; //cost per ounce to ship package
string nameR;
string addressR;
string cityR;
string stateR;
int ZIPR;
public:
friend ostream& operator<<(ostream&, const Package&); //Stream insertion
//default constructor
Package(string a, b, c, d, int e, float f, g);
double calculateCost(double weight, double costPerOz);
};
#endif
|
I don't think I'm going about this the right way. I don't know what should go in .cpp and what should go in .h. Halp!