Question

Hello I have a question. I would like to check if the code follows this requirement....

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 Rectangle::setWidth(double w)

{

width = w;

}

//**************************************************

// setLength assigns a value to the length member. *

//**************************************************

void Rectangle::setLength(double len)

{

length = len;

}

//**************************************************

// getWidth returns the value in the width member. *

//**************************************************

double Rectangle::getWidth() const

{

return width;

}

//****************************************************

// getLength returns the value in the length member. *

//****************************************************

double Rectangle::getLength() const

{

return length;

}

//*****************************************************

// getArea returns the product of width times length. *

//*****************************************************

double Rectangle::getArea() const

{

return width * length;

}

rectangle.cpp


#include<iostream>
#include "rectangle.h"
using namespace std;
int main()

{
Rectangle *rec=new Rectangle();

double width,length;
cout<<"This program will calculate the area of a \nreactangle.";
cout << " What is the width? ";

cin >> width; // Get the width

cout << "What is the length? ";

cin >> length; // Get the length

rec->setLength(length);
rec->setWidth(width);

cout << "here is rectangle's data\n";
cout<<"width "<<rec->getWidth()<<endl;
cout<<"length "<<rec->getLength()<<endl;
cout<<"Area "<<rec->getArea()<<endl;

return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hello,

This follows the following requirement 1 defined in file Rectangle.h file. You should have given this file name as same as the class name "Rectangle" and traditionally we follow this approach. But you here you have given it as "rectangle.h" instead of "Rectangle.h"

Requirement 1:

A complete Rectangle Class including both declaration and definition

Answer: You can change the name of the file from "rectangle.h" to "Rectangle.h", to match with the class name.

Requirement 2: Implementation needs to be in different file and here you are using "rectangle.cpp" file which is correct.

Add a comment
Know the answer?
Add Answer to:
Hello I have a question. I would like to check if the code follows this requirement....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The clas...

    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...

  • I need help with the C++ for the following problem: Write a program uses objected oriented...

    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(),...

  • 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...

  • Use C++ 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...

  • Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks...

    Consider the Rectangle2 java class definition below. Write the definition of an equals) method that checks if two Rectangle objects have the same dimensions Write a Java program to test the equals method public class Rectangle2 K private int width, length; public Rectangle2(int w, int 1) { setWidth(w); setLength(1); System.out.println("Inside parameterized!!!"); } public void setWidth(int w) { width = w;} public void setLength(int i) { length = 1;} int getWidth() { return width; } int getLength() { return length; }...

  • Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override...

    Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle {       private double length;    private double width;       public Rectangle(double l, double w)    {        length = l;        width = w;    }       public double getLength()    {   ...

  • In the code (C++) below, if you input 2 as length and 4 as width, the...

    In the code (C++) below, if you input 2 as length and 4 as width, the output is: Enter the rectangle's length: 2 Enter the rectangle's width: 4 Length: 2 | Width: 4 | Area: 8 | Perimeter:12 We worked on this code during class, but there were some things that I did not understand. 1) how does compiler read"l" as length, "w" as width, etc.? I thought you had to update it first, like "w=width." 2) i thought you...

  • Why are obj1 and obj2 printing the same areas? I'm trying to learn about Comparable interface....

    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...

  • Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then...

    Creating a Class in C++ Summary In this lab, you create a programmer-defined class and then use it in a C++ program. The program should create two Rectangle objects and find their area and perimeter. Instructions Ensure the class file named Rectangle.cpp is open in your editor. In the Rectangle class, create two private attributes named length and width. Bothlength and width should be data type double. Write public set methods to set the values for lengthand width. Write public...

  • Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The...

    Programming Language: Java Write a class named ColoredRectangle that extends the Rectangle class (given below). The ColoredRectangle class will have an additional private String field named Color. The ColoredRectangle class should have four constructors: a no-arg constructor; a three-arg constructor; a two-arg constructor that accepts a Rectangle object and a color; and a copy constructor. The ColoredRectangle class should have an Equals and toString methods. The ColoredRectangle class should have mutators and accessors for all three fields. public class Rectangle...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT