Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do so in C++ A pipe is to be carried around the right-angled corner of tw

ID: 3879658 • Letter: P

Question

Please do so in C++

A pipe is to be carried around the right-angled corner of two intersecting corridors. Suppose that the widths of the intersecting hallways are measured in feet. In the example shown below, the widths happen to be 8 feet and 5 feet, respectively. Your objective is to find the length of the longest pipe, floored to the nearest foot, that can be carried level around the right-angled corridor. Specifications: Write a program that prompts the user to input the widths of both hallways. The vertical hallway is considered to be the first hallway, and the horizontal hallway the second hallway. The program should determine critical angle that constrains the length of the pipe that can be carried around the corner, and print the result in degrees using two values after the decimal point. The length of the pipe should be floored to the nearest foot and printed as well. FIGURE 7-22 Pipe problem The length of the longest pipe should be calculated using a function with the following function prototype /7 Calculates the length of longest pipe void longestPipe (double wHallwayl, double wHallway2, double &mTheta;, double &mLength;) The function returns the maximum theta and length values. Assume 0

Explanation / Answer

#include <iostream>

#include <cmath>

#include <iomanip>

using namespace std;

#define PI 3.14159265

double roundOffToTwoDecimal(double var)

{

double value = (int)(var * 100 + .5);

return (double)value / 100;

}

void longestPipe(double wHallway1, double wHallway2, double &mTheta, double &mLength) {

// max theta calculated by this formula a/b = tan^3(theta)

double a = pow(wHallway1, 1.0/3.0);

a = roundOffToTwoDecimal(a);

double b = pow(wHallway2, 1.0/3.0);

b = roundOffToTwoDecimal(b);

double theta = atan2 (a,b);

mTheta = roundOffToTwoDecimal(theta * 180 / PI);

double length = wHallway1 / sin(theta) + wHallway2 / cos(theta);

mLength = roundOffToTwoDecimal(length);

}

int main() {

double wHallway1, wHallway2, mTheta, mLength;

cout<<"Enter the length of the first hallway: "<< endl;

cin>>wHallway1;

cout<<"Enter the length of the second hallway: "<< endl;

cin>>wHallway2;

longestPipe( wHallway1,wHallway2, mTheta, mLength);

cout<< "The length constraint occurs at Theta: " << mTheta << " deg." << endl;

cout<< "Length of longest pipe is: " << mLength << " ft."<< endl;

return 0;

}