Answer to Question #244150 in C++ for sar dar waleed

Question #244150

#include <iostream>

Write a program for carpeting a rectangular room.

Create a class named Dimension that has three fields:

·        one for the length of the room

·        one for the width of the room


It also has a parameterized constructor to set the values of length and width with user-defined values and set area to zero.

Next create a class Carpet that is friend class of the Dimension class. It should have a field for the cost of the carpet per square foot and a parameterized constructor to set its value. The Carpet class should also have a method that calculates the area of the carpet (l*w) and then calculate the cost of carpeting the room by multiplying cost per sq foot with area. It will also return total cost of carpeting the room.

In main(), create instance of Dimension and set values. Then calculate and display total cost of carpeting the room through Carpet class object.



1
Expert's answer
2021-09-29T03:42:28-0400
#include <iostream>
# include<stdio.h>
#include<stdlib.h>

using namespace std;

/*
Write a program for carpeting a rectangular room.
Create a class named Dimension that has three fields:
·        one for the length of the room
·        one for the width of the room


	It also has a parameterized constructor to set the values of length and width with user-defined values and set area to zero.
	Next create a class Carpet that is friend class of the Dimension class. 
	It should have a field for the cost of the carpet per square foot and a parameterized constructor to set its value. 
	The Carpet class should also have a method that calculates the area of the carpet (l*w) and then,
 	calculate the cost of carpeting the room by multiplying cost per sq foot with area. 
 	It will also return total cost of carpeting the room.
	In main(), create instance of Dimension and set values. Then calculate and display total cost of carpeting the room through Carpet class object.
*/


class Dimension
{
	public:
		int length;
		int width;
		int area;
		setDim(int l, int w)
		{
			length = l;
			width = w;
			cout<<"\n\tLength = "<<length<<" fts.";
			cout<<"\n\tWidth  = "<<width<<" fts.";
			area = 0;
		}
};


class Carpet : public Dimension
{
	public:
		float CostPerSqfeet;
		float Area;
		float Cost;
		setCost(float f)
		{
			CostPerSqfeet = f;
			cout<<"\n\tCost per square feet  = US $ "<<CostPerSqfeet<<" per sq. feet";
		}
		float CalculateArea(void)
		{
			Area = length*width;
			cout<<"\n\n\tTotal Carpetting Area = "<<Area<<" sq. feets";
			return(Area);
		}
		float CalculateCost()
		{
			Cost = Area*CostPerSqfeet;
			cout<<"\n\tTotal Carpetting Cost = US $ "<<Cost;
			return(Cost);
		}
};


int main()
{
	class Carpet C;
	
	C.setDim(12,7);
	C.setCost(2);
	C.CalculateArea();
	C.CalculateCost();
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS