Cmpsc H.w

<p>Write a C++ program that finds ths closest integer approximate root of a linear equation that is known to contain a root between x=-100 and x=100. The program must read two values from the external data file C:/TEMP/a3data.txt. The two values are to be used as the m and b terms in the linear equation y=mx + b and they will be read from the file in that order. There will be no user input into the program since the two values are read from a data file. The program must output the rounded integer approximate rootand the number of loop iterations that were used to find the approximate root. For example, if the real root is 8.5, then the outputted integer should be 9. If the real root is -8.5, then the outputted integer should be -9. You must use a loop in this program that inspects possible integer roots starting at x=-100. DO NOT set y = 0 and solve the equation for x ith assignment statements.</p>

<p>Any thoughts/suggestions?-----</p>

<p>Well the answer is pretty much spelled out for you, use a loop to solve the root using an iterative approach. Do a loop to go from -100 to 100 for the value of x, something like </p>

<p>for (x=-100; x<=100; x++)
{
…
}</p>

<p>Plug the value of x into your equation (y=mx + b) and check the y-value each iteration. Since it’s a linear equation, the value of y will only across the x-axis (y=0) once. So first check to see if there is an x-value that returns a y-value of 0. That x-value your root. However, since you are only using integer x values, it’s possible you will never get the exact root, thus it’s possible y is never actually 0 (for example, x=7, y=-0.7; x=8, y=0.2). So you will need to check to see if the sign of y changes, and take the x value with a corresponding y value whose magnitude (absolute value) is closest to 0, in the above example, it would be x=8.</p>

<p>what college level computing question is this?</p>

<p>

Do your own homework? (Both a thought and a suggestion.)</p>

<p>

</p>

<p>I’d say this is a freshman CS class type question.</p>

<p>it’s C++…morfinx- my problem is setting up the algorithm that performs all those functions. I dont know where to after i put in for(x=-100, x<=100, x++)…</p>

<p>See my explaination above. I don’t know how else to explain it without actually writing the code for you.</p>