Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please someone help me with this assignment ASAP ALL IN C++ SAMPLE OUTPUT INSTRU

ID: 3763033 • Letter: P

Question

please someone help me with this assignment ASAP

ALL IN C++

SAMPLE OUTPUT

INSTRUCTIONS

ASSIGNMENT 6
20 points
CSC 140: Fall 2015
Date assigned: Monday 11/2
Date due: Wednesday 11/11 (9 days)
Your objective for this assignment will be to demonstrate new concepts regarding classes: writing a class to
model an object, creating objects, and using objects to call their functions. The main program itself will not
necessarily be practical but instead more of a testing ground to define an object and call its functions. Follow
the instructions in the presentation for this assignment (in Blackboard) to create a project with multiple files.
Objectives to be met (Basis for assignment “points”):
1 Demonstrate writing a class using private data and public functions.
2 Demonstrate how to create objects using your class.
3 Demonstrate using objects to call their own functions.
This is a different approach using a class to model a new data type rather than just to write a group of
statements in a main() or other functions. The basic idea is to write a Distance class that represents length as
an object in English measurements (feet and inches). However there will be only one data member for this
class where you store both feet and inches combined into one field as a total length in inches: e.g. 10 ft. 6 in.
stored as 126 inches. This may seem counter-intuitive but good reasons exist for modeling it this way, in fact,
an argument might be made for storing the entire length in just total feet like 10.5. The idea is to make the
internal representation of the object “transparent” to any external (client) program code that might need to
create and work with our Distance objects.
Because the data for each object will be stored as a private data member, you will need some means of
accessing an object’s data: to set (change or transform) its value and to get (return or observe) its value. For
this, define public member functions to “set” a new value for the data field, where a new value would be
passed to this type of function as an argument. And define “get” member functions in your class to retrieve
(return) a Distance object’s data value as follows: to get the entire length with both feet and inches combined,
to get just the feet, and to get just the inches. FYI: These types of “set” and “get” functions are customary
with Object-Oriented Programming languages and sometimes are referred to also as mutator (transformer)
and accessor (observer) functions.
Minimum requirements for a “letter grade of C” (See Recommended Improvements):
1
Follow the UML diagram and adhere to those requirements when writing your Distance
class. (See Other Examples and Appendix F)
2
Your Distance class should model a length using just 1 private data member to represent that
length in feet and inches combined as one value.
3
In your Distance class, include 3 public functions to set (change) an object’s data value: 1 for
total length, 1 for just feet, and 1 for just inches.
4
In your Distance class, include 4 public functions to get (return) an object’s data value: 1 for
total length, 1 for just feet, 1 for just inches, and 1 for total length in fractional feet (e.g. a length
of 126 inches would return 10.5 feet).
5
Complete the TODO steps at the end of these instructions to code your main program function.
Those steps should help guide you with how to define at least 1 Distance object and then
demonstrates calling all its member functions as described in those steps.
6
In your main program class, get the object’s total length in feet and use that value to calculate
the result for a given formula. (See first item under Considerations).
UML Diagram
Distance
- length : long
+ setLength(newLength: long) : void
+ setFeet(newFeet: int) : void
+ setInches(newInches: int) : void
+ getLength( ) : long
+ getFeet( ) : int
+ getInches( ) : int
+ getLengthInFeet( ) : double
// Optional, Recommended Improvement #2, add two Constructors
+ Distance( )
+ Distance(initialLength: long)
// Optional, Recommended Improvement #3, add one toString function
+ toString( ) : string
NOTE: See Assignment 6 Discussion Board forum in Blackboard for help defining required functions,
and for sample program output with all recommended improvements.
Considerations:
? Here is a formula that can be used to estimate the speed a car was traveling from the length of the
skid mark left behind – based on locked brakes and wet pavement (for a car without anti-lock brakes):
double mph = 2 * sqrt( 3 * lengthInFeet );
You should be able to call one of your object’s functions to obtain its length value as a single unit
(both feet and inches combined into feet) and then plug that value into the formula shown above. The
sqrt() function is defined in the header file.
? Start simple by defining your class with the length data member and only a few function
members. Then test your work! Don’t write too much code without testing, or you will almost
certainly run into multiple compiler errors, wasting considerable time and effort. You can compile
your class .cpp file while defining the functions to catch compiler errors before they build up. Do this
repeatedly while building your Distance class so that it is thoroughly tested and clear of compiler
(syntax) errors before you write code in the main program to test your work so far.
? Refer to the class examples and associated UML diagrams about how to define data and functions
based on UML notation. Also refer to Appendix F – Using UML in Class Design.
? Do not add anything to the Distance class that is not included in the UML Diagram or recommended
in the Improvements section. If you think you have a reason to modify the diagram or specifications
for that class then bring it up on the Discussion Board to see if it will be acceptable.
? You will need to use multiplication and division, and probably a type cast, when trying to combine or
extract feet and inches separately from the total length. For example, if the current state of an object’s
length is 33 inches (2 feet, 9 inches) then the getFeet function should return 2 and the getInches
function should return 9. Then, if you call setFeet(5), the object’s length data should become 69
inches (5 feet, 9 inches), and then if you call setInches(3), the object’s length field should become
63 inches (5 feet, 3 inches). Use the Discussion Board for help – there already is a thread with
recommended algorithms for some of these functions.
? Calling a Distance object’s “instance” function from main() will be different than calling other
functions from main() – you must use object-dot-function instead of just the function name.

Steps to code and complete your main() program function…
// TODO: Define 1 Distance object: dist1
// TODO: Call the setLength member function to store a
// length in dist1
// TODO: Define 1 variable type double and assign it the
// calculated speed based on the Distance stored in dist1.
// Use the following formula and the getLengthInFeet
// member function with the dist1 object to get its
// length in feet and inches combined into feet...
//
// mph = 2 * sqrt( 3 * lengthInFeet )
// TODO: Output the length in total feet, total inches, and the
// just the feet and inches parts separately. Call the
// getLengthInFeet, getLength, getFeet, and getInches functions
// to output the Distance object values, and print the
// related mph value calculated for that distance.
// TODO: Call just the setFeet function to change just the feet
// part of the length
// TODO: Output the length in total feet, total inches, and the
// just the feet and inches parts separately.
// TODO: Call just the setInches function to change just the inches
// part of the length
// TODO: Output the length in total feet, total inches, and the
// just the feet and inches parts separately, again.
// TODO: Recalculate the speed in mph for this revised Distance
// and output the mph for that distance.
// OPTIONAL: Add any other code necessary to demonstrate
// other Recommended Improvements according to
// those instructions...

Explanation / Answer

//This is the Distance class defined here.
// To calculate speed each time, use setLength function to set the length, and then call calculateSpeed to calculate the speed in miles per hour! :)

public class distance
{
private:
long length;
long feet;
long inches;
public:
void setLength(long length)
{
this.length=length;
}
void setFeet(long feet)
{
this.feet=feet;
}
void setInches(long inches)
{
this.inches=inches;
}

loong getLength()
{
return length;
}
long getFeet()
{
return feet;
}
long getInches()
{
return inches;
}

long getLengthInFeet()
{
length=(feet*12)+inches;
return length;
}

Distance()
{
length=0;
inches=0;
feet=0;
}

Distance( long length)
{
this.length=length;
}

void calculateSpeed()
{
long mph = 2 * sqrt( 3 * length );
cout<<"The speed is"<<mph;
}

}