Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187
All the code and pictures, ready to submit
,Question 1 A program that will calculate the price to be
paid for sending a parcel to London.
Output
When you enter ‘d’ for DHL
When you enter ‘g’ for GLOBALMAIL and zone 1-3
When you enter ‘g’ for GLOBALMAIL and zone 4-6
, Source code:
#include <iostream>
using namespace std;
const double GLOBALMAIL_ZONE_1_TO_3 = 108.0;
const double GLOBALMAIL_ZONE_4_TO_6 = 130.0;
const double DHL_RATE = 70.0;
const double VOLUMETRIC_WEIGHT_DIVISOR = 5000.0;
double calcPostage(double weight, int zone) {
if (zone >= 1 && zone <= 3) {
return weight * GLOBALMAIL_ZONE_1_TO_3;
} else if (zone >= 4 && zone <= 6) {
return weight * GLOBALMAIL_ZONE_4_TO_6;
} else {
cout << "Invalid zone. Please enter a value between 1 and 6." << endl;
return 0.0;
}
}
double calcPostage(double weight, double length, double width, double height) {
double volumetricWeight = (length * width * height) /
VOLUMETRIC_WEIGHT_DIVISOR;
double highestWeight = (weight > volumetricWeight)? weight :
volumetricWeight;
return highestWeight * DHL_RATE;
}
int main() {
char choice;
cout << "Do you want to use GlobalMail (g) or DHL (d)?" << endl;
cin >> choice;
if (choice == 'g') {
int zone;
double weight;
cout << "Enter the weight of the parcel (in kg): ";
cin >> weight;
cout << "Enter the zone (1-6): ";
cin >> zone;
if(zone >0 && zone <= 6){
double cost = calcPostage(weight, zone);
cout << "The total cost is R" << cost << endl;
}
}
else if (choice == 'd') {
double weight, length, width, height;
cout << "Enter the weight of the parcel (in kg): ";
cin >> weight;
cout << "Enter the length of the box (in cm): ";
cin >> length;
cout << "Enter the width of the box (in cm): ";
cin >> width;
cout << "Enter the height of the box (in cm): ";