C Write a program to compute the charge for mailing a series
C++
Write a program to compute the charge for mailing a series of packages. The charge for a package is based on its weight (int) and volume (int). There is a charge of $4.00 per pound for the first 2 pounds of package weight, $3.00 per pound for each pound between 2 and 6 pounds and $2.00 per pound charge for the package weight over 6 pounds. There is no additional charge for a package whose volume is 2000 cubic inches or less. There is an additional charge of $0.01 per cubic inch of package volume over 2000 cubic inches. For example if a package weighs 13 pounds and has a volume of 3000 cubic inches then the charge is 4.0*2.00 + 3.0*4.00 + 2.00*7.00 = $34.00 for the weight. Then because the volume is over 2000 cubic inches an additional 1000*0.01 = $10.00 would be added to the charge giving $44.40. There is a minimum charge of $6.00 so if the charge for a package computes to be less than $6.00 it is still charged as $6.00. The program must also compute the total number, weight, volume and charges for all the packages at the end of the transaction. With the fuel cost fluctuate rapidly; it is possible that you may have to change the rate that you charge the customers. So design your program accordingly.
This program must use a while-controlled input loop. Input the package weight right before the loop and at the end of the loop. The complete interactive I/O for this program should look like the sample below.
Input: the user should insert the following for each package:
• The package weight in pounds (one integer).
• The 3 dimensions for each package (three integers).
Once the user is finished, he should insert -1 as the weight to end the program.
Output: as shown in the sample below, the output should show the detailed charges for every package. For example if the volume is over 2000 cubic inches, your program output should printout the extra charges for the extra volume. The samples below cover the 3 possible cases for any package.
These cases are:
1. No extra volume charges.
2. Extra volume charges.
3. Final Package Charge is less than $6.
Once the user ends the program “by inserting -1” the program must printout a summary for the whole processed packages (see the sample below). Note that computer stores the weight in float type which may not be very precise. It is recommended that you test for negative weight instead of doing an equality testing.
Solution
#include<bits/stdc++.h>
using namespace std;
float First2Pounds=4.00f;
float _2to6Pounds=3.00f;
float Above6Pounds=2.00f;
float DefaultFreeVolume=2000.00f;
float ExtraVolumeCost=0.01f;
float MinCharge=6.00f;
float calCulateVolume(float l,float b,float h)
{
return l*b*h;
}
int ChangeRate()
{
char ch;
cout<<\"Do you want to change cost for First 2 Pounds(y/n)\ \";
cin>>ch;
if(ch==\'y\')
{
cout<<\"Enter new cost\ \";
cin>>First2Pounds;
}
cout<<\"Do you want to change cost for 2 to 6 Pounds(y/n)\ \";
cin>>ch;
if(ch==\'y\')
{
cout<<\"Enter new cost\ \";
cin>>_2to6Pounds;
}
cout<<\"Do you want to change cost for Extra Volume charge(y/n)\ \";
cin>>ch;
if(ch==\'y\')
{ cout<<\"Enter new cost\ \";
cin>>ExtraVolumeCost;
}
cout<<\"Do you want to change Deafult minimum free Volume (y/n)\ \";
cin>>ch;
if(ch==\'y\')
{
cout<<\"Enter new Volume\ \";
cin>>DefaultFreeVolume;
}
cout<<\"Do you want to change Minimum Charge (y/n)\ \";
cin>>ch;
if(ch==\'y\')
{
cout<<\"Enter new charge\ \";
cin>>MinCharge;
}
}
int main(int argc, char const *argv[])
{
char ch;
cout<<\"Do you want to change rate (y/n)\ \";
cin>>ch;
if(ch==\'y\')
{
ChangeRate();
}
int flag=1;
while(flag)
{
float PackageWeight,PackageLength,PackageBreadth,PackageHeight;
LOOP:
cout<<\"Enter Package Weight in Pounds\ \";
cin>>PackageWeight;
if(PackageWeight<0.0f)
{
cout<<\"Cant be negative\";
goto LOOP;
}
cout<<\"Enter Length of package\ \";
cin>>PackageLength;
cout<<\"Enter Breadth of package\ \";
cin>>PackageBreadth;
cout<<\"Enter Height of package\ \";
cin>>PackageHeight;
float PackageVolume=calCulateVolume(PackageLength,PackageBreadth,PackageHeight);
float TotalCharge=0;
if(PackageWeight>=2)
{
PackageWeight=PackageWeight-2;
TotalCharge+=2*First2Pounds;
}
if(PackageWeight>=4)
{
PackageWeight=PackageWeight-4;
TotalCharge+=4*_2to6Pounds;
}
if(PackageWeight>=6)
{
TotalCharge+=PackageWeight*Above6Pounds;
}
float ExtraVolume;
if(PackageVolume>DefaultFreeVolume)
{
ExtraVolume=PackageVolume-DefaultFreeVolume;
TotalCharge=TotalCharge+ExtraVolume*ExtraVolumeCost;
}
if(TotalCharge<MinCharge)
{
TotalCharge=MinCharge;
}
int ch;
cout<<\"Enter -1 to get Details of Package\ \";
cin>>ch;
if(ch==-1)
{
cout<<\"Extra Volume is \"<<ExtraVolume<<\"\ \";
cout<<\"Total Charge is \"<<TotalCharge<<\"\ \";
}
}
return 0;
}




