Question #196344

You have been tasked with designing a computer program solution that is expected to determine the placements of metal beams, which will be used as part of a supporting barrier along newly constructed highways are expected to be 55 feet or more in length write a c++ programming language, implement a computer program solution that will accept the length of a highway and the distance between beams and then determine and output the amount of beams that will be required for creating the highways support barrier. Your solution must use a user defined function to display the positioning of each beam. All the metal beams will be K feet apart, such that 5 _<, K _<15. Your user-defined function function will return the total amount of beams that are required to the function that called it. Your computer program must output the total amount of beams before it terminates


Expert's answer

#include <iostream>
#include <cmath>

using namespace std;

int count_beams(int len, int k)
{
    int n = ceil((double)len / k);
    cout << "beams posistion: ";
    for (int i = 0; i <= len; i += k) {
        cout << i << " ";
    }
    if (len % k) {
        cout << len << "\n";
    } else {
        cout << "\n";
    }
    return n + 1;
}

int main() 
{
    int len, k;
    
    cout << "highway length: ";
    cin >> len;
    if (len < 55) {
        cout << "highway length cannot be less than 55!";
        return 0;
    }
    cout << "distance between beams: ";
    cin >> k;
    if (5 > k or k > 15) {
        cout << "'k' must lie on [5,15].";
        return 0;
    }
    cout << count_beams(len, k);
    return 0;
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS