Question

In: Computer Science

Use DevC++ to implement a program uses objected oriented programming to calculate the area of a...

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.

2. Output the length, width, and area of a rectangle.

3. Continue to ask the user to calculate another rectangle area by asking length and width.

C++ ONLY

Solutions

Expert Solution

#include<iostream>
using namespace std;
//rectangle class
class rectangle
{
    private: //attributes of the rectangle
        double width;
        double length;
    public:   
      void setWidth(double)   ;//method to set the width
      void setLength(double); //method to set the length
      double getLength(); //method to get the length
      double getWidth();//method to get the width
      double getArea();//method to return the area
};
//definations of the methods()
void rectangle :: setLength(double l)
{
   length = l;
}
void rectangle :: setWidth(double w)
{
   width=w;
}
double rectangle :: getLength()
{
   return length;
}
double rectangle :: getWidth()
{
   return width;
}
  
double rectangle :: getArea()
{
   return length * width;
}
//driver program
int main()
{
    rectangle robj;//declaration of object
    double a,b,ar;
    char ch;
    //infinite loop
    while(1)
    {
    cout<<endl<<"Enter the length of rectangle"   ;
    cin>>a; //input the length
    cout<<endl<<"Enter the width of rectangle";
    cin>>b; //input the width
    //validate the length
    while(a<=0)
    {
       cout<<endl<<"Invalid length";
       cout<<endl<<"Enter the length of rectangle"   ;
    cin>>a;
           }
           //validate the width
           while(b<=0)
    {
       cout<<endl<<"Invalid Width";
       cout<<endl<<"Enter the Width of rectangle"   ;
    cin>>b;
           }
    //set the length
    robj.setLength(a);
    //set the width
    robj.setWidth(b);
    //display the details
    cout<<endl<<"Length of the Rectangle : "<<robj.getLength()<<" units.";
    cout<<endl<<"Width of the Rectangle : "<<robj.getWidth()<<" units.";
    cout<<endl<<"Area of the Rectangle : "<<robj.getArea()<<" Sq. units.";
    //ask for choice
    cout<<endl<<"Do you want to find more area[y/n]";
    cin>>ch;
    if(ch=='y' || ch=='Y')
    continue;
           else
           break;
   }
}
  

output


Related Solutions

Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class...
Kindly Do the program in C++ language Object Oriented Programming. Objectives  Implement a simple class with public and private members and multiple constructors.  Gain a better understanding of the building and using of classes and objects.  Practice problem solving using OOP. Overview You will implement a date and day of week calculator for the SELECTED calendar year. The calculator repeatedly reads in three numbers from the standard input that are interpreted as month, day of month, days...
This week, you will create and implement an object-oriented programming design for your project. You will...
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it. Submit a screen shot from Visual Studio with your explanation into a Word...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a...
-What is object-oriented programming? -What is a class? -What is an object? -A contractor uses a blueprint to build a set of identical houses. Are classes analogous to the blueprint or the houses? Explain. -What is a class diagram? How is it used in object-oriented programming? -What is an attribute in OOP? What is a data member? -What is a method in OOP? What is a member function? -What is the difference between private members and public members of a...
Write a program to calculate the area and circumference of a cuboid. Use printf to display...
Write a program to calculate the area and circumference of a cuboid. Use printf to display 2 digits after decimal point in all the results Program should be in java language.
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for...
Use Java programming to implement the following: Implement the following methods in the UnorderedList class for managing a singly linked list that cannot contain duplicates. Default constructor Create an empty list i.e., head is null. boolean insert(int data) Insert the given data into the end of the list. If the insertion is successful, the function returns true; otherwise, returns false. boolean delete(int data) Delete the node that contains the given data from the list. If the deletion is successful, the...
Why is it more feasible to use Objects and object oriented programming as compared to using...
Why is it more feasible to use Objects and object oriented programming as compared to using method based programs? What are the disadvantages of using only methods in your programs.
This program should be done in python. This must use the principles of object oriented program....
This program should be done in python. This must use the principles of object oriented program. Create one or more classes to play Four-in-a-Row (also called Connect Four) with a user. It’s similar to tic-tac-toe but the board is of size 7×6 and discs fall straight through so the legal moves are more stringent than tic-tac-toe. The state of the board should be printed to the terminal after each legal move. You can represent the different colored discs as X’s...
This program focuses on programming with Java Collections classes. You will implement a module that finds...
This program focuses on programming with Java Collections classes. You will implement a module that finds a simplified Levenshtein distance between two words represented by strings. Your program will need support files LevenDistanceFinder.Java, dictionary.txt, while you will be implementing your code in the LevenDistanceFinder.java file. INSTRUCTIONS The Levenshtein distance, named for it's creator Vladimir Levenshtein, is a measure of the distance between two words. The edit distance between two strings is the minimum number of operations that are needed to...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files...
In this programming assignment, you will implement a SimpleWebGet program for non- interactive download of files from the Internet. This program is very similar to wget utility in Unix/Linux environment.The synopsis of SimpleWebGet is: java SimpleWebGet URL. The URL could be either a valid link on the Internet, e.g., www.asu.edu/index.html, or gaia.cs.umass.edu/wireshark-labs/alice.txt or an invalid link, e.g., www.asu.edu/inde.html. ww.asu.edu/inde.html. The output of SimpleWebGet for valid links should be the same as wget utility in Linux, except the progress line highlighted...
11. Write a user oriented MATLAB program that will calculate the capacitance of the capacitor connected...
11. Write a user oriented MATLAB program that will calculate the capacitance of the capacitor connected across the loads to improve the overall power factor to 0.8 lagging,0.9 lagging, unity power factor, 0.8 leading, 0.9 leading. Also MATLAB will calculate total reactive, real power, and the total current at the source for each ste
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT