Question

I need a c++ visual basic program that will. Carpet Calculator. This problem starts with the...

I need a c++ visual basic program that will.

Carpet Calculator. This problem starts with the FeetInches class that is provided in the course Content area on the assignment page for this week. This program will show how classes will interact with each other as data members within another class. Modify the FeetInches class by overloading the following operators which should all return a bool.

<=

>=

!=

Next add a copy constructor to the FeetInches class and a multiply function.

The copy constructor should accept a FeetInches object as an argument. It will assign the feet attribute the value in the argument’s feet attribute and do the same for the inches attributes.

The multiply function should accept a FeetInches object as an argument. The argument object’s feet and inches attributes will be multiplied by the calling object’s feet and inches attributes. It will return a FeetInches object containing the result of the multiplication.

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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// FeetInches.h
#ifndef FEETINCHES_H
#define FEETINCHES_H
class FeetInches //feetinches class
{
private:
int feet;
int inches;
void simplify();
public:
FeetInches(int ft = 0, int i = 0) //constructoe
{
feet = ft;
inches = i;
simplify();
}
//getter setter methods
void setFeet(int ft)
{
feet = ft;
}
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: //variables declared
int w;
int l;
public://constructor
RoomDimension(int len, int wid)
{
l=len;
w=wid;
}
FeetInches width;
FeetInches length;
int getArea() const //calcualting area
{
return l*w;
}
};
  
---------------------------------------------------------------------------------

// RoomCarpet.h
class RoomCarpet //this is the class where actual calculations are done
{
private:
RoomDimension roomDimensions;
double carpetCost;
public:
RoomCarpet(RoomDimension dim, double cost) //constructor
{
roomDimensions = dim;
carpetCost = cost;
}
double getTotalCost() const //method to calcualte cost
{
return carpetCost * roomDimensions.getArea();
}
};

--------------------------------------------------------------------

// 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 length;
int width;
double cost;
//Reading data from user
cout << "Enter Length";
cin >> length;
cout<<"\nEnter width";
cin>>width;
cout<<"Enter cost";
cin>>cost;
//creating roomDimension and roomCarpet objects
RoomDimension dimension = new RoomDimension(length,width);
RoomCarpet carpet = new carpet(dimension,cost);
//calculating cost by calling getTotalCost method
cout<<"Finally Carpet cost Calculated is: "<<carpet.getTotalCost();
return 0;
}

Add a comment
Answer #2

Program Screenshot:

// carpet.cpp:Defines the entry point for the console application. // To load the standard library // declare the stdafx.h he

Program starts from the main int main) // Declare the variables int length, width; int price, a; // Prompt the user to enter

Output Screenshot:

Enter Dimensions and cost per square feet Enter the length: 30 Enter the width: 40 Enter the price: 10 Total Cost -12000 Pres


Code to copy:

// carpet.cpp : Defines the entry point for the console application.

//

// To load the standard library

// declare the stdafx.h header file in Visual Studio 2015

#include "stdafx.h"

# include <iostream>

// Avoid naming conflicts by using the namespace

using namespace std;

// Create a class RoomDimension

class RoomDimension {

// Declare the variable len, wid

public:

     int len;

     int wid;

// Define the area()

public:

     int area() {

          return len*wid;

     }

};

// Declare the class RoomCarpet

class RoomCarpet {

public: RoomDimension rmd;

public:

     int unit_cost;

// Define the cost()

public:

     int cost() {

          int a = rmd.area();

          return a*unit_cost;

     }

};

// Program starts from the main()

int main() {

     // Declare the variables

     int length, width;

     int price, a;

     // Prompt the user to enter the input

     cout << "Enter Dimensions and cost per square feet" << endl;

     cout << "Enter the length: ";

     cin >> length;

     cout<<endl;

     cout << "Enter the width: ";

     cin >> width;

     cout << endl;

     cout << "Enter the price: ";

     cin >> price;

     cout << endl;

     RoomDimension rd;

     RoomCarpet rc;

     rd.len = length;

     rd.wid = width;

     rc.unit_cost = price;

     rc.rmd = rd;

     // Store the result in the variable 'a'

     a = rc.cost();

     // Dispaly the total cost

     cout << "Total Cost =" << a << endl;

     //system("pause"); // for Visual Studio 2015

     return 0;

}

Add a comment
Know the answer?
Add Answer to:
I need a c++ visual basic program that will. Carpet Calculator. This problem starts with the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants...

    This is in c programming using functions in visual studios Carpet Jolb A carpeting company wants to estimate what it will cost a customer to have a room carpeted. They can carpet 65 sq. ft. of room space in 4 hours, and they charge $25.00 per hour as their labor rate Write a program to ask the user for the length of the room (in inches) to be carpeted, the width of the room (in inches) to be carpeted, and...

  • IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header...

    IN C++ MUST INCLUDE HEADER FILE, IMPLEMENTATION FILE, AND DRIVER FILE. IN C++ Create a header and implementation file to define an apartment class. Create a driver program to test the class, and create a make file to compile the driver program. Create two files called apartment.h and appartmentImp.cpp along with creating a driver program named testApartment.cpp containing the main function. Program Requirements: • Class attributes should include integers for number of rooms, monthly rent, and square feet, as well...

  • #include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured...

    #include <iostream> #include <string> #include <stdio.h> using namespace std; /** The FeetInches class holds distances measured in feet and inches. */ class FeetInches { private: int feet; // The number of feet int inches; // The number of inches /** The simplify method adjusts the values in feet and inches to conform to a standard measurement. */ void simplify() { if (inches > 11) { feet = feet + (inches / 12); inches = inches % 12; } } /**...

  • program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks,...

    program language: python 3 Purpose: Solve a problem by writing multiple functions that perform different subtasks, and combining their use to solve a larger problem. Also to practice documenting functions. Degree of Difficulty: Moderate Your task is to compute the cost of renovating the flooring in a rectangular room. This includes replacing the carpet and and the baseboards. Your task is to write a Python program that calculates and the cost of the renovation. To accomplish this, you will need...

  • Template Exercise (50 pts) Modified FeetInches Specification file (30pts) – FeetInches.h Driver program with function template...

    Template Exercise (50 pts) Modified FeetInches Specification file (30pts) – FeetInches.h Driver program with function template (20 pts) – TempDriver.cpp Template Exercise Write template for two functions called minimum and maximum. Each function should accept two arguments and return the lesser or greater of the two values. Test these templates in a driver program. The template with the following types: int, double, string and FeetInches (which is an object). You will need: The FeetInches class (which was provided in Week...

  • ////****what am i doing wrong? im trying to have this program with constructors convert inches to...

    ////****what am i doing wrong? im trying to have this program with constructors convert inches to feet too I don't know what im doing wrong. (the program is suppose to take to sets of numbers feet and inches and compare them to see if they are equal , greater, less than, or not equal using operator overload #include <stdio.h> #include <string.h> #include <iostream> #include <iomanip> #include <cmath> using namespace std; //class declaration class FeetInches { private:    int feet;   ...

  • I need help with the C++ for the following problem: Write a program uses objected oriented...

    I need help with the C++ for the following problem: Write a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(),...

  • In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class...

    In c++ Please. Now take your Project 4 and modify it.  You’re going to add another class for getting the users name. Inherit it. Be sure to have a print function in the base class that you can use and redefine in the derived class. You’re going to also split the project into three files.  One (.h) file for the class definitions, both of them.  The class implementation file which has the member function definitions. And the main project file where your main...

  • PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1:...

    PLEASE DO IN C# AND MAKE SURE I CAN COPY CODE IN VISUAL STUDIO Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: 1. Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 1.0 in the default constructor. 2. A non-argument constructor method to create a default rectangle. 3. Another constructor method to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT