Sale!

COSC6000 Homework 05

$30.00 $18.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (7 votes)

Develop a class called USLength that is an abstract data type (ADT) for a length.
The complete class will include all the following public member functions :
A constructor to set yards, feet and inches; ex. 2yd 2ft 3in can be set as USLength item1(2,2,3);
A constructor to set feet and inches; ex. 4ft 3in can be set as USLength item1(4,3);
A constructor to set inches; ex. 23in can be set as USLength item1(23);
A default constructor (takes no input) that sets 0yd 0ft 0in.
Public member function, “getYards()” that returns the yard part of length.
Public member function, “getFeet()” that returns the foot part of length.
Public member function, “getInches()” that returns the inch part of length.
Public member function, setLength(1,2,3) that sets 1yd 2ft 3in.
You may define private member functions. (helper functions)
It is your decision how to store the length information, yard, feet, and inches.
You can assume that yard, feet, and inches are all integers.
All member variables must be private.
Note: 12inches = 1foot, 3feet = 1yard.
Use following main function to test your class.
int main(int argc, const char * argv[]) {
USLength bar1(100);
USLength bar2(3,8);
USLength bar3(3,13);
USLength bar4(1,2,23);

std::cout << “bar1 : ” << bar1.getYards() << ” yards, ” << bar1.getFeet() << ” feet, ” << bar1.getI
nches() << ” inches\n”;
std::cout << “bar2 : ” << bar2.getYards() << ” yards, ” << bar2.getFeet() << ” feet, ” << bar2.getI
nches() << ” inches\n”;
std::cout << “bar3 : ” << bar3.getYards() << ” yards, ” << bar3.getFeet() << ” feet, ” << bar3.getI
nches() << ” inches\n”;
std::cout << “bar4 : ” << bar4.getYards() << ” yards, ” << bar4.getFeet() << ” feet, ” << bar4.getI
nches() << ” inches\n”;

USLength bar12;
bar12.setLength(bar1.getYards() + bar2.getYards(), bar1.getFeet() + bar2.getFeet(), bar1.getInches(
)+ bar2.getInches());
std::cout << “bar12 : ” << bar12.getYards() << ” yards, ” << bar12.getFeet() << ” feet, ” << bar12.
getInches() << ” inches\n”;
return 0;
}
4/23/2018 Homework 05
https://tulane.instructure.com/courses/2165899/assignments/13464159 2/2
The output must be:
bar1 : 2 yards, 2 feet, 4 inches
bar2 : 1 yards, 0 feet, 8 inches
bar3 : 1 yards, 1 feet, 1 inches
bar4 : 2 yards, 0 feet, 11 inches
bar12 : 4 yards, 0 feet, 0 inches
You see, for example, ‘bar1’ is set 100 inches and the output shows 2 yards, 2 feet and 4 inches. That is
100/12=8 feet, the remeinder is 4 inches, 8/3=2 yards, the remeinder is 2 feet.