Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Otro

COS1512 Assignment 2 2024 solution, full working code

Puntuación
-
Vendido
5
Páginas
8
Subido en
02-07-2024
Escrito en
2023/2024

COS1512 Assignment 2 2024 solution, full working code

Institución
Grado

Vista previa del contenido

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;

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
2 de julio de 2024
Número de páginas
8
Escrito en
2023/2024
Tipo
OTRO
Personaje
Desconocido

Temas

$5.62
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
foxNotes Acsess Business Academy
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
113
Miembro desde
3 año
Número de seguidores
63
Documentos
36
Última venta
3 semanas hace
saveNotes

5.0

5 reseñas

5
5
4
0
3
0
2
0
1
0

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes