last point from backward difference formula

What will be an ideal response?


```
first.observed[numPoints-1]
= observed[numPoints-1] - observed[numPoints-2];
}

void ObservedFunction::findSecond(ObservedFunction& second)
{
// ensure array second is of correct size (2 smaller)
if (second.numPoints != numPoints - 2) {
second.numPoints = numPoints - 2;
second.deleteFunction();
second.observed = new double [second.numPoints];
}

for (int i=1; i < numPoints - 1; i++)
second.observed[i-1] = observed[i+1] - 2 * observed[i] +
observed[i-1];
}

double ObservedFunction::getValue(int index) const
{
return observed[index];
}

istream& operator>> (istream& is, ObservedFunction& of)
{
for (int i = 0; i < of.numPoints; i++) {
cin >> of.observed[i];
}
return is;
}

ostream& operator<< (ostream& os, const ObservedFunction& of)
{
cout << setiosflags(ios::fixed) << setprecision(1);
for (int i = 0; i < of.numPoints; i++)
cout << setw(10) << of.observed[i];
cout << endl;
return os;
}
class RaceCar
{
public:
RaceCar(){}
RaceCar(int, double);
void deleteRaceCar(); // free mem
void findForce();

private:
ObservedFunction distance;
ObservedFunction velocity;
ObservedFunction deaccel;
double* force;
int numPoints;
double mass;

friend istream& operator>> (istream&, RaceCar&);
friend ostream& operator<< (ostream&, const RaceCar&);
};

RaceCar::RaceCar(int points, double carMass)
:distance(points), velocity(points), deaccel(points-2)
{
numPoints = points;
mass = carMass;
force = new double [points-2];

for (int i = 0; i < points-2; i++)
{
force[i]=0;
}
}

void RaceCar::deleteRaceCar()
{
delete[] force;
distance.deleteFunction();
velocity.deleteFunction();
deaccel.deleteFunction();
}

void RaceCar::findForce()
{
distance.findFirst(velocity);
distance.findSecond(deaccel);
for (int i = 0; i < numPoints-2; i++)
force[i] = mass * deaccel.getValue(i);

}

istream& operator>> (istream& is, RaceCar& rc)
{
cin >> rc.distance;
return is;
}

ostream& operator<< (ostream& os, const RaceCar& rc)
{
int i;

cout << setw(-12) << "Distance:" << rc.distance << endl
<< setw(-12) << "Velocity:" << rc.velocity << endl
<< setw(-12) << "Deaccel:" << setw(11) << " "
<< rc.deaccel << endl << setw(-12) << "Force:" << setw(13)
<< " ";
for (i = 0; i < rc.numPoints-2; i++) {
cout << setw(10) << rc.force[i];
}
cout << endl;
return os;
}

int main()
{
int num;
double mass;
RaceCar car;

cout << endl << "What is the mass of the car? => ";
cin >> mass;
cout << endl << "How many points were observed? => ";
cin >> num;
car = RaceCar(num, mass);
cout << endl << "Please enter the " << num << " distances => ";
cin >> car;
car.findForce();

cout << endl << car << endl;

return 0;
}

```

Computer Science & Information Technology

You might also like to view...

Most programmers use the Structure statement to create data types that contain procedures.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Case-Based Critical Thinking QuestionsCase 21-1Maxwell is learning about evaluating the quality of information people can find online. He is looking for the answers to the following three questions. Which of the following can raise the quality rating of a Web site?

A. information is re-posted B. information is republished C. information originates at the site D. information is retweeted

Computer Science & Information Technology

Calculating the specificity using weighting methodology, which of the following selectors have the lowest weight?

A. class selectors B. element selectors C. id selectors D. universal selectors

Computer Science & Information Technology

An unbound form is a form that it is directly connected to a data source such as a table or query and can be used to enter, edit, or display data from that data source

Indicate whether the statement is true or false

Computer Science & Information Technology