100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 Assignment 2 memo 2024 CA$7.96   Add to cart

Other

COS1512 Assignment 2 memo 2024

 162 views  9 purchases
  • Course
  • Institution

COS1512 Assignment 2 memo 2024 Question 1 Peter wants to send a box containing a painting to London. The Post Office sends parcels to London via GlobalMail or DHL. If GlobalMail is chosen, the cost is R108 per kg if the parcel goes to zone 1 to 3 in London, and R130 per kg if the parcel goes to...

[Show more]

Preview 3 out of 10  pages

  • July 1, 2024
  • 10
  • 2023/2024
  • Other
  • Unknown
avatar-seller
COS1512 2024 Assignment 2 memo

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): ";

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 CrystalIndigo. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 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
CA$7.96  9x  sold
  • (0)
  Add to cart