51 Write a program that uses a class rectangle in a separate

5-1.   Write a program that uses a class rectangle in a separate header file.

The class has data members for length, width, area, and perimeter. The length and width can be set by the user, but the area and perimeter can not be set by the user (their values depend on the values of length and width). Include 2 other member functions that separately calculates the perimeter and area of the rectangle. Let the user be able to separately get the value of all 4 data fields. Include a constructor, that does not take any arguments, but initializes all the data fields, the length and width to 1, and the area and perimeter calculated as in the two calculate functions.

The main program file will declare a rectangle object, call the member functions to calculate the perimeter and area, and then get and print out the results.

Use the following ex5-1.cpp and create the corresponding rectangle5-1.h header file.

/*
Exercise 5-1
This program will create a rectangle object
*/
#include<iostream>
#include\"rectangle5-1.h\"
using namespace std;

void main()
{
    rectangle51 r; // write constructor
    float len, wid;
    cout << \"Enter length: \";
    cin >> len;
    r.setlength(len); // write functions
    cout << \"Enter width: \";
    cin >> wid;
    r.setwidth(wid);
    r.calcarea();
    r.calcperimeter();
    cout << \"Rectangle\'s length = \" << r.getlength() << endl;
    cout << \"Rectangle\'s width = \" << r.getwidth() << endl;
    cout << \"Rectangle\'s area = \" << r.getarea() << endl;
    cout << \"Rectangle\'s perimeter = \" << r.getperimeter() << endl;
}

Solution

R is an implementation of the S programming language combined with lexical scoping semantics inspired by Scheme.[11] S was created by John Chambers while at Bell Labs. There are some important differences, but much of the code written for S runs unaltered.[12]

R was created by Ross Ihaka and Robert Gentleman[13] at the University of Auckland, New Zealand, and is currently developed by the R Development Core Team, of which Chambers is a member. R is named partly after the first names of the first two R authors and partly as a play on the name of S.[14] The project was conceived in 1992, with an initial version released in 1995 and a stable beta version in 2000

5-1. Write a program that uses a class rectangle in a separate header file. The class has data members for length, width, area, and perimeter. The length and wi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site