Answer to Question #254597 in C++ for dawdaw

Question #254597
A rectangle is 4 times as long as it is wide. If the length is increased by 4 inches and the width is decreased by 1 inch, the area will be X_AREA square inches. If X_AREA is entered by the user, create a program that will determine what were the dimensions (length and width) of the original rectangle?
1
Expert's answer
2021-10-21T16:06:42-0400
#include <iostream>
#include <math.h>
using namespace std;
int main(){
    float r_len, r_wid, X_AREA;
    cout<<"Enter X_AREA: ";
    cin>>X_AREA;


    //(r_len + 4) * (r_wid - 1) = X_AREA
    //r_len = 4r_wid
    //(4r_wid + 4) * (r_wid - 1) = X_AREA
    //(4r_wid^2 + 4r_wid - 4r_wid -4) = X_AREA
    //4r_wid^2 = X_AREA + 4
    //r_wid^2 = (X_AREA + 4)/4
    //r_wid = sqrt((X_AREA + 4)/4)
    //r_len = 4r_wid
    r_wid = sqrt((X_AREA + 4)/ 4);
    r_len = 4 * r_wid;
    cout<<"length: "<<r_len<<endl;
    cout<<"width: "<<r_wid<<endl;


    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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS