assignment 6 - #include <iostream> using namespace std...

This preview shows page 1 - 3 out of 9 pages.

#include <iostream>using namespace std;double length; // To hold the rectangle's lengthdouble width;// To hold the rectangle's widthdouble area;// implementation example:double getLength() {double length;cout << "Enter the length: ";cin >> length;return length;}double getWidth() {cout << "Enter the width: ";cin >> width;return width;}double getArea() {area = length * width;}int displayData() {cout << "\nRectangle Data"<< "\n--------------"<< "\nLength: " << length<< "\nWidth: " << width<< "\nArea: " << area;}// You are to follow the getLength() example, and to implement 3 more functions: // getWidth(), getArea(), displayData()// then replace the original code main program with the functions!int main(){// Get the rectangle's length // cout << "Enter the length: ";// cin >> length;length = getLength();// Get the rectangle's width
// Define/refer an external function as getWidth width = getWidth();// Get the rectangle's area// Define/refer an external function as getArea area = getArea();// Display the rectangle's data// Define/refer an external function as displayDatadisplayData();return 0;}//Alagu version 6a comment simplification#include <iostream>using namespace std;double length; // To hold the rectangle's lengthdouble width;// To hold the rectangle's widthdouble area;double getLength() {double length;cout << "Enter the length: ";cin >> length;return length;}double getWidth() {cout << "Enter the width: ";cin >> width;return width;}double getArea() {area = length * width;}int displayData() {cout << "\nRectangle Data"<< "\n--------------"<< "\nLength: " << length<< "\nWidth: " << width<< "\nArea: " << area;}

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture