100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada
logo-home
COS1512 Assignment 2 memo 2024 $5.96   Añadir al carrito

Otro

COS1512 Assignment 2 memo 2024

 157 vistas  9 veces vendidas
  • Grado
  • Institución

COS1512 Assignment 2 memo 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...

[Mostrar más]

Vista previa 3 fuera de 10  páginas

  • 1 de julio de 2024
  • 10
  • 2023/2024
  • Otro
  • Desconocido
avatar-seller
COS1512 2024 Assignment 2 memo

Crystal Indigo!
Crystal Indigo!
Providing all solutions you need anytime
+27 76 626 8187




All the code and pictures, ready to submit

,Question 1 A program that will calculate the price to be
paid for sending a parcel to London.
Output
When you enter ‘d’ for DHL




When you enter ‘g’ for GLOBALMAIL and zone 1-3




When you enter ‘g’ for GLOBALMAIL and zone 4-6

, Source code:
#include <iostream>
using namespace std;

const double GLOBALMAIL_ZONE_1_TO_3 = 108.0;
const double GLOBALMAIL_ZONE_4_TO_6 = 130.0;
const double DHL_RATE = 70.0;
const double VOLUMETRIC_WEIGHT_DIVISOR = 5000.0;


double calcPostage(double weight, int zone) {
if (zone >= 1 && zone <= 3) {
return weight * GLOBALMAIL_ZONE_1_TO_3;
} else if (zone >= 4 && zone <= 6) {
return weight * GLOBALMAIL_ZONE_4_TO_6;
} else {
cout << "Invalid zone. Please enter a value between 1 and 6." << endl;
return 0.0;
}
}


double calcPostage(double weight, double length, double width, double height) {
double volumetricWeight = (length * width * height) /
VOLUMETRIC_WEIGHT_DIVISOR;
double highestWeight = (weight > volumetricWeight)? weight :
volumetricWeight;
return highestWeight * DHL_RATE;
}


int main() {
char choice;
cout << "Do you want to use GlobalMail (g) or DHL (d)?" << endl;
cin >> choice;


if (choice == 'g') {
int zone;
double weight;
cout << "Enter the weight of the parcel (in kg): ";
cin >> weight;
cout << "Enter the zone (1-6): ";
cin >> zone;

if(zone >0 && zone <= 6){
double cost = calcPostage(weight, zone);
cout << "The total cost is R" << cost << endl;
}
}
else if (choice == 'd') {
double weight, length, width, height;

cout << "Enter the weight of the parcel (in kg): ";
cin >> weight;

cout << "Enter the length of the box (in cm): ";
cin >> length;

cout << "Enter the width of the box (in cm): ";
cin >> width;

cout << "Enter the height of the box (in cm): ";

Los beneficios de comprar resúmenes en Stuvia estan en línea:

Garantiza la calidad de los comentarios

Garantiza la calidad de los comentarios

Compradores de Stuvia evaluaron más de 700.000 resúmenes. Así estas seguro que compras los mejores documentos!

Compra fácil y rápido

Compra fácil y rápido

Puedes pagar rápidamente y en una vez con iDeal, tarjeta de crédito o con tu crédito de Stuvia. Sin tener que hacerte miembro.

Enfócate en lo más importante

Enfócate en lo más importante

Tus compañeros escriben los resúmenes. Por eso tienes la seguridad que tienes un resumen actual y confiable. Así llegas a la conclusión rapidamente!

Preguntas frecuentes

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.

100% de satisfacción garantizada: ¿Cómo funciona?

Nuestra garantía de satisfacción le asegura que siempre encontrará un documento de estudio a tu medida. Tu rellenas un formulario y nuestro equipo de atención al cliente se encarga del resto.

Who am I buying this summary from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller CrystalIndigo. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy this summary for $5.96. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

45,681 summaries were sold in the last 30 days

Founded in 2010, the go-to place to buy summaries for 14 years now

Empieza a vender
$5.96  9x  vendido
  • (0)
  Añadir