Answer to Question #165211 in C++ for Kefilwe Mamabolo

Question #165211

Just post is a new courier service company which services all provinces in the South Africa. They charge 

their customers based on the weight of the parcel as indicated in the table below. However, if kilograms 

are above 50, the cost is charged according to the number of hours it took to deliver. Although the time 

is entered in minutes but they are charged R95.00 per hour. Clients may also add some extras to the 

delivery such as insurance which is charged 8.5% and priority is charged at 5% of the charge.


Distance Weight Cost (R)

Local Under 5 kg R125.00

Local 5 kg up to 20 kg R175.00

Local Over 20 Kg R250.00

Long Under 5 kg R390.00

Long 5 kg up to 20 kg R450.00

Write a program that will assist with calculating the postage amount.

2.1 Create a C++ source file called Postage and save it in a file called Postage.cpp. 

2.2 Create the following functions: 

 



1
Expert's answer
2021-02-21T19:51:24-0500
#include <iostream>
using namespace std;
void enterPostageDetails(int minutes, int weight, string distance, char insurance, char priority) {
    cout << "Enter the number of minutes it took to deliver: ";
    cin >> minutes;
    cout << "Enter the weight of the product: ";
    cin >> weight;
    cout << "Enter the distance(Local, Long): ";
    cin >> distance;
    cout << "Enter the status of insurance (Y/y Or N/n): ";
    cin >> insurance;
    cout << "Enter the status of priority (Y/y Or N/n): ";
    cin >> priority;
}
float convertTime (int minutes) {
    float Hours;
    Hours = (float) minutes / 60;
    return Hours;
}
float determineCost(string distance, int weight, float timeHours) {
    float costProduct;
    if (weight <= 50) {
        if (weight <= 5) {
            if (distance == "Local") {
                costProduct = 125.00;
            }
            if (distance == "Long") {
                costProduct = 390.00;
            }
        }
        if (weight > 5 && weight <= 20) {
            if (distance == "Local") {
                costProduct = 175.00;
            }
            if (distance == "Long") {
                costProduct = 450.00;
            }
        }
        if (weight > 20) {
            if (distance == "Local") {
                costProduct = 250.00;
            }
            if (distance == "Long") {
                costProduct = 500.00;
            }
        }
    }
    else {
        costProduct = 95 * timeHours;
    }
    return costProduct;
}
void calcAmtDue (float costProduct, char insurance, char priority) {
    float insuranceCost, priorityCost;
    if (tolower(insurance) == 'y') {
        insuranceCost = costProduct * 0.085;
        cout << "the amount of insurance: " << insuranceCost;
    }
    if (tolower(insurance) == 'n') {
        cout << "no insurance";
    }
    if (tolower(priority) == 'y') {
        priorityCost = costProduct * 0.05;
        cout << "the amount of priority: " << priorityCost;
    }
    if (tolower(priority) == 'n') {
        cout << "no insurance";
    }
    costProduct += insuranceCost + priorityCost;
    cout << "total product cost: " << costProduct;
}
int main () {
    int minutes, weight;
    string distance;
    char insurance, priority;
    enterPostageDetails(minutes, weight, distance, insurance, priority);
    float timeHours;
    timeHours = convertTime(minutes);
    float costProduct;
    costProduct = determineCost(distance, weight, timeHours);
    calcAmtDue(costProduct, insurance, priority);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog