Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ * Please be sure that your code is structured into the following files: - UML - FeetInches class - RoomDimension class - RoomCarpet class

C++

* Please be sure that your code is structured into the following files:

- UML

- FeetInches class

- RoomDimension class

- RoomCarpet class

- carpetmain.cpp

- makefile

Part B needed

Part B- Write a program that calculates the price of carpeting for rectangular rooms. To calculate the price, you multiply the area of the floor (width times length) by the price per square foot of carpet. For example, the area of floor that is 12 feet long and 10 feet wide is 120 square feet. To cover that floor with carpet that costs $8 per square foot would cost $960. (12 X 10 X 8 = 960.)"

First, you should create a class named RoomDimension that has two FeetInches objects as attributes: one for the length of the room and one for the width. (You should use the version of the FeetInches class that you created in Part A) The RoomDimension class should have a member function that returns the area of the room as a FeetInches object.

Next, you should create a RoomCarpet class that has a RoomDimension object as an attribute. It should also have an attribute for the cost of the carpet per square foot. The RoomCarpet class should have a member function that returns the total cost of the carpet.

Note: start by developing the UML diagram.

Part A has been completed

Part A - Modify the FeetInches class, discussed in lecture, so that it overloads the following

operators: - <=

- >= - != - * (multiplication)

- Demonstrate the classs capabilities in a simple program.

FeetInches Program from part A for reference

FeetInches.h:

#ifndef FEETINCHES_H

#define FEETINCHES_H

// 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(); }

// Mutator functions

void setFeet(int f)

{ feet = f; }

void setInches(int i)

{ inches = i;

simplify(); }

// Accessor functions

int getFeet() const

{ return feet; }

int getInches() const

{ return inches; }

// Overloaded operator functions

FeetInches operator + (const FeetInches &); // Overloaded +

FeetInches operator - (const FeetInches &); // Overloaded -

bool operator <= (const FeetInches &);

bool operator >= (const FeetInches &);

bool operator != (const FeetInches &);

FeetInches operator * (const FeetInches &);

};

#endif

FeetInchesmain.cpp:

#include

#include "FeetInches.h"

using namespace std;

int main()

{

FeetInches a(7,8);

FeetInches b(6,7);

cout << (a + b).getFeet() << endl;

cout << (a + b).getInches() << endl;

cout << (a - b).getFeet() << endl;

cout << (a - b).getInches() << endl;

cout << (a <= b) << endl;

cout << (a >= b) << endl;

cout << (a != b) << endl;

cout << (a * b).getFeet() << endl;

cout << (a * b).getInches() << endl;

}

FeetInches.cpp:

// Implementation file for the FeetInches class

#include // 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. *

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

//overload >=

bool FeetInches::operator >= (const FeetInches &right)

{

if(inches >= right.inches && feet >= right.feet)

return true;

else

return false;

}

//overload <=

bool FeetInches::operator <= (const FeetInches &right)

{

if(inches <= right.inches && feet <= right.feet)

return true;

else

return false;

}

//overload !=

bool FeetInches::operator != (const FeetInches &right)

{

if(inches != right.inches && feet != right.feet)

return true;

else

return false;

}

//overload * 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 binary - operator. *

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

FeetInches FeetInches::operator - (const FeetInches &right)

{

FeetInches temp;

temp.inches = inches - right.inches;

temp.feet = feet - right.feet;

temp.simplify();

return temp;

}

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);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems 12th Asian Conference ACIIDS 2020 Phuket Thailand March 23 26 2020 Proceedings

Authors: Pawel Sitek ,Marcin Pietranik ,Marek Krotkiewicz ,Chutimet Srinilta

1st Edition

9811533792, 978-9811533792

More Books

Students also viewed these Databases questions

Question

What appraisal intervals are often used in appraisal reviews?

Answered: 1 week ago