100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4,6 TrustPilot
logo-home
Other

COS1512 Assignment 2 2024 solution, full working code

Rating
-
Sold
5
Pages
8
Uploaded on
02-07-2024
Written in
2023/2024

COS1512 Assignment 2 2024 solution, full working code










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 2, 2024
Number of pages
8
Written in
2023/2024
Type
Other
Person
Unknown

Subjects

Content preview

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;

Get to know the seller

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.
foxNotes Acsess Business Academy
View profile
Follow You need to be logged in order to follow users or courses
Sold
112
Member since
2 year
Number of followers
63
Documents
35
Last sold
3 months ago
saveNotes

5,0

5 reviews

5
5
4
0
3
0
2
0
1
0

Recently viewed by you

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

Frequently asked questions