Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

FeetInches Class Copy Constructor and multiply Function Add a copy constructor to the FeetInches class. This constructor should accept a FeetInches object as an argument.

FeetInches Class Copy Constructor and multiply Function

Add a copy constructor to the FeetInches class. This constructor should accept a FeetInches object as an argument. The constructor should assign to the feet attribute the value in the arguments feet attribute, and assign to the inches attribute the value in the arguments inches attribute. As a result, the new object will be a copy of the argument object. Next, add a multiply member function to the FeetInches class. The multiply function should accept a FeetInches object as an argument. The argument objects feet and inches attributes will be multiplied by the calling objects feet and inches attributes, and a FeetInches object containing the result will be returned.

Carpet Calculator

The Westfield Carpet Company has asked you to write an application 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 10 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 Programming Challenge 11 with the addition of a multiply member function. You can use this function to calculate the area of the room.) 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. Once you have written these classes, use them in an application that asks the user to enter the dimensions of a room and the price per square foot of the desired carpeting. The application should display the total cost of the carpet.

Instructions

Implement:

1. Redefine stream operators. 2. Overloaded constructors functions. 3. Mutator functions. 4. Accessor functions.

Please Show answer using the following code as an example on what to apply to the problem above the instructions c++

#ifndef _MAGIC_DATE_H #define _MAGIC_DATE_H #include using namespace::std; #include "Date.h"; class MagicDate { private: Date date; public: MagicDate(int month, int day, int year); int getYear() const; bool getMagicDay() const; void display() const; }; #endif ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include #include using namespace::std; #include "MagicDate.h" MagicDate::MagicDate(int month, int day, int yeary) :date(month, day, yeary) {} int MagicDate::getYear() const { //cambio a do digito int twoDigitsYear; string yyyy; yyyy = to_string(date.getYear()); char yyTemp[3]; yyTemp[0] = yyyy[2]; yyTemp[1] = yyyy[3]; yyTemp[2] = '\0'; twoDigitsYear = atoi(yyTemp); return twoDigitsYear; } bool MagicDate::getMagicDay() const { if (date.getMonth() * date.getDay() == getYear()) return true; else return false; } void MagicDate::display() const { if (getMagicDay()) { cout << "The " << date << " is a magic date "; } else { cout << "The " << date << " is not magic date "; } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #ifndef _DATE_H #define _DATE_H class Date { private: int month, day, year; public: //Constructores Date(); Date(int aMonth, int aDay, int aYear); //Copy Constructor Date(const Date& aDate); //Destructor ~Date(); //Mutators void setMonth(int aMonth); void setDay(int aDay); void setYear(int aYear); //Accessor int getMonth() const; int getDay() const; int getYear() const; //Funcion que imprime la fecha void displayDate() const; void helpIncrement(); bool endOfMonth(int testDay); bool leapYear(int testYear); Date& operator++(); // prefix increment operator Date operator++(int); // postfix increment operator bool operator==(const Date& obj); friend ostream& operator << (ostream& strm, const Date& obj); friend istream& operator >> (istream& strm, Date& obj); static const int days[]; // array of days per month }; #endif ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + #include #include using namespace::std; #include "MagicDate.h" MagicDate::MagicDate(int month, int day, int yeary) :date(month, day, yeary) {} int MagicDate::getYear() const { //cambio a do digito int twoDigitsYear; string yyyy; yyyy = to_string(date.getYear()); char yyTemp[3]; yyTemp[0] = yyyy[2]; yyTemp[1] = yyyy[3]; yyTemp[2] = '\0'; twoDigitsYear = atoi(yyTemp); return twoDigitsYear; } bool MagicDate::getMagicDay() const { if (date.getMonth() * date.getDay() == getYear()) return true; else return false; } void MagicDate::display() const { if (getMagicDay()) { cout << "The " << date << " is a magic date "; } else { cout << "The " << date << " is not magic date "; } } ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include using namespace::std; #include "MagicDate.h" int main() { MagicDate myBirthday1(2, 10, 1920); myBirthday1.display(); MagicDate myBirthday2(2, 10, 1921); myBirthday2.display(); system("pause"); return 0; }

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_2

Step: 3

blur-text-image_3

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

Advances In Spatial And Temporal Databases 10th International Symposium Sstd 2007 Boston Ma Usa July 2007 Proceedings Lncs 4605

Authors: Dimitris Papadias ,Donghui Zhang ,George Kollios

2007th Edition

3540735399, 978-3540735397

More Books

Students also viewed these Databases questions

Question

why should we read Kempe s text as fiction? Jessica Barr

Answered: 1 week ago