Question

In: Computer Science

The solution has to be written on C++ Visual Studio Thank you (Package Inheritance Hierarchy) Package-delivery...

The solution has to be written on C++ Visual Studio

Thank you

(Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base class Package should include data members representing the name, address, city, state and ZIP

code for both the sender and the recipient of the package, in addition to data members that store the weight (in ounces) and cost per ounce to ship the package. Package’s constructor should initialize these data members. Ensure that the weight and cost per ounce contain positive values. Package should provide a public member function calculateCost that returns a double indicating the cost associated with shipping the package. Package’s calculateCost function should determine the cost by multiplying the weight by the cost per ounce. Derived class TwoDayPackage should inherit the

functionality of base class Package, but also include a data member that repressents a flat fee that the shipping company charges for two-day-delivery service. TwoDayPackage’s constructor should receive a value to initialize this data member. TwoDayPackage should redefine member function calculateCost so that it computes the shipping cost by adding the flat fee to the weight-based cost calculated by base class Package’s calculateCost function. Class OvernightPackage should inherit directly

from class Package and contain an additional data member representing an additional fee per ounce charged for overnight-delivery service. OvernightPackage should redefine member function calculateCost so that it adds the additional fee per ounce to the standard cost per ounce before calculating the shipping cost. Write a test program that creates objects of each type of Package and tests member function calculateCost.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Package {
private :
string senderName;
string senderAddress;
string senderCity;
string senderState;
string senderZIP;
string recipientName;
string recipientAddress;
string recipientCity;
string recipientState;
string recipientZIP;
double weight;
double costperounce;
public:Package(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost);
void setsenderName(string sender_n);
string getsenderName();
void setsenderAddress(string sender_addr);
string getsenderAddress();
void setsenderCity(string sender_c);
string getSendCity();
void setsenderState(string sender_s);
string getsenderState();
void setsenderZIP(string sender_Z);
string getsenderZIP();
void setrecipientName(string recipient_n);
string getrecipientName();
void setrecipientAddress(string recipient_addr);
string getrecipientAddress();
void setrecipientCity(string recipient_c);
string getrecipientCity();
void setrecipientState(string recipient_s);
string getrecipientState();
void setrecipientZIP(string recipient_Z);
string getrecipientZIP();
void setweight(double w);
double getweight();
void setcostperounce(double cost);
double getcostperounce();
double calculateCost();
};
Package::Package(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost)
{
senderName = sender_n;
senderAddress = sender_addr;
senderCity = sender_c;
senderState = sender_s;
senderZIP = sender_Z;
recipientName = recipient_n;
recipientAddress = recipient_addr;
recipientCity = recipient_c;
recipientState = recipient_s;
recipientZIP = recipient_Z;
if (wei > 0.0 && cost > 0.0)
{weight = wei;costperounce = cost;}
else
{
weight = 0.0;
costperounce = 0.0;
}
}
void Package::setsenderName(string sender_n)
{
senderName = sender_n;
}
string Package::getsenderName()
{
return senderName;
}
void Package::setsenderAddress(string sender_addr)
{
senderAddress = sender_addr;
}
string Package::getsenderAddress()
{
return senderAddress;
}
void Package::setsenderCity(string sender_c)
{
senderCity = sender_c;
}
string Package::getSendCity()
{
return senderCity;
}
void Package::setsenderState(string sender_s)
{
senderState = sender_s;
}
string Package::getsenderState()
{
return senderState;
}
void Package::setsenderZIP(string sender_Z)
{
senderZIP = sender_Z;
}
string Package::getsenderZIP()
{
return senderZIP;
}
void Package::setrecipientName(string recipient_n)
{
recipientName = recipient_n;
}
string Package::getrecipientName()
{
return recipientName;
}
void Package::setrecipientAddress(string recipient_addr)
{
recipientAddress = recipient_addr;
}
string Package::getrecipientAddress()
{
return recipientAddress;
}
void Package::setrecipientCity(string recipient_c)
{
recipientCity = recipient_c;
}
string Package::getrecipientCity()
{
return recipientCity;
}
void Package::setrecipientState(string recipient_s)
{
recipientState = recipient_s;
}
string Package::getrecipientState()
{
return recipientState;
}
void Package::setrecipientZIP(string recipient_Z)
{
recipientZIP = recipient_Z;
}
string Package::getrecipientZIP()
{
return recipientZIP;
}
void Package::setweight(double w)
{
weight = (w < 0.0) ? 0.0 : w;
}
double Package::getweight()
{
return weight;
}
void Package::setcostperounce(double cost)
{
costperounce = (cost < 0.0) ? 0.0 : cost;
}
double Package::getcostperounce()
{
return costperounce;
}
double Package::calculateCost()
{
double result;
result = weight * costperounce;
return result;
}
class TwoDayPackage : public Package {
private :
double two_day_delivery_fee;
public :
TwoDayPackage(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost,double delivery_fee);
double gettwo_day_delivery_fee();
void settwo_day_delivery_fee(double delivery_fee);
double calculateCost();
};
TwoDayPackage::TwoDayPackage(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost,double delivery_fee)
: Package(sender_n,sender_addr,sender_c,sender_s,sender_Z,recipient_n,recipient_addr,recipient_c,recipient_s,recipient_Z,wei,cost)
{settwo_day_delivery_fee(delivery_fee);
}
double TwoDayPackage::gettwo_day_delivery_fee()
{
return two_day_delivery_fee;
}
void TwoDayPackage::settwo_day_delivery_fee(double delivery_fee)
{
two_day_delivery_fee = delivery_fee;
}
double TwoDayPackage::calculateCost()
{
double result;
result = Package::calculateCost() + two_day_delivery_fee;
return result;
}

class OvernightPackage:public Package
{
private :
double overnight_delivery_fee;
public :
OvernightPackage(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost,double delivery_fee);
double calculateCost();
double getovernight_delivery_fee();
void setovernight_delivery_fee(double delivery_fee);
};
OvernightPackage::OvernightPackage(string sender_n,string sender_addr,string sender_c,string sender_s,string sender_Z,string recipient_n,string recipient_addr,string recipient_c,string recipient_s,string recipient_Z,double wei,double cost,double delivery_fee)
:Package(sender_n,sender_addr,sender_c,sender_s,sender_Z,recipient_n,recipient_addr,recipient_c,recipient_s,recipient_Z,wei,cost)
{
setovernight_delivery_fee(delivery_fee);
}
double OvernightPackage::getovernight_delivery_fee()
{
return overnight_delivery_fee;
}
void OvernightPackage::setovernight_delivery_fee(double delivery_fee)
{
overnight_delivery_fee = delivery_fee;
}
double OvernightPackage::calculateCost()
{
double result;
result=(getcostperounce() + overnight_delivery_fee) * getweight();
return result;
}
int main(int argc, char* argv[])
{
OvernightPackage item1("Kane Williams","12,Church Street","Mumbai","Maharastra","32456","Mike","23,Park Street","Banglore","Karnataka","53455",15.00,2.50,1.90);
TwoDayPackage item2("Sachin Tendulkar","12,Bandhra Street","Mumbai","Maharastra","43556","Jimmy","12,Race Course Road","Banglore","Karnataka","21345",20.00,1.50,9.50);
cout << fixed << setprecision(2);
cout << "======================================\n";
cout << "Overnight Delivery\n";
cout << "Sender " <<item1.getsenderName() << "\n";
cout << " " << item1.getsenderAddress() << "\n";
cout <<" " << item1.getSendCity() <<" "<<item1.getsenderState() <<" "<<item1.getsenderZIP()<<"\n";
cout << "\n";
cout << "Recipient " << item1.getrecipientName() << "\n";
cout << " " << item1.getsenderAddress() << "\n";
cout << " " << item1.getrecipientCity() << " " <<
item1.getrecipientState() << " " << item1.getrecipientZIP() << "\n";
cout << "Cost $ " << item1.calculateCost() << "\n";
cout << "======================================\n";
cout << "\n\n";
cout << "======================================\n";
cout << "Sender " << item2.getsenderName() << "\n";
cout << " " << item2.getsenderAddress() << "\n";
cout<<" "<< item2.getSendCity()<<" "<<item2.getsenderState()<<" "<<item2.getsenderZIP()<< "\n";
cout << "\n";
cout << "Recipient " << item2.getrecipientName() << "\n";
cout << " " << item2.getsenderAddress() << "\n";
cout<<" "<<item2.getrecipientCity()<<" "<<item2.getrecipientState()<<" "<< item2.getrecipientZIP()<<"\n";
cout << "Cost $ " << item2.calculateCost() << "\n";
cout << "======================================\n";

system("pause");

return 0;

}

=====================================

output:

===============================Thank You


Related Solutions

use c++ Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number...
use c++ Package Inheritance Hierarchy) Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of different shipping options, each with specific costs associated. Create an inheritance hierarchy to represent various types of packages. Use class Package as the base class of the hierarchy, then include classes TwoDayPackage and OvernightPackage that derive from Package. Base-class Package should include data members representing the name, address, city, state and ZIP code for both the sender and the recipient of the package,...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this...
ONLY USE VISUAL STUDIO (NO JAVA CODING) VISUAL STUDIO -> C# -> CONSOLE APPLICATION In this part of the assignment, you are required to create a C# Console Application project. The project name should be A3<FirstName><LastName>P2. For example, a student with first name John and Last name Smith would name the project A1JohnSmithP2. Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper. This program will use a menu...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions:...
Visual Studio C# Create an application illustrating the following: Class definition Encapsulation Constructor Instantiation Inheritance Suggestions: Simulation Calculation Interface apps
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write...
MUST BE WRITTEN IN ASSEMBLY LANGUAGE ONLY AND MUST COMPILE IN VISUAL STUDIO You will write a simple assembly language program that performs a few arithmetic operations. This will require you to establish your programming environment and create the capability to assemble and execute the assembly programs that are part of this course. Your \student ID number is a 7-digit number. Begin by splitting your student ID into two different values. Assign the three most significant digits to a variable...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the...
In c++, when dealing with inheritance in a class hierarchy, a derived class often has the opportunity to overload or override an inherited member function. What is the difference? and which one is the better?
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
Must be written in C++ in Visual studios community In this lab, you will modify the...
Must be written in C++ in Visual studios community In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed...
Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT