Programming Laboratory Assignments 01B
Instructions:
1. Write a C++ program that that computes the area of a rectangle, which is width * height.
2. Run the program and correct any errors that occur.
3. Test the program with different inputs.
Guide On Rating System
Vote
Here's a possible implementation of the program:
```c++
#include <iostream>
using namespace std;
int main() {
double width, height, area;
// Step 1: Read the inputs from the user
cout << "Enter the width of the rectangle: ";
cin >> width;
cout << "Enter the height of the rectangle: ";
cin >> height;
// Step 2: Calculate the area of the rectangle
area = width * height;
// Step 3: Display the result
cout << "The area of the rectangle is: " << area << endl;
return 0;
}
```
To compile and run the program, you can use a C++ compiler like g++:
```
g++ -o rectangle rectangle.cpp
./rectangle
```
Once the program is running, you can test it with different inputs by entering the width and height values when prompted. The program will then calculate and display the area of the rectangle.