Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4,6 TrustPilot
logo-home
Document preview thumbnail
Preview 3 out of 22 pages
Exam (elaborations)

COS1512 Assignment 2 2024 (199828) - DUE 12 July 2024

Document preview thumbnail
Preview 3 out of 22 pages

COS1512 Assignment 2 2024 (199828) - DUE 12 July 2024 QUESTIONS AND ANSWERS

Content preview

COS1512 Assignment
2 2024 (199828) -
DUE 12 July 2024
QUESTIONS WITH COMPLETE ANSWERS




[School]
[Course title]

,COS1512 Assignment 2 2024 (199828) - DUE 12 July 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 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. 3

, To solve this problem, we'll create a C++ program that calculates the cost of
sending a parcel to London using either GlobalMail or DHL. The program will use
overloaded functions named calcPostage to handle the calculations for each
service.

Here’s how you can implement the program:

1. Define constants for the cost per kg for each service.

2. Implement the calcPostage function for GlobalMail, which takes the weight
and zone as parameters.

3. Implement the calcPostage function for DHL, which takes the actual weight,
length, width, and height as parameters.

4. Implement the main function to get user input, validate the input, and call
the appropriate calcPostage function.

Here is the complete C++ program:

cpp

Copy code

#include <iostream>

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 int ZONE_MIN = 1;

Document information

Uploaded on
June 27, 2024
Number of pages
22
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers
R49,34

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
msmartie11
3,9
(30)
Sold
246
Followers
224
Items
1232
Last sold
10 months ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions