#include<iostream>
#include<string>
using namespace std;
class Package{ //Base Class
private: //data members
string name,city,state,sender,recipient;
int zip;
string address;
float weight; //in ounce
double cost; //per ounce
public: //member functions
void setName(string name);
void setCity(string city);
void setState(string state);
void setZip(int zip);
void setAddress(string address);
void setSender(string sender);
void setRecipient(string recipient);
string getName(){ return name;}
string getCity(){return city;}
string getState(){return state;}
int getZip(){return zip;}
string getAddress(){return address;}
string getSender(){return sender;}
string getRecipient(){return recipient;}
double calculatecost(float weight,double costperounce) //function that calculate the cost z
{
double z; //total cost = weight*cost per ounce
z=weight*costperounce; //the cost z
cout<< "The Base Cost = " <<z << endl<<endl;
return z;
}
};
void Package::setName(string n){
name=n;
}
void Package::setCity(string c){
city=c;
}
void Package::setState(string s){
state=s;
}
void Package::setZip (int zp){
zip=zp;
}
void Package::setAddress(string adr){
address=adr;
}
void Package::setSender(string sen)
{
sender=sen;
}
void Package::setRecipient(string rec)
{
recipient=rec;
}
class TwoDayPackage: public Package{ //inhereted class
public:
double calcshippingcost(float weight,double costperounce,double k) /* function that calculate shipping cost by adding the flat
fee to the weight-based cost calculated by base class Package’s calculateCost function*/
{
double z; //shippingcost of Two day Package class
z= calculatecost(weight,costperounce) +k; //where k is the ???????
cout<< "The TwoDayPackage Cost = " <<z << endl;
}
private:
double flatfee;
};
class OvernightPackage: public Package{ //the inhereted function thatadds the additional fee per ounce to the standard cost per ounce
public:
double calccostovernight(float weight,double costperounce,double w )
{
double z; //shippingcost of overnight class
z=calculatecost(weight,costperounce)+(w*weight);
cout<< "The OvernightPackage Cost = " <<z << endl;
}
private:
double overnightcost; //per ounce
};
int main(){
// weight and costperounce sabteen fe kol el classes y3ne hane7teghom fel kol el mataleb
int i; //i represent the user`s choice number
string customername,customeraddress,city,state,senderaddress,recipientaddress;
float packageweight;
string customercity;
double costperounce;
double flatfee;
double additionalcost;
string customerstate;
int customerzipcode;
Package base; //the object base of the package class
TwoDayPackage twoday; //the object twoday of the first inhereted calss
OvernightPackage overnight; //the object overnight of the second inhereted calss
/*int package[3];
for()
int packag={"TwoDaypackage","overnightpackage"};
int *packag;
*/
cout<<" *****Welcome To The American Package Delievery Services*****"<<endl<<endl;
cout<<"Please Fill In The Requested Data Follow: "<<endl<<"-----------------------------------------"<<endl<<endl;;
cout<<"Enter Customer Name "<<endl<<endl;
cin>>customername;
cout<<endl;
base.setName(customername); //call function setName
cout<<"Enter Customer Address"<<endl<<endl;
cin>>customeraddress;
cout<<endl;
base.setAddress(customeraddress);
cout<<"Enter Customer City"<<endl<<endl;
cin>>customercity;
cout<<endl;
base.setCity(customercity);
cout<<"Enter Customer State"<<endl<<endl;
cin>>customerstate;
cout<<endl;
base.setState(customerstate);
cout<<"Enter Customer ZIP code"<<endl<<endl;
cin>>customerzipcode;
cout<<endl;
base.setZip(customerzipcode);
cout<<"Enter Weight"<<endl;
cin>>packageweight;
cout<<endl;
cout<<"Enter Cost Per Ounce"<<endl;
cin>>costperounce;
cout<<endl;
cout<<"Please Enter Your Choice From The Menu Below:"<<endl<<endl;
cout<<" 1- Calculate Base Cost "<<endl<<endl;
cout<<" 2- Calculate Two Day Cost "<<endl<<endl;
cout<<" 3- Calculate Over Night Cost"<<endl<<endl;
cin>>i;
cout<<endl; //i represent customer choice
switch (i)
{
case 1 :
base.calculatecost(packageweight,costperounce);
break;
case 2 :
cout<<"Enter Flat Cost"<<endl<<endl; //additonal(to weight and cost) needed information
cin>>flatfee;
twoday.calcshippingcost(packageweight,costperounce,flatfee);
break;
case 3 :
cout<<"Enter The Additional Cost"<<endl<<endl;
cin>>additionalcost;
overnight.calccostovernight(packageweight,costperounce,additionalcost);
break;
default:
cout<<"INVALID CHOICE....Please Enter ur Choice Number From 1-->3 "<<endl;
}
cout<<"Enter sender address "<<endl<<endl;
cin>>senderaddress;
cout<<endl;
base.setSender( senderaddress);
cout<<"Enter ricipent address"<<endl<<endl;
cin>>recipientaddress;
cout<<endl;
base.setRecipient(recipientaddress);
cout<<"address from:"<< senderaddress<<endl;
cout<<"To:"<<recipientaddress<<endl;
[b]// [color=#FF0000] int package[3];
for(int i=0;i<3;i++)
{
if(i=0)
{
}
int packag={"TwoDaypackage","overnightpackage"};
int *packag;[/[/color]b]
system ("pause");
return 0;
problem is(Use the Package inheritance hierarchy created in the previous problem to create a program
that displays the address information and calculates the shipping costs for several Packages. The
program should contain an array of Package pointers to objects of classes TwoDayPackage and
OvernightPackage. Loop through the array to process the Packages polymorphically. For each
Package, invoke get functions to obtain the address information of the sender and the recipient,
then print the two addresses as they would appear on mailing labels. Also, call each Package’s
calculateCost member function and print the result. Keep track of the total shipping cost for all
Packages in the array, and display this total when the loop terminates.)
i want to replay very fast

New Topic/Question
Reply




MultiQuote





|