Question: Assignment (OOP) Carpet Class You are asked to write a program using C++ Object Oriented programming concept. You will design a Carpet class that will

Assignment (OOP) Carpet Class

You are asked to write a program using C++ Object Oriented programming concept. You will design a Carpet class that will have information of length, width of a room and the carpeting cost per square yard. The Inventory class will have the following private member variables.

Data member name

Description

length

An int type data that holds the rooms length in yards

width

An int type data that holds rooms width in yards

unitCost

A double type data that holds cost of carpeting per Sq yard

totalCost

A double type data that holds the total cost of carpeting

The Carpet class will have the following public member functions.

Member function

Description

Default Constructor

Set all the member variables to 0

setLength

Accepts an Integer argument that is copied to the length member

setWidth

Accepts an Integer argument that is copied to the width member

setUnitCost

Accepts an double argument that is copied to the unitCost member

setTotalCost

Calculates the total cost of carpeting for the room that is product of length, width and unitCost and stores the product in the totalCost member

getLength

Returns the value in length

getWidth

Returns the value in width

getUnitCost

Returns the value in unit cost

getTotalCost

Returns the value in totalCost

You are required to do the input validation inside respective member functions not to accept negative values for length, width, and unit cost.

You will create Carpet object specification (Carpet.h) and implementation (Carpet.cpp) codes.

Use the given driver program (CarpetingDriver.cpp) given in the next page to test the Carpet.h and Carpet.cpp.

You submit the zipped folder with the following files: Carpet.h, Carpet.cpp, and CarpetingDriver.cpp.

// declare an Carpet object and the following variables

Carpet hall;

int hall_length;

int hall_width;

double hall_UnitCost;

// Display the member values

cout << Object is initialized with values using the default constructor ";

cout << "The values of the members --- ";

cout << "Length: " << hall. getLength () << endl;

cout << "Width: " << hall. getWidth () << endl;

cout << "Unit Cost: " << hall. getUnitCost () << endl;

cout << "Total cost: " << hall. getTotalCost () << endl << endl;

// Enter the member values.

cout << "Enter length: ";

cin >> length

cout << "Enter width: ";

cin >> width

cout << "Enter unit cost of carpeting: ";

cin >> unitCost;

hall.setLength (length); //sets the value

hall.setWidth (width); //sets the value

hall.setUnitCost (unitCost); //sets the value

hall.setTotalCost (length, width); //compute and sets the value

// Display the values

cout << "The values of the members --- ";

cout << "Length: " << hall. getLength () << endl;

cout << "Width: " << hall. getWidth () << endl;

cout << "Unit Cost: " << hall. getUnitCost () << endl;

cout << "Total cost: " << hall. getTotalCost () << endl << endl;

Sample Output:

Object is initialized with values using the default constructor ";

The values of the members ---

Length: 0

Width: 0

Unit Cost: 0

Total cost: 0

The values of the members ---

Length: 20

Width: 30

Unit Cost: 25.75

Total cost: $15450.00

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!