Question

In: Computer Science

In c++ format please ABC Delivery promises to deliver any package from one location in Miami...

In c++ format please

ABC Delivery promises to deliver any package from one location in Miami Dade County to another in 2 to 24 hours. They can handle packages from 0.1 to 100 pounds. Their rate table is below:

  • Flat rate for all deliveries = $50
  • To that they add $0.50 per pound
  • To that they add a speed surcharge of $100 if request is between 2 and 4 hours and $50 if request is between 5 to 7 hours.

Write a program that asks the user for the package weight. If the range is acceptable, ask for the delivery speed. If the range is acceptable, proceed with calculating the delivery cost.

Prompt:

Enter a shipping weight (in pounds) up to 100 lbs:

How soon do you need this delivered? Enter a number of hours between 2 and 24:

Possible Outputs (the numbers do not output, they are for clarification only)

1) Invalid weight

2) Invalid number of hours

3) We can make that delivery!
The total price of your 100-pound package delivered within 5 hours is $150

Notes and Hints:

1) Nothing weighs zero pounds. Reject that type of entry.

2) Hours must be a whole number entry from user. Weight can include decimal.

3) There are many ways to solve this. You only need what you learned in class today (nothing from future lessons). The best solutions are those that minimize CPU time by reducing how many conditions it has to check. Be creative and think this through before you start coding!

Solutions

Expert Solution

As per your requirement, here is the C++ code:

Rawcode:

//including libraries
#include <iostream>
#include <stdlib.h>
//using namespace
using namespace std;
//main function
int main(){
   //declaring variables
   double weight, totalPrice;
   int hours, flatRate = 50, surcharge;
   //prompting user to enter shipping weight
   cout << "Enter a shipping weight (in pounds) up to 100 lbs: ";
   //scanning it into a variable
   cin >> weight;
   //checking if weight is less than or equal to 0 or weight is greater than 100
   if(weight <= 0 || weight > 100){
       //if above condition is true then print user that it is invalid weight
       cout << "Invalid weight" << endl;
       //terminating the program
       exit(EXIT_FAILURE);
   }
   //asking user to enter the number of hours he needed to deliver the package
   cout << "How soon do you need this delivered? Enter a number of hours between 2 and 24: ";
   //scanning it into a variable
   cin >> hours;
   //checking if the hours entered by user is less than or equal to 24 and greater than or equal to 2
   if(hours <= 24 && hours >= 2){
       //checking if hours are between 2 and 4
       if(hours >= 2 && hours <= 4){
           //if above condition is true then set surcharge of 100
           surcharge = 100;
           //calculating total price
           totalPrice = (0.50 * weight) + flatRate + surcharge;
           //printing that we can make delivery
           cout << "We can make that delivery!" << endl;
           //printing the total price
           cout << "The total price of your "<< weight << "-pound package delivered within " << hours << " hours is $" << totalPrice << endl;
       }
       //checking if hours are between 5 and 7
       else if(hours >= 5 && hours <= 7){
           //if above condition is true then set surcharge of 50
           surcharge = 50;
           //calculating total price
           totalPrice = (0.50 * weight) + flatRate + surcharge;
           //printing that we can make delivery
           cout << "We can make that delivery!" << endl;
           //printing the total price
           cout << "The total price of your "<< weight << "-pound package delivered within " << hours << " hours is $" << totalPrice << endl;
       }
       //checking if other hours entered between 2 and 24
       else{
           //calculating total price
           totalPrice = (0.50 * weight) + flatRate;
           //printing that we can make delivery
           cout << "We can make that delivery!" << endl;
           //printing the total price
           cout << "The total price of your "<< weight << "-pound package delivered within " << hours << " hours is $" << totalPrice << endl;
       }
   }
   //if above condition is not true
   else{
       //then printing that they are invalid hours
       cout << "Invalid number of hours" << endl;
   }
   return 0;
}

Here is the screenshots of source code:

Here is the screenshot of output:

Hope this helps you. Please feel free to ask if you still have any queries.

Do upvote. Thank you !


Related Solutions

Your express package delivery company is drawing up new zones for the location of drop boxes...
Your express package delivery company is drawing up new zones for the location of drop boxes for customers. The city has been divided into six zones. You have targeted seven possible locations for drop boxes. The list of which zones the drop boxes could serve is shown below Possible Drop Box Location Can serve Zones Location 1 2, 5, 6 Location 2 1, 3, 6 Location 3 2, 4, 5 Location 4 1, 2, 6 Location 5 3, 4, 5...
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...
On March 1, 2021, Gold Examiner receives $154,000 from a local bank and promises to deliver...
On March 1, 2021, Gold Examiner receives $154,000 from a local bank and promises to deliver 96 units of certified 1-oz. gold bars on a future date. The contract states that ownership passes to the bank when Gold Examiner delivers the products to Brink’s, a third-party carrier. In addition, Gold Examiner has agreed to provide a replacement shipment at no additional cost if the product is lost in transit. The stand-alone price of a gold bar is $1,560 per unit,...
On March 1, 2018, Gold Examiner receives $149,000 from a local bank and promises to deliver...
On March 1, 2018, Gold Examiner receives $149,000 from a local bank and promises to deliver 94 units of certified 1-oz. gold bars on a future date. The contract states that ownership passes to the bank when Gold Examiner delivers the products to Brink’s, a third-party carrier. In addition, Gold Examiner has agreed to provide a replacement shipment at no additional cost if the product is lost in transit. The stand-alone price of a gold bar is $1,410 per unit,...
On March 1, 2018, Gold Examiner receives $150,000 from a local bank and promises to deliver...
On March 1, 2018, Gold Examiner receives $150,000 from a local bank and promises to deliver 96 units of certified 1-oz. gold bars on a future date. The contract states that ownership passes to the bank when Gold Examiner delivers the products to Brink’s, a third-party carrier. In addition, Gold Examiner has agreed to provide a replacement shipment at no additional cost if the product is lost in transit. The stand-alone price of a gold bar is $1,560 per unit,...
On March 1, 2018, Gold Examiner receives $155,000 from a local bank and promises to deliver...
On March 1, 2018, Gold Examiner receives $155,000 from a local bank and promises to deliver 96 units of certified 1-oz. gold bars on a future date. The contract states that ownership passes to the bank when Gold Examiner delivers the products to Brink’s, a third-party carrier. In addition, Gold Examiner has agreed to provide a replacement shipment at no additional cost if the product is lost in transit. The stand-alone price of a gold bar is $1,560 per unit,...
ABC Inc is a package delivery company that has branches all over Canada. The Sender (person...
ABC Inc is a package delivery company that has branches all over Canada. The Sender (person who is sending a package) can drop a package to any of the branches and pay the applicable fee and taxes. ABC staff members sort and forward the packages to an office close to the destination addressees. Each branch office has a manager along with other staff members. The manager creates a weekly schedule for the staff members for the hours they are supposed...
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,...
ABC Clothiers, Inc., has a contract with Taylor & Sons, a retailer, to deliver one thousand...
ABC Clothiers, Inc., has a contract with Taylor & Sons, a retailer, to deliver one thousand summer suits to Taylor’s place of business on or before May 1. On April 1, Taylor receives a letter from ABC informing him that ABC will not be able to make the delivery as scheduled. Taylor is very upset, as he had planned a big ad campaign. Can Taylor immediately sue ABC for breach of contract (on April 2)? Suppose that Taylor’s son, Tom,...
ABC Ltd initiated a one-person pension plan in January 2012 that promises the employee a pension...
ABC Ltd initiated a one-person pension plan in January 2012 that promises the employee a pension on retirement according to the following formula: pension benefit = 2.5% of final salary per year of service after the plan initiation. The employee began employment with ABC Ltd early in 2009 at age 33, and expects to retire at the end of 2035, the year in which he turns 60. His life expectancy at that time is 21 years. Assume that this employee...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT