Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Next create a class called RoomDimension which will have its class declaration i

ID: 3549119 • Letter: N

Question

Next create a class called RoomDimension which will have its class declaration in RoomDimension.h and its implementation in RoomDimension.cpp. This class will have two data members which have a data type of FeetInches, one for the length of the room and another for the width of the room. The multiply function in FeedInches will be used to calculate the area of the room. RoomDimension will have a function that returns the area of the room as a FeetInches object.

Next create a class called RoomCarpet class that has a RoomDimension object as an attribute. This class will have its class declaration in RoomCarpet.h and its implementation in RoomCarpet.cpp.  It should also have an attribute for the cost of the carpet per square foot. It will have a member function that returns the total cost of the carpet. For example, a room that is 12 feet long and 10 feet wide has an area of 120 square feet. If the cost per square foot is $8 then the cost to carpet the room will be $960 (120 x 8).

The main for this program will create an instance of RoomCarpet and ask the user for the dimensions of the room and the price per square foot for the carpet. The application should then display the total cost of the carpet. It should allow the user to continue doing more calculations until the user indicates they are done.

I am having an issure with what's in the bold. I've triend everything  but I can't seem to get the cost input to work and it to display the total cost. The multiply function don't work either. This is a lot to read through that is why I'm offering a lot of points. Thanks in advance.

It says enter feet, inches, and cost.. When I do the total cost is 0.

// Specification file for the FeetInches class
#ifndef FEETINCHES_H
#define FEETINCHES_H

#include <iostream>
using namespace std;

class FeetInches; // Forward Declaration

// Function Prototypes for Overloaded Stream Operators
ostream &operator << (ostream &, const FeetInches &);
istream &operator >> (istream &, FeetInches &);

// The FeetInches class holds distances or measurements
// expressed in feet and inches.

class FeetInches
{
private:
   int feet;        // To hold a number of feet
   int inches;      // To hold a number of inches
   void simplify(); // Defined in FeetInches.cpp
public:
   // Constructor
   FeetInches(int f = 0, int i = 0)
      { feet = f;
        inches = i;
        simplify(); }
   
   // Copy constructor
   FeetInches(FeetInches &right)
      { feet = right.feet;
        inches = right.inches; }

   // Mutator functions
   void setFeet(int f)
      { feet = f; }

   void setInches(int i)
      { inches = i;
        simplify(); }
   
   // Multiply function
   FeetInches multiply(FeetInches obj)
      { FeetInches temp;
        temp.feet = feet * obj.feet;
        temp.inches = inches * obj.inches;
        temp.simplify();
        return temp;  }

   // Accessor functions
   int getFeet() const
      { return feet; }

   int getInches() const
      { return inches; }

   // Overloaded operator functions
   FeetInches operator + (const FeetInches &);
   FeetInches operator - (const FeetInches &);
   FeetInches operator ++ ();    // Prefix ++
   FeetInches operator ++ (int); // Postfix ++
   bool operator > (const FeetInches &);
   bool operator < (const FeetInches &);
   bool operator == (const FeetInches &);

   // New operators
   bool operator >= (const FeetInches &);
   bool operator <= (const FeetInches &);
   bool operator != (const FeetInches &);

   // Conversion functions
   operator double();
   operator int();
   
   // Friends
   friend ostream &operator << (ostream &, const FeetInches &);
   friend istream &operator >> (istream &, FeetInches &);
};

#endif

// Implementation file for the FeetInches class
#include <cstdlib>  // Needed for abs()
#include "FeetInches.h"

//************************************************************
// Definition of member function simplify. This function     *
// checks for values in the inches member greater than       *
// twelve or less than zero. If such a value is found,       *
// the numbers in feet and inches are adjusted to conform    *
// to a standard feet & inches expression. For example,      *
// 3 feet 14 inches would be adjusted to 4 feet 2 inches and *
// 5 feet -2 inches would be adjusted to 4 feet 10 inches.   *
//************************************************************

void FeetInches::simplify()
{
   if (inches >= 12)
   {
      feet += (inches / 12);
      inches = inches % 12;
   }
   else if (inches < 0)
   {
      feet -= ((abs(inches) / 12) + 1);
      inches = 12 - (abs(inches) % 12);
   }
}

//**********************************************
// Overloaded binary + operator.               *
//**********************************************

FeetInches FeetInches::operator + (const FeetInches &right)
{
   FeetInches temp;

   temp.inches = inches + right.inches;
   temp.feet = feet + right.feet;
   temp.simplify();
   return temp;
}


//**********************************************
// Overloaded binary - operator.               *
//**********************************************

FeetInches FeetInches::operator - (const FeetInches &right)
{
   FeetInches temp;

   temp.inches = inches - right.inches;
   temp.feet = feet - right.feet;
   temp.simplify();  
   return temp;
}

//*************************************************************
// Overloaded prefix ++ operator. Causes the inches member to *
// be incremented. Returns the incremented object.            *
//*************************************************************

FeetInches FeetInches::operator ++ ()
{
   ++inches;
   simplify();
   return *this;
}

//***************************************************************
// Overloaded postfix ++ operator. Causes the inches member to  *
// be incremented. Returns the value of the object before the   *
// increment.                                                   *
//***************************************************************

FeetInches FeetInches::operator ++ (int)
{
   FeetInches temp(feet, inches);

   inches++;
   simplify();
   return temp;
}

//************************************************************
// Overloaded > operator. Returns true if the current object *
// is set to a value greater than that of right.             *
//************************************************************

bool FeetInches::operator > (const FeetInches &right)
{
   bool status;

   if (feet > right.feet)
      status = true;
   else if (feet == right.feet && inches > right.inches)
      status = true;
   else
      status = false;

   return status;
}

//************************************************************
// Overloaded < operator. Returns true if the current object *
// is set to a value less than that of right.                *
//************************************************************

bool FeetInches::operator < (const FeetInches &right)
{
   bool status;

   if (feet < right.feet)
      status = true;
   else if (feet == right.feet && inches < right.inches)
      status = true;
   else
      status = false;

   return status;
}

//*************************************************************
// Overloaded == operator. Returns true if the current object *
// is set to a value equal to that of right.                  *
//*************************************************************

bool FeetInches::operator == (const FeetInches &right)
{
   bool status;

   if (feet == right.feet && inches == right.inches)
      status = true;
   else
      status = false;

   return status;
}

//********************************************************
// Overloaded << operator. Gives cout the ability to     *
// directly display FeetInches objects.                  *
//********************************************************

ostream &operator<<(ostream &strm, const FeetInches &obj)
{
   strm << obj.feet << " feet, " << obj.inches << " inches";
   return strm;
}

//********************************************************
// Overloaded >> operator. Gives cin the ability to      *
// store user input directly into FeetInches objects.    *
//********************************************************

istream &operator >> (istream &strm, FeetInches &obj)
{
   // Prompt the user for the feet.
   cout << "Feet: ";
   strm >> obj.feet;

   // Prompt the user for the inches.
   cout << "Inches: ";
   strm >> obj.inches;

   // Normalize the values.
   obj.simplify();

   return strm;
}

//*************************************************************
// Conversion function to convert a FeetInches object         *
// to a double.                                               *
//*************************************************************

FeetInches::operator double()
{
   double temp = feet;

   temp += (inches / 12.0);
   return temp;
}

//*************************************************************
// Conversion function to convert a FeetInches object         *
// to an int.                                                 *
//*************************************************************

FeetInches:: operator int()
{
   return feet;
}

// New operators

//******************************************************
// Overloaded >= operator. Returns true if the current *
// object is set to a value greater than or equal to   *
// that of right.                                      *
//******************************************************

bool FeetInches::operator >= (const FeetInches &right)
{
   bool status;

   if ((*this > right) || (*this == right))
      status = true;
   else
      status = false;

   return status;
}

//******************************************************
// Overloaded <= operator. Returns true if the current *
// object is set to a value less than or equal to      *
// that of right.                                      *
//******************************************************

bool FeetInches::operator <= (const FeetInches &right)
{
   bool status;

   if ((*this < right) || (*this == right))
      status = true;
   else
      status = false;

   return status;
}

//******************************************************
// Overloaded != operator. Returns true if the current *
// object is set to a value not equal to that of       *
// right.                                              *
//******************************************************

bool FeetInches::operator != (const FeetInches &right)
{
   bool status;

   if (*this == right)
      status = false;
   else
      status = true;

   return status;
}

#ifndef ROOMDIMENSION_H
#define ROOMDIMENSION_H
#include "FeetInches.h"

class RoomDimension
{
private:
FeetInches length; // To hold length of room
FeetInches width; // To hold width of room

public:

// Constructor
RoomDimension()
{}

// Two FeetInches objects as attributes
RoomDimension(FeetInches l, FeetInches w)
{
  length = l.getInches();
  width = w.getInches();
}

double getArea()
{
  FeetInches area;
  area.multiply(length);
  return area;
}


};
#endif

#ifndef ROOMCARPET_H
#define ROOMCARPET_H
#include "RoomDimension.h"

class RoomCarpet
{
double cost;  // To hold cost per square foot
RoomDimension size; // RoomDimension attribute

public:

RoomCarpet(RoomDimension s, double cost)
{
  this->cost = cost;
  size = s;
}

// Funtion to return total cost
double getTotalCost()
{
  return size.getArea() * cost;
}
};
#endif

#include "FeetInches.h"
#include "RoomCarpet.h"
#include "RoomDimension.h"
#include <iostream>
using namespace std;

void main()
{
double cost;
double length;
double width;

cout << "Enter the dimensions of a room and the price ";
cout << "per square foot of the desired carpeting ";

// Create FeetInches object for input
// This calls the istream operator from FeetInches.cpp
FeetInches input;
cin >> input;

FeetInches l(length);
FeetInches w(width);


RoomDimension r(l, w);
cin >> cost;

// Pass Cost to the RoomCarpet constructor
RoomCarpet carpet(r, cost);
cout << "Total Cost: " << carpet.getTotalCost() << endl;

// After I run this it says runtime error. Length is
// being used without being initialized. Also I am supposed
// To use the multiply function from FeetInches.h in
// RoomDimension..I don't know if it will work because I
// Can't get passed the cost input

}

Explanation / Answer


#include <stdio.h>

#include <stdlib.h>


typedef struct {

double dblLength;

double dblWidth;

double dblDiscount;

double dblCost;

double dblArea;

const double dblLabourCost; // = 0.35;

const double dblTaxRate; // = 0.85;

} CARPET;


void carpet_input(CARPET *carpet)

{

printf("Length of room (feet)?> ");

scanf("%lf", &carpet->dblLength);

printf("Width of room (feet)?> ");

scanf("%lf", &carpet->dblWidth);

printf("Customer Discount (%%)");

scanf("%lf", &carpet->dblDiscount);

printf("Cost per Square Foot?> ");

scanf("%lf", &carpet->dblCost);

carpet->dblArea = carpet->dblLength * carpet->dblWidth;

}

void carpet_print(CARPET *carpet)

{

double cost = carpet->dblArea * carpet->dblCost;

double labour = carpet->dblArea * carpet->dblLabourCost;

double sqmCost = carpet->dblCost + carpet->dblLabourCost;

double totCost = sqmCost * carpet->dblArea;

double sqmDiscount = sqmCost * carpet->dblDiscount / 100.0;

double totDiscount = sqmDiscount * carpet->dblArea;

double sqmTaxes = sqmCost * carpet->dblTaxRate;

double totTaxes = sqmTaxes * carpet->dblArea;

printf(" Measurement");

printf(" %-16.16s %11.2lf", "Length", carpet->dblLength);

printf(" %-16.16s %11.2lf", "Width", carpet->dblWidth);

printf(" %-16.16s %11.2lf", "Area", carpet->dblLength * carpet->dblWidth);

printf(" DESCRIPTION COST/SQ.FT CHARGE");

printf(" ----------------- ---------- ----------");

printf(" %-16.16s %11.2lf %10.2lf", "Carpet", carpet->dblCost, cost);

printf(" %-16.16s %11.2lf %10.2lf", "Labor", carpet->dblLabourCost, labour);

printf(" ----------------- ---------- ----------");

printf(" %-16.16s %11.2lf %10.2lf", "INSTALLED PRICE $", sqmCost, totCost);

printf(" %-16.16s %11.2lf %10.2lf", "Discount", sqmDiscount, totDiscount);

printf(" ----------------- ---------- ----------");

printf(" %-16.16s %11.2lf %10.2lf", "SUBTOTAL", sqmCost - sqmDiscount, totCost - totDiscount);

printf(" %-16.16s %11.2lf %10.2lf", "Taxes: ", sqmTaxes, totTaxes);

printf(" ----------------- ---------- ----------");

printf(" %-16.16s %11.2lf %10.2lf", "Total: ", sqmCost * carpet->dblTaxRate + sqmCost - sqmDiscount, totCost * carpet->dblTaxRate + totCost - totDiscount);

printf(" ================= ========== ========== ");

/*

Tax XXXX.XX

TOTAL $XXXX.XX

*/


}


int main(void)

{

CARPET carpet = {

.dblLength = 0.0,

.dblWidth = 0.0,

.dblDiscount = 0.0,

.dblLabourCost = 0.35,

.dblTaxRate = 0.085

};

carpet_input(&carpet);

carpet_print(&carpet);

return 0;

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote