You have been tasked with designing a computer program solution that is expected to determine the placements of metals beams, which will used as part of a supporting barrier along newly constructed highways. Highways are expected to be 55 feet or more in length.
Required: Using the 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 highway's support barrier. Your solution must used a user-defined function to display the positioning of each beam. All metal beams will be k feet apart, such that 5 < k < 15. Your user-defined 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.
#include <iostream>
using namespace std;
int NumberOfBeams(double length, double distance);
void Display(int beams);
int main()
{
double length;
cout << "Enter length of highway(55+ feet): ";
cin >> length;
if (length < 55)
{
cout << "Wrong length!" << endl;
return 0;
}
cout << "Enter distance between beams (5 - 15): ";
double distance;
cin >> distance;
if (distance < 5 || distance > 15)
{
cout << "Wrong distance" << endl;
return 0;
}
cout << "Total number of beams is: " << NumberOfBeams(length, distance) << endl;
Display(NumberOfBeams(length, distance));
system("pause");
return 0;
}
int NumberOfBeams(double length, double distance)
{
return (int)(length / distance) + 1;
}
void Display(int beams)
{
cout << "*****Beams placement*****" << endl;
for (int i = 0; i < beams; i++)
{
if (i == beams - 1)
{
cout << "|" << endl;
break;
}
cout << "| ";
}
}