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

C++ homework help! Assignment using PRIVATE and PUBLIC functions. Please help! P

ID: 3567641 • Letter: C

Question

C++ homework help! Assignment using PRIVATE and PUBLIC functions. Please help! Pictures are the assignment.

Thank you!

NOTE: See Assignment 6 Discussion Board form in Blackboard for help defining functions and 'ample program output Considerations: ? Here is a formula that can be used to estimate the speed a car was traveling from the length of the skid mark Ieft 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 use one of your object's functionss to obtain its length value as a single unit (both feet and inches combined) and then plug that value into the formula shown above. The sqrt () function is defined in the header file.

Explanation / Answer

// DistanceDemoProgram.cpp : main project file.

#include "stdafx.h"

#include <iostream>

#include <cmath>

using namespace std;

//inorder to maintain the

//feet vales and inches values

//feets and inch are declared as static

static int feets=0, inch=0;

//class declaration

class Distance

{

     //private member

private:

     long length;

     //public memebers

public:

     Distance();

     void setLength(long len);

     void setFeet(int feet);

     void setInches(int inches);

     long getLength();

     int getFeet();

     int getInches();

     double getLengthInFeet();

};

//definition of constructor

Distance::Distance()

{

     length=0;

   

}

//definition of setLength

void Distance::setLength(long len)

{

     length=len;

     feets=length/12;

     inch=length%12;

}

//defintion of setFeet

void Distance::setFeet(int feet)

{

     feets=feet;

     length=(feet*12)+inch;   

}

//defintion for setInches

void Distance::setInches(int inches)

{

     length=(feets*12)+inches;

}

//defintion for getLength

long Distance::getLength()

{

     return length;

}

//defintion for getInches

int Distance::getInches()

{

     return inch;

}

//defintion for getFeet

int Distance::getFeet()

{

     return feets;

}

//defintion for getLengthInFeet

double Distance::getLengthInFeet()

{

     double lengthinfeet=length/12.0;

     return lengthinfeet;

}

//main class

int main()

{

     //instance is an object of Distance class

     Distance instance;

     //call the setLength method

     instance.setLength(126);

     //display what the Length value is set

     cout<<"Distance is set to "<<instance.getFeet()<<"ft "<<instance.getInches()<<"inches"<<endl;

     //formula to calculate the speed of the car

     double mph=2*sqrt(3*instance.getLengthInFeet());

     //display the final result

     cout<<"The speed of the car is traveling from length "<<instance.getLength()

          <<" is: "<<mph<<endl;

}

----------------------------------------------------------------------------------------------

Sample Output:

Distance is set to 10ft 6inches

The speed of the car is traveling from length 126 is: 11.225mp

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote