Use DevC++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions:
Attributes:
width and length
Member functions:
setWidth(), setLength(), getWidth() , getLength(), getArea()
Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the length, width, and area. The program should
1. Ask the user for the length and width of rectangle. (5 points)
2. Output the length, width, and area of a rectangle. (10 points)
3. Continue to ask the user to calculate another rectangle area by asking length and width. (10 points)
Prelude to Programming (6th Edition)
Answer: Hey dear student find the solution of your query if you have any doubt feel free to ask. Thanks!!
this C++ program has a Rectangle class and its member variables, member functions. Member functions are used to set width or length of the rectangle and return both. One member functions to get area of the rectangle.
in main asks for length and width from the user , passing parameters into member functions. Print all information on the screen.
#include<iostream>
using namespace std;
class Rectangle//class Rectangle
{
double width;//member variables
double length;
public://member functions
void setWidth(double w)//to set width
{
width = w;
}
void setLength(double l)//to set length
{
length = l;
}
double getWidth()//get length
{
return width;
}
double getLength()//get width
{
return length;
}
double getArea()//get area
{
return length*width;
}
};
int main()
{
double l,w,area;//variable declarations
int ans = 1;
Rectangle r1;//create object of the class
while (ans!=0)
{
cout<<"Enter the length of a Rectangle: ";
cin>>l; //ask for length
cout<<"Enter the width of a Rectangle: ";
cin>>w;//ask for width
r1.setLength(l);//call member functions of the class
r1.setWidth(w);
l = r1.getLength();
w = r1.getWidth();
area = r1.getArea();
cout<<endl;
cout<<"Length: "<<l;//print all information of the
rectangle
cout<<"\nWidth: "<<w;
cout<<"\nArea: "<<area;
cout<<"\nDo you want to calculate area of another rectangle
press any number or press 0 to exit:";
cin>>ans;//again ask from user to execute program
}
return 0;
}

Use DevC++ to implement a program uses objected oriented programming to calculate the area of a...
Use C++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...
I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...
Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...
Construct a C++ class named Rectangle that has floating-point data members named length and width. The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...
Write a program to display the area of a rectangle after accepting its length and width from the user by means of the following functions: getLength – ask user to enter the length and return it as double getWidth – ask user to enter the width and return it as double getArea – pass width and length, compute area and return area displayArea – pass area and display it in this function. Expected Output: (i) Enter the length: 29 Enter...
Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...
share your program enhance your work after submitting export to repl Due: Oct 12, 2020 05:00 pm submit : back to classroom run Instructions from your teacher: #include <iostream> Complete this program. using namespace std; When the program is complete it should ask the user to enter a rectangle's length and width, then display the rectangle's area. The program calls the following functions which need to be completed: double getLength() { // Add code here } double getWidth() { //...
Why are obj1 and obj2 printing the same areas? I'm trying to learn about Comparable interface. Couldn't figure it out. the compare to method should print 0, 1, or -1 import java.util.*; public class RectangleMain { public static void main(String [] args) throws CloneNotSupportedException { /*ComparableRectangleAlsoCloneable obj1 = new ComparableRectangleAlsoCloneable(4, 5); ComparableRectangleAlsoCloneable obj2 = (ComparableRectangleAlsoCloneable)obj1.clone(); System.out.println(obj1.toString()); System.out.println(obj1 == obj2); //false System.out.println(obj2.toString());*/ Scanner...
// This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int main() { Rectangle rectangle1; Rectangle rectangle2; rectangle1.setLength(10.0); rectangle1.setWidth(5.0); rectangle2.setLength(7.0); rectangle2.setWidth(3.0); cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl; cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl; cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl; cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...