Question: C++ Program - I can not get values for min and max x_r and y_r, they output the same values for all 5 data records.

C++ Program - I can not get values for min and max x_r and y_r, they output the same values for all 5 data records.

#include

#include

#include

using namespace std;

int main()

{

int x_s, y_s, x_r;

int height = 0, beta, m, y_r = 0, maxX_R, minX_R, maxY_R, minY_R, datapoints;

double maxAlpha = 0, minAlpha = 100000;

double alpha (0);

ifstream fin;

fin.open("P:\\Private\\sound.txt");

if (fin.fail())

{

cout

}

else

{

fin >> datapoints;

for (int i = 1; i

{

fin >> x_s >> y_s >> height >> x_r;

while (y_r

{

for (m = -1000; m

{

if (m % 2 == 0)

{

beta = 0;

}

else

{

beta = (height - 2 * (y_r));

}

alpha = alpha + (1.0 / (pow((x_r - y_r), 2) + pow((m*height + y_r - y_s + beta), 2)));

if (alpha > maxAlpha)

{

maxAlpha = alpha;

maxX_R = x_r;

maxY_R = y_r;

}

if (alpha

{

minAlpha = alpha;

minX_R = x_r;

minY_R = y_r;

}

}

y_r++;

}

maxX_R = 0;

minX_R = 0;

minY_R = 0;

minX_R = 0;

cout

cout

cout

cout

}

system("pause");

return 0;

fin.close();

}

}

The Data: The first 5 represents the number of values.

5

5 3 10 8

1 2 10 10

5 3 10 8

5 3 10 8

5 9 10 4

C++ Program - I can not get values for min and max

Program Specification speaker) speaker at a position (xs, ys) and a receiver at (xr, yr) the sound intensity is proportional to: Sound intensity is a function of the distance from the receiver (your ear) and the source (the In a large room, the floor and ceiling can be approximated as perfect reflectors and for a Where h is the height of the room andd 0 when m is even h-2 yr when m is odd The summation represents an infinite integral. Adding up 'm' terms is the same as integrating. For a given speaker position, calculate the sound intensity as a function of height. represents m represents represents h represents the intensity of the sound number of terms in the integral, start at -1000 and go to 1000 strength of the source, related to the loudness" the height of the room What does your program needs to do? 1. Read the values for the Xs, Ys, h and xr from the input file sound.txt. The file is located on Canvas. For CMPSC 201, put the file in your P:\Private directory. Do not change the name of the input file or the directory location. If I cannot locate your file when I run your project your grade will reflect this yr is based on the height of the room, start at 0 and go to h at an increment of 1 foot Calculate the value of and for each data point Output the position of the point where the sound is the loudest and the quietest. (xrand yr where is at maximum and minimum) The sound intensity formula will be its own function. Pass the appropriate values to the function and it will return 2. 3. 4. 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!