100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 Assignment 2 2024 solution, full working code $5.15
Add to cart

Other

COS1512 Assignment 2 2024 solution, full working code

 106 views  5 purchases
  • Course
  • Institution

COS1512 Assignment 2 2024 solution, full working code

Preview 2 out of 8  pages

  • July 2, 2024
  • 8
  • 2023/2024
  • Other
  • Unknown
avatar-seller
COS1512 2024 Assignment 2 ready
to submit solutions

Question 1
#include <iostream>
#include <cmath> // For ceil function


using namespace std;
// Constants for cost per kg
const double GLOBALMAIL_COST_ZONE_1_TO_3 = 108.0;
const double GLOBALMAIL_COST_ZONE_4_TO_6 = 130.0;
const double DHL_COST_PER_KG = 70.0;
const int VOLUMETRIC_WEIGHT_DIVISOR = 5000;


// Function to calculate volumetric weight
double calculateVolumetricWeight(double length, double width,
double height) {
return (length * width * height) / VOLUMETRIC_WEIGHT_DIVISOR;
}


// Function to calculate cost using GlobalMail
double calcPostage(double weight, int zone) {
if (zone >= 1 && zone <= 3) {
return weight * GLOBALMAIL_COST_ZONE_1_TO_3;
} else if (zone >= 4 && zone <= 6) {
return weight * GLOBALMAIL_COST_ZONE_4_TO_6;
} else {
cout << "Invalid zone. Please choose a zone between 1 and
6." <<endl;
return 0.0;
}

, }


// Function to calculate cost using DHL
double calcPostage(double actualWeight, double length, double
width, double height) {
double volumetricWeight = calculateVolumetricWeight(length,
width, height);
double chargeableWeight = max(actualWeight, volumetricWeight);
return chargeableWeight * DHL_COST_PER_KG;
}


int main() {
char shippingMethod;
cout << "Choose shipping method (g for GlobalMail, d for DHL):
";
cin >> shippingMethod;


if (shippingMethod == 'g' || shippingMethod == 'G') {
int zone;
cout << "Enter the zone (1 to 6): ";
cin >> zone;
double weight;
cout << "Enter the weight of the parcel (in kg): ";
cin >> weight;
double totalCost = calcPostage(weight, zone);
cout << "Total cost using GlobalMail: R" << totalCost <<
endl;
} else if (shippingMethod == 'd' || shippingMethod == 'D') {
double length, width, height, actualWeight;
cout << "Enter the length of the box (in cm): ";
cin >> length;
cout << "Enter the width of the box (in cm): ";
cin >> width;

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller foxNotes. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.15. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

52355 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.15  5x  sold
  • (0)
Add to cart
Added