100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
COS1512 Assignment 2 2024 | Due 12 July 2024 $2.85   Add to cart

Exam (elaborations)

COS1512 Assignment 2 2024 | Due 12 July 2024

 24 views  2 purchases
  • Course
  • Institution
  • Book

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 zone 4 to 6. If DHL is chosen, ...

[Show more]

Preview 2 out of 11  pages

  • June 24, 2024
  • 11
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
, PLEASE USE THIS DOCUMENT AS A GUIDE TO ANSWER YOUR ASSIGNMENT


Please note that the author of this document will not responsibility for any plagiarizing you
commit.

 Question 1

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 zone 4 to 6. If DHL is chosen,
the actual weight is compared to the volumetric weight, and whichever is the higher weight, is
used in the calculation. The volumetric weight is calculated by the formula (length * width *
height) / 5000, where length, width and height is the size of the box in cm. The cost per kg for
DHL is R70. Write a program that will calculate the price to be paid for sending a parcel to
London. The program must use two overloaded functions, each named calcPostage. The user
must be asked if he wants to use GlobalMail or DHL. Define a char variable and ask the user to
input „d‟ for DHL or „g‟ for GlobalMail. If he chooses GlobalMail, the zone must be requested.
The program must validate that the zone is between 1 and 6. If he chooses DHL, the length,
width and height of the box must be requested. The first function will receive two parameters,
one of type double representing the weight of the parcel, and one of type int, representing the
zone. The second function will receive four parameters of type double, representing the actual
weight, and the length, width and height of the box in cms. The second function will first
determine whether the actual weight or the volumetric weight is the highest, before calculating
the cost. Both functions will return the cost in a variable of type double. The main function
should then display the total cost. Define const variables where applicable.

PROGRAM
#include <iostream>
#include <iomanip>

using namespace std;

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 double VOLUME_WEIGHT_DIVISOR = 5000.0;

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 {
cerr << "Invalid zone provided." << endl;
return 0.0;
}
}

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

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

67096 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
$2.85  2x  sold
  • (0)
  Add to cart