2. Given the length class interface below: class length public: length(); length
ID: 3803024 • Letter: 2
Question
2. Given the length class interface below: class length public: length(); length (int f, int i); initialized Postconditin: a new length object is declared and void set Feet (int); known as the "mutator" function object is changed Postcondition: feet date member of the calling void set Inches (int); int get Feet() function is returned known as the "accessor" calling object Postcondition: feet data member of the int get Inches bool compare (length& obj2); compare the the calling object to obj3 otherwise condition: return true if calling object is longer; return false void display(); object like 5'7" for 5 feet 7 inches Postcondition: display the contents of the callig than 12 Note that the inches part must be less length& obj2); object and obj2 Postcondition: Display the contents of the sum of the calling Note that the inches must be less than 12 double area length& obj2); obj width Post return the area of a rectangle where calling represents the sqare ft. and obj2 represents the length of the rectangle Area is measure inExplanation / Answer
Here is the code for you:
#include <iostream>
class length
{
int feet;
int inches;
public:
length()
{
feet = inches = 0;
}
length(int f, int i)
{
feet = f; inches = i;
}
void setFeet(int f)
{
feet = f;
}
void setInches(int i)
{
inches = i;
}
int getFeet()
{
return feet;
}
int getInches()
{
return inches;
}
bool compare(length& obj2)
{
return feet == obj2.feet && inches == obj2.inches;
}
void display()
{
std::cout << feet + inches / 12 << "'" << inches%12 << """ << std::endl;
}
length add(length& obj2)
{
return length(feet + obj2.feet, inches + obj2.inches);
}
double area(length& obj2)
{
int totalInches = (feet * 12 + inches) * (obj2.feet * 12 + obj2.inches);
return totalInches / 12.0;
}
};
void display(length obj)
{
obj.display();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.