100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

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

Beoordeling
-
Verkocht
-
Pagina's
19
Cijfer
A+
Geüpload op
27-06-2024
Geschreven in
2023/2024

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

Instelling
Vak










Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
27 juni 2024
Aantal pagina's
19
Geschreven in
2023/2024
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

Voorbeeld van de inhoud

COS1512
ASSIGNMENT 2 2024
(199828) - DUE 12
JULY 2024
QUESTIONS WITH COMPLETE ANSWERS




[DATE]
[COMPANY NAME]
[Company address]

,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;

const int ZONE_MAX = 6;

const double VOLUMETRIC_DIVISOR = 5000.0;



// Function to calculate postage for GlobalMail

double calcPostage(double weight, int zone) {

if (zone >= ZONE_MIN && zone <= 3) {

return weight * GLOBALMAIL_COST_ZONE_1_TO_3;

} else if (zone >= 4 && zone <= ZONE_MAX) {

return weight * GLOBALMAIL_COST_ZONE_4_TO_6;

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
QuizDoc Chamberlain College Of Nursng
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
226
Lid sinds
2 jaar
Aantal volgers
193
Documenten
1051
Laatst verkocht
2 maanden geleden

3,7

31 beoordelingen

5
13
4
4
3
10
2
0
1
4

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen