You have been given a flat cardboard of area, say, 70 square inches to make an o
ID: 3766707 • Letter: Y
Question
You have been given a flat cardboard of area, say, 70
square inches to make an open box by cutting a square from each corner and folding the sides (see Figure 7-20). Your objective is to determine the dimensions,
that is, the length and width, and the side of the square to be cut fromthe
corners so that the resulting box is of maximum length.
Write a program that prompts the user to enter the area of the flat cardboard.
The program then outputs the length and width of the cardboard and the
length of the side of the square to be cut from the corner so that the resulting
box is of maximum volume. Calculate your answer to three decimal places.
Your program must contain a function that takes as input the length and width
of the cardboard and returns the side of the square that should be cut to
maximize the volume. The function also returns the maximum volume.
Can you please do this program in java language and not c, thanks!
Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double min(double,double);
void max(double,double,double&,double&);
int main()
{double area,length,width=.001,vol,height,mLen,mWidth,mHeight,mVol=-1;
cout<<setprecision(3)<<fixed<<showpoint;
cout<<"Enter the area of the flat cardboard: ";
cin>>area;
while(width<=area)
{length=area/width;
max(length,width,vol,height);
if(vol>mVol)
{mLen=length;
mWidth=width;
mHeight=height;
mVol=vol;
}
width+=.001;
}
cout<<"dimensions of card to maximize the cardboard box which has a volume "
<<mVol<<endl;
cout<<"Length: "<<mLen<<" Width: "<<mLen<<endl;
cout<<"dimensions of the cardboard box ";
cout<<"Length: "<<mLen-2*mHeight<<" Width: "
<<mWidth-2*mHeight<<" Height: "<<mHeight<<endl;
system("pause");
return 0;
}
void max(double l,double w,double& max, double& mside)
{double vol,ss;
mside=min(l,w);
ss=.001;
max=-1;
while(mside>ss*2)
{vol=(l-ss*2)*(w-ss*2)*ss;
if(vol>max)
{max=vol;
mside=ss;
}
ss+=.001;
}
}
double min(double l,double w)
{if(l<w)
return l;
return w;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.