Question

C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...

C++

Lone Star Package Service ships packages within the state of Texas. Packages are accepted for shipping subject to the following restrictions:

Shipping requirements

  • The package weight must not exceed 50 pounds.
  • The package must not exceed 3 feet in length, width, or height.
  • The girth of the package must not exceed 5 feet. The girth is the circumference around the two smallest sides of the package. If side1, side2, and side3 are the lengths of the three sides, and largest is the largest of the three sides, then the girth can be calculated using:
    girth = 2 * ( side1 + side2 + side3 - largest )

For each transaction (package to be shipped), the user should enter the package weight followed by the 3 package dimensions in any order. The weight should be specified as a whole number of pounds and the dimensions are specified as a whole number of inches.

To end the program, the user should enter a weight of -1. When the user enters -1 to end the program, they should not have to enter values for the 3 package dimensions. That is, when the user is ready to end the program, they should only have to enter the weight:

Enter package weight and 3 dimensions: -1

They should not have to enter:

Enter package weight and 3 dimensions: -1 0 0 0

Input Validation

Check to be sure that the user enters positive numbers for the package weight and dimensions (weight and dimensions must be larger than zero). For transactions with invalid weight or dimensions, print an error message and skip the transaction.

The shipping charge is based on the following table. This table may be represented in your program as parallel arrays (two one-dimensional arrays), one for the weight and one for the shipping charge. Alternatively, you may define a struct or simple class to represent one table entry (one weight and cost). Then the table would be an array of structs or an array of objects.

Note: Do not use a two-dimensional array to store the weights and costs. The weights need to be stored as integers, and the costs need to be stored as floating-point values. So they cannot be mixed in one array.

You can initialize the array elements in the array declarations using the values from the table below.

Weight

Shipping Charge

1

1.50

2

2.10

3

4.00

5

6.75

7

9.90

10

14.95

13

19.40

16

24.20

20

27.30

25

31.90

30

38.50

35

43.50

40

44.80

45

47.40

50

55.20

To determine the shipping charge, search the weight array for the package weight and then use the corresponding element from the shipping charge array. For example, the shipping charge for a 3 pound package would be $4.00. If the package weight falls between the weights in the weight table, use the larger weight. For example, the shipping charge for a 4 pound package would be 6.75. Do not hard code these values into your program code. For example, you should NOT have code like:

if ( packageWeight == 4 || packageWeight == 5)
   shippingCost = 6.75;

If you need a hint, check here:

programming assignment 7 hint

Output

Note that you should be able to write this program with only two loops, a transaction processing loop and a cost search loop. You do not need an input validation loop. If the package input is invalid, just print an error message and skip the normal package processing.

I want you to input the package information, process the package and output some information about the package in a single loop (the transaction processing loop).

Your program output should look similar to the example below.

Note: Do not store the package information in an array or vector. If you process a lot of packages, you will eventually run out of space in the array. If you use a vector, as you process more transactions you will eat up more and more memory. This program should be designed to run for long periods of time without running out of memory.

For each transaction, print:

  • the transaction number (start counting with 1)
  • whether the package was accepted or rejected
  • the package weight
  • the cost for shipping (if applicable)

When the program ends, print the number of packages accepted for shipping and the number of packages rejected. Transactions that contain invalid input should not be counted (see Input Validation section).

The screen dialog should look similar to this (user input is shown in bold):

For each transaction, enter package weight and 3 dimensions.
Enter -1 to quit.

Enter package weight and 3 dimensions: 1 2 3 3

Transaction:         1
Status     :  Accepted
Weight     :         1
Cost       :      1.50

Enter package weight and 3 dimensions: 7 4 2 3

Transaction:         2
Status     :  Accepted
Weight     :         7
Cost       :      9.90

Enter package weight and 3 dimensions: 21 12 15 12

Transaction:         3
Status     :  Accepted
Weight     :        21
Cost       :     31.90

Enter package weight and 3 dimensions: 45 12 20 2

Transaction:         4
Status     :  Accepted
Weight     :        45
Cost       :     47.40

Enter package weight and 3 dimensions: 49 24 40 20

Transaction:         5
Status     :  Rejected
Weight     :        49
Cost       :         -

Enter package weight and 3 dimensions: 25 35 30 20

Transaction:         6
Status     :  Rejected
Weight     :        25
Cost       :         -

Enter package weight and 3 dimensions: 68 10 20 10

Transaction:         7
Status     :  Rejected
Weight     :        68
Cost       :         -

Enter package weight and 3 dimensions: 50 0 10 10

Error - package weight and dimensions must be larger than 0
Please re-enter transaction

Enter package weight and 3 dimensions: 50 10 10 10

Transaction:         8
Status     :  Accepted
Weight     :        50
Cost       :     55.20

Enter package weight and 3 dimensions: 45 20 20 20

Transaction:         9
Status     :  Rejected
Weight     :        45
Cost       :         -

Enter package weight and 3 dimensions: -1

Number of accepted packages: 5
Number of rejected packages: 4

Additional Requirements:

  1. Do not use global variables in any assignment. A global variable is a variable that is declared outside any function. It is okay to use global constants.
  2. You must use multiple functions in this program. Do not write the program as one large main function.
  3. Do not store the transaction information in arrays or vectors. When you store transactions in arrays, you set a limit on the number of transactions your program can process. For this program, you should be able to read and process transactions one at a time.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The Code below will help you generate the required results.

main.cpp

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

   //struct
   const int SIZE = 15;
  
   struct packInfo
   {
       int trans;                  
       string status;              
       double pkgwt;          
       double pkgCost;              
   };

int getLargest(int s1, int s2, int s3)
   {
       int l;
       if (s1 > 0 && s2 > 0 && s3 > 0)
       {
           if (s1 > s2 && s1 > s3)
               l = s1;
           else if (s2 > s1 && s2 > s3)
               l = s2;
           else if ( s3 > s1 && s3 > s2)
               l = s3;
       }
       else
           cout << "Package weight and dimensions must be larger than 0" << endl;
           //error message if length is too big
       return l;
   }
  

   void displayHead()
   {
   cout<<"For each transaction, enter package weight and 3 dimensions.\n"<<"Enter -1 to quit"<<endl<<endl;
   }


   int main ()
   {
   packInfo pack;
      
       //declare variables and arrays
       int transNum = 0 ,length = 0, width = 0, height = 0;                  
       int girth = 0, largest = 0, index = 0, numGood = 0;          
       int numBad = 0;                  
       string status = " ";
       int weight[SIZE] = {1, 2, 3, 5, 7, 10, 13, 16, 20, 25, 30, 35, 40, 45, 50};
       double shipping[SIZE] = {1.50, 2.10, 4.00, 6.75, 9.90, 14.95, 19.40, 24.40, 27.30, 31.90, 38.50, 43.50, 44.80, 47.40, 55.20};

  displayHead();
       cout <<"Enter pack weight in pounds and 3 dimensions: ";
       // get input
       cin >> pack.pkgwt >> length >> width >> height;

       while (pack.pkgwt > 0)
       {
          
           if ((length <= 0)||(width <= 0)||(height <= 0)||(pack.pkgwt <= 0))
       {
           cout << "Error: Enter Valid Dimensioins" << endl <<"Please Re-Enter Transaction";
           cout<<endl;
           cout <<"Enter pack weight in pounds and 3 dimensions: ";
           cin >> pack.pkgwt >> length >> width >> height;
       }
           //search the arrays for location
           for (int i = 0; i < 15; i++)
           {
               if (pack.pkgwt == weight[i])
               {
                   index = i;
                   break;
               }
               else if (pack.pkgwt >= weight[i])
                   continue;
               else
               {
                   pack.pkgwt = weight[i];
                   index = i;
                   break;
               }
           }

           pack.pkgCost = shipping[index];

           transNum++;
           pack.trans = transNum;

//get the largest number
           largest = getLargest(length, width, height);

           //girth calc
           girth = 2 * (length + width + height - largest);
          
           //determine pack status
           if ((girth > 60)||(pack.pkgwt > 50))
           {
               pack.status = "Rejected";
               numBad++;
               pack.pkgCost = 0;
           }
           else {
               pack.status = "Accepted";
               numGood++;
           }
          
           cout << endl;
       cout << "Transaction :" << setw(5) << pack.trans <<endl;
       cout << "Status :" << setw(5) <<pack.status<<endl;
       cout << "Weight :" << setw(5) <<pack.pkgwt<<endl;
       cout << "Cost :"<< setw(5) << pack.pkgCost << endl << endl;
      
           cout <<"Enter pack weight in pounds and 3 dimensions: ";
           cin >> pack.pkgwt;
           if (pack.pkgwt > 0)
           {
               cin >> length >> width >> height;
           }
           else
           {
               break;
           }
       }
       cout << "Number of Accepted packs: " << numGood << endl;
       cout << "Number of Rejected packs: " << numBad << endl;

       return 0;
   }

Output

Add a comment
Know the answer?
Add Answer to:
C++ Lone Star Package Service ships packages within the state of Texas. Packages are accepted for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you...

    C PROGRAMMING Introduction In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person! Shipping Calculator Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the...

  • An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit...

    An Internet service provider offers four subscription packages to its customers, plus a discount for nonprofit organizations: Package A: 10 hours of access for $12.95 per month. Additional hours are $4.00 per hour. Package B: 20 hours of access for $14.95 per month. Additional hours are $2.00 per hour. Package C: 30 hours of access for $20 per month. Additional hours are $1.00 per hour. Package D: Unlimited access for $35.95 per month. A nonprofit organizations will get 20% discount...

  • C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of...

    C++ Model rocket engines (or motors) are generally purchases in boxes of 24 or packages of 3. If I want 32 engines I would need to purchase 1 box of 24 and 3 packages of 3 (I would end up with 1 extra engine). Write a program that calculates how many boxes and packages you must purchase to get a specific number of engines. Also enter the price of a box and a package and calculate the total cost of...

  • please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you...

    please post ONLY flatratepackage.cpp, flateratepackage.h, package inventory.h and package inventory.cpp... Thank you! In this homework, you are going to write a program to represent various types of packages offered by package-delivery services. You need to create an inheritance hierarchy to represent various types of packages with different shipping options and associated costs. The base class is Package and the derived classes are FlatRatePackage and OvernightPackage. The base class Package includes the following attributes: • Sender information: senderName (string), senderAddress (string),...

  • write a program for C++ to use on Putty . C++ not Java The Fast Freight...

    write a program for C++ to use on Putty . C++ not Java The Fast Freight Company provides three kinds of shipping services for packages: regular, priority and overnight. They charge the following rates: Regular Priority Overnight <= 2 Kg $1.00 per Kg $3.50 per Kg $11.50 per Kg > 2 Kg but <=6 Kg $1.50 per Kg $5.50 per Kg $16.50 per Kg > 6 Kg but <=10 Kg $2.00 per Kg $7.50 per Kg $21.50 per Kg >...

  • In this assignment, you will develop a C++ program which calculates a shipping charge and determines...

    In this assignment, you will develop a C++ program which calculates a shipping charge and determines the “type of trip” for a freight shipping company. Ask the user to enter the distance a package is to be shipped, and use a menu and a switch statement to determine the rate based on the package’s weight. Then display the shipping charge and using the table in #7 below, display the type of trip. Below is the chart to use to calculate...

  • C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as...

    C++ IMPORTANT: Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Write a driver program (PackageDriver) that creates objects of each type of Package as pointers to a Package and cout the objects. Package-delivery services, such as FedEx®, DHL® and UPS®, offer a number of...

  • Drink Machine Simulator C++

    Drink Machine SimulatorThe purpose of this exercise is to give you practice with abstract data types, namely structures and arrays of structures.Write a program that simulates a softdrink machine. The program should use a structure that stores the following data:Drink NameDrink CostNumber of Drinks in MachineThe program should create an array of five structures. The elements should be initialized with the following data:Drink Name Cost Number in MachineCoca-Cola .75 20Root Beer .75 20Sprite .75 20Spring Water .80 20Apple Juice .80...

  • A cruise ship offers the following packages for 5 day / 4 night Cruise & Stay....

    A cruise ship offers the following packages for 5 day / 4 night Cruise & Stay. Package 1. Room only Rate $1000.00 $1000.00 $200.00 for each person sharing the room (Maximum 3) 2. Room plus Meals Discount Details (just for package 2): -$50.00: if just one of the occupant is 17 or under $80.00: if at least two of the occupants are 17 or under Write a program to ask the user the following information The package type (R: Room...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT