I'm making a program that uses three classes to calculate the price of carpet in a rectangular room: The price is calculated by multiplying the area of the floor by the price per square foot.
In my RoomDimension class i need two FeetInches objects for length and width. I should use a multiply member function to calculate the area. The class should have a member function that returns the area of the room as a FeetInches object.
In the RoomCarpet class there should be a Room Dimension object as an attribute. There should also be 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.
The main portion should ask for the dimensions and the price per square foot . It should then display the total cost of the carpet.
Here is my code:

``````// FeetInches.h
#ifndef FEETINCHES_H
#define FEETINCHES_H

class FeetInches
{
private:
int feet;
int inches;
void simplify();

public:
FeetInches(int f = 0, int i = 0)
{
feet = f;
inches = i;
simplify();
}

void setFeet(int f)
{
feet = f;
}
void setInches(int i)
{
inches = i;
simplify();
}
int getFeet() const
{
return feet;
}
int getInches() const
{
return inches;
}

FeetInches operator + (const FeetInches &);
FeetInches operator - (const FeetInches &);

};

#endif

// RoomDimension.h

#include "FeetInches.h"

class RoomDimension
{
private:
int w;
int l;

public:
FeetInches width;
FeetInches length;

};

// RoomCarpet.h

class RoomCarpet
{
private:

public:

};

// FeetInches.cpp

#include <cstdlib>
#include "FeetInches.h"

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);
}
}
FeetInches FeetInches::operator - (const FeetInches &right)
{
FeetInches temp;

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

// RoomMain.cpp

#include "RoomCarpet.h"
#include "RoomDimension.h"
#include "FeetInches.h"
#include <iostream>

using namespace std;

int main()
{
int l;
int w;

cout << "What are the dimensions of the room? ";
cin >>

return 0;
}``````

I know it's not much, but if someone can get me on the right path I would appreciate it. Thanks!

Start by looking at this class and deciding exactly what you want here:

``````class RoomDimension
{
private:
int w;
int l;

public:
FeetInches width;
FeetInches length;

};``````

You have two pairs of width/length here. Why? Better to store only one and to convert from inches to feet/inches and vice versa as needed. Decide how you want the user to enter input and state that explicitly (i.e. feet and inches or just inches), read in the input and create whatever objects you need in main in order to use these classes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.