Details of this Paper

Lab8 Ex2. Object Conversion and Aggregation - fr. Program Charllenge Chap14-12. LandTract Class

Description

solution


Question

Question;Lab8 Ex2. Object Conversion and Aggregation - fr. Program Charllenge Chap14-12. LandTract Class;Make a LandTract class that is composed of two FeetInches objects, one for the tract s length and one for the width. The class should have a member function that returns the tract s area. Demonstrate the class in a program that asks the user to enter the dimensions for two tracts of land. The program should display the area of each tract of land and indicate whether the tracts are of equal size.;To calculate the area, the FeetInches objects have to be converted into double (in feet). You will need to impletement the object conversion inside the FeetInches class to double in order to compute the area in square feet.;FeetInches::operator double();The final output of this exercise shall display the area in square feet, and drop the fraction.;Starter: lab8_ex2.zip (lab8_ex2.cpp, FeetInches.h, FeetInches.cpp);You need to add the FeetInches object conversion to double in FeetInches class.;Submit: lab8_ex2.zip (lab8_ex2.cpp, FeetInches.h, FeetInches.cpp, LandTract.h, LandTract.cpp);lab8_ex2.cpp;// Lab8 Ex2 Aggregation fr. Ch14-12: LandTract Class;#include;#include "FeetInches.cpp;#include "LandTract.cpp;using namespace std;int main();// Create two FeetInches objects for width;// and length.;FeetInches width(125, 6);FeetInches length(275, 0);// Create a LandTract Class.;LandTract land(width, length);// Display the area.;cout << "The area of the tract is;<< land.getArea() << endl;return 0;FeetInches.h;// Specification file for the FeetInches class;#ifndef FEETINCHES_H;#define FEETINCHES_H;#include;using namespace std;class FeetInches, // Forward Declaration;// Function Prototypes for Overloaded Stream Operators;ostream &operator (istream &&, FeetInches &);// The FeetInches class holds distances or measurements;// expressed in feet and inches.;class FeetInches;private;int feet, // To hold a number of feet;int inches, // To hold a number of inches;void simplify(), // Defined in FeetInches.cpp;public;// Constructor;FeetInches(int f = 0, int i = 0);{ feet = f;inches = i;simplify(), };// New Constructor added for this assignment.;// This constructor takes double argument and;// converts it to feet and inches. Example;// 2.5 would be converted to 2 feet 6 inches.;FeetInches(double distance);{ feet = static_cast (distance);inches = (distance - feet) * 12, };// Copy constructor;FeetInches(FeetInches &right);{ feet = right.feet;inches = right.inches, };// Mutator functions;void setFeet(int f);{ feet = f, };void setInches(int i);{ inches = i;simplify(), };// Multiply function;FeetInches multiply(FeetInches obj);{ FeetInches temp;temp.feet = feet * obj.feet;temp.inches = inches * obj.inches;temp.simplify();return temp, };// Accessor functions;int getFeet() const;{ return feet, };int getInches() const;{ return inches, };// Overloaded operator functions;FeetInches operator + (const FeetInches &);FeetInches operator - (const FeetInches &);FeetInches operator ++ (), // Prefix ++;FeetInches operator ++ (int), // Postfix ++;bool operator > (const FeetInches &);bool operator = (const FeetInches &);bool operator <= (const FeetInches &);bool operator != (const FeetInches &);// Conversion functions;// Friends;friend ostream &operator (istream &&, FeetInches &);#endif;FeetInches.cpp;// Implementation file for the FeetInches class;#include // Needed for abs();#include "FeetInches.h;//************************************************************;// Definition of member function simplify. This function *;// checks for values in the inches member greater than *;// twelve or less than zero. If such a value is found, *;// the numbers in feet and inches are adjusted to conform *;// to a standard feet & inches expression. For example, *;// 3 feet 14 inches would be adjusted to 4 feet 2 inches and *;// 5 feet -2 inches would be adjusted to 4 feet 10 inches. *;//************************************************************;void FeetInches::simplify();if (inches >= 12);feet += (inches / 12);inches = inches % 12;else if (inches operator. Returns true if the current object *;// is set to a value greater than that of right. *;//************************************************************;bool FeetInches::operator > (const FeetInches &right);bool status;if (feet > right.feet);status = true;else if (feet == right.feet && inches > right.inches);status = true;else;status = false;return status;//************************************************************;// Overloaded < operator. Returns true if the current object *;// is set to a value less than that of right. *;//************************************************************;bool FeetInches::operator < (const FeetInches &right);bool status;if (feet < right.feet);status = true;else if (feet == right.feet && inches < right.inches);status = true;else;status = false;return status;//*************************************************************;// Overloaded == operator. Returns true if the current object *;// is set to a value equal to that of right. *;//*************************************************************;bool FeetInches::operator == (const FeetInches &right);bool status;if (feet == right.feet && inches == right.inches);status = true;else;status = false;return status;//********************************************************;// Overloaded << operator. Gives cout the ability to *;// directly display FeetInches objects. *;//********************************************************;ostream &operator<<(ostream &strm, const FeetInches &obj);strm << obj.feet << " feet, " << obj.inches operator. Gives cin the ability to *;// store user input directly into FeetInches objects. *;//********************************************************;istream &operator >> (istream &strm, FeetInches &obj);// Prompt the user for the feet.;cout obj.feet;// Prompt the user for the inches.;cout obj.inches;// Normalize the values.;obj.simplify();return strm;//*************************************************************;// Conversion function to convert a FeetInches object *;// to a double. *;//*************************************************************;// FeetInches::operator double();//*************************************************************;// Conversion function to convert a FeetInches object *;// to an int. *;//*************************************************************;// FeetInches:: operator int();// New operators;//******************************************************;// Overloaded >= operator. Returns true if the current *;// object is set to a value greater than or equal to *;// that of right. *;//******************************************************;bool FeetInches::operator >= (const FeetInches &right);bool status;if ((*this > right) || (*this == right));status = true;else;status = false;return status;//******************************************************;// Overloaded <= operator. Returns true if the current *;// object is set to a value less than or equal to *;// that of right. *;//******************************************************;bool FeetInches::operator <= (const FeetInches &right);bool status;if ((*this < right) || (*this == right));status = true;else;status = false;return status;//******************************************************;// Overloaded != operator. Returns true if the current *;// object is set to a value not equal to that of *;// right. *;//******************************************************;bool FeetInches::operator != (const FeetInches &right);bool status;if (*this == right);status = false;else;status = true;return status;Tutorials for this Question;Available for;$40.00;Lab8 Ex2. Object Conversion and Aggregation - fr. Program Charllenge Chap14-12. LandTract Class;Tutorial # 00018167;Number of words in this Tutorial: 13;Posted On: 06/29/2014 01:44 PM;Feedback Score: Not rated yet!;This tutorial has been purchased 0 times.;Posted By: maqj;Questions:1137Tutorials:1044Spent$0.00Earned$2,596.00;Feedback Score:75% (4 ratings);Report this Tutorial as Inappropriate;Tutorial Preview;?Aggregation x?;Attachments;lab8_ex2.zip (3.84 KB);Preview not available.;Purchase this Tutorial @ $40.00 *;* - Additional Paypal / Transaction Handling Fee (3.4% of Tutorial price + $0.30) applicable;Copyright ? 2012-2014 HomeworkMinutes.com

 

Paper#30249 | Written in 18-Jul-2015

Price : $62
SiteLock