188k views
4 votes
Write a program that takes the length and width of a rectangular yard and the length and width of a rectangular house situated in the yard. Your program should compute the time required to cut the grass at the rate of two square feet a second.

User Mbmcavoy
by
6.1k points

1 Answer

5 votes

Answer:

// here is code in c++.

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

int y_len,y_wid;

int h_len,h_wid;

// read the length and width of yard

cout<<"Enter the legth of yard:";

cin>>y_len;

cout<<"Enter the width of yard:";

cin>>y_wid;

// read the length and width of house

cout<<"Enter the legth of house:";

cin>>h_len;

cout<<"Enter the width of house:";

cin>>h_wid;

// calculate grass area

int g_area=(y_len*y_wid)-(h_len*h_wid);

// find the time

int t=g_area/2;

// print the time

cout<<"time required to cut the grass is: "<<t<<" seconds."<<endl;

return 0;

}

Step-by-step explanation:

Read the length and width of the yard. Then read the length and width of house from user.Calculate the area of grass by subtracting the area of house from area of yard.Then divide the area of grass by rate of 2 square feet per second.

Output:

Enter the legth of yard:25

Enter the width of yard:20

Enter the legth of house:15

Enter the width of house:12

time required to cut the grass is: 160 seconds.

User ElPiter
by
6.2k points