Question

Construct a class named Room that declares two double-precision data members named length and width (2...

Construct a class named Room that declares two double-precision data members named length and width (2 points). Include a constructor that initializes each data member to 1.0 when a Room object is created (1 point). Add two accessor functions for displaying the length and width values of a Room object and two mutator functions that allow changing these data member values. (2 points)

Write a program that tests all functionality of this class. (3 points)

Extra Credit: Create this class in a separate set of files (i.e. Room.cpp and Room.h) (1 point)

Provide source code (all files) containing comment with your name, course code and date (1 point). Also provide screenshot of a sample run (1 point).

Submit source code and screenshot together in a zip file.

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

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

Room.h

#ifndef ROOM_H
#define ROOM_H

class Room
{
public:
  
Room();
Room (double l,double w);

double getLength();
double getWidth();
void setLength(double l);
void setWidth(double w);


private:
// Declaring variables
double length;
double width;

};
#endif

_________________

Room.cpp

#include <iostream>
using namespace std;
#include "Room.h"

Room::Room()
{
this->length=0;
this->width=0;
}
Room::Room (double l,double w)
{
length=l;
width=w;
}

double Room::getLength()
{
return length;
}
double Room::getWidth()
{
return width;
}
void Room::setLength(double l)
{
length=l;
}
void Room::setWidth(double w)
{
width=w;
}

_____________________

main.cpp

#include <iostream>
using namespace std;
#include "Room.h"

int main()
{
//Declarin variables
double length;
double width;
  
//Getting the input entered by the user
cout<<"Enter Room Length :";
cin>>length;
cout<<"Enter Room Width :";
cin>>width;
  
//Creating an instance of Room class
Room r;
  
//calling the setters
r.setLength(length);
r.setWidth(width);
  
//Displaying the room dimensions
cout<<"__ Displaying Room Dimensions __"<<endl;
cout<<"Length :"<<r.getLength()<<endl;
cout<<"Width :"<<r.getWidth()<<endl;

return 0;
}

_____________________

Output:

/RoomClass Enter Room Length :4.5 Enter Room Width :5.5 -Displaying Room Dimensions- Length :4.5 Width 5.5 Press any key to continue

________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Construct a class named Room that declares two double-precision data members named length and width (2...
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
  • a. construct a class named room that declares two-double precision data members named length and width....

    a. construct a class named room that declares two-double precision data members named length and width. include a constructor that initializes each datavmember to 1.0 when a room object is created. add two accessor funtions for displaying the length and width values of a room object and two mutator functions that allow changing these data member values. b. include the class written for 6a in the context of a complete program

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

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

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double...

    Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...

  • *using c++* Construct a class named Savings containing three floating-point data members named balance, rate, and...

    *using c++* Construct a class named Savings containing three floating-point data members named balance, rate, and interest and a constructor that initializes each data member to 0. This class should be established with typical two files(.h and .cpp). Include a member function that inputs a balance and rate and then calculates an interest. The rate should be stored as a   percent, such   as   6.5   for   6.5%,   and   the   interest   is   computed   as   interest   = (balance)(rate/100). Add a member function to...

  • Construct a class named Fractions containing two integer data members named num and denom, used to...

    Construct a class named Fractions containing two integer data members named num and denom, used to store the numerator and denominator of a fraction having the form num/denom. Your class should include a default constructor that initializes num and denom to 1 if there's no user initialization, and it must prohibit a 0 denominator value. In addition, create member functions for displaying an object's data values and overloaded operator functions for adding, subtracting, multiplying, and dividing two Fraction objects, as...

  • (Classes and Objects) Design a class named Box. The class should have the following private members:...

    (Classes and Objects) Design a class named Box. The class should have the following private members: width - A double member variablethat holds the width of the box. length – A double member variable for holding the length of the box. height – A double member variable of type double that holds the height of the box. In addition, provide the following member functions with full (inline) implementation. a) A default constructor that sets all member variables to 0. b)...

  • Question 2) Use Point class to define another class called Rectangle which has only two data memb...

    C++ Question 2) Use Point class to define another class called Rectangle which has only two data members of type Point named UpperLeftPoint and BottomRightPoint a. Define two constructors one is default and one is initializer b. Define member functions named getLength of rectangle c. Define member functions named get Width of rectangle d. Define member functions named getArea of rectangle. Note, the values of the functions are calculated based on the two points of the rectangle e. Define member...

  • Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and...

    Please help with this assignment. Thanks. 1. Write a C++ program containing a class Invoice and a driver program called invoiceDriver.cpp. The class Invoice is used in a hardware store to represent an invoice for an item sold at the store. An invoice class should include the following: A part number of type string A part description of type string A quantity of the item being purchased of type int A price per item of type int A class constructor...

  • Design a class for python named PersonData with the following member variables: lastName firstName address city...

    Design a class for python named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be...

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
ADVERTISEMENT