This program uses graphics and requires the DirectX "Graphics Machine".
There are two REQUIRED functions for you to write as part of this assignment: Distance and GetNumber.
1. Gather the Data
Prompt the user for four sets of x,y coordinates from (0 to 639, 0 to 479). These will be locations for four antennas. Also ask for the range of each antenna, from 5 to 200. This part of the program should look like this:
Enter the x coordinate for antenna 1 (0 to 639): 60
Enter the y coordinate for antenna 1 (0 to 479): 340
Enter the range for antenna 1 (5 to 200): 50
Enter the x coordinate for antenna 2 (0 to 639): etc...
Write a function called GetNumber that will prompt for a number and verify that it is between two values before returning the result. It should be used in your program similar to the following sample code:
cout << "Enter the x coordinate for antenna 1 (0 to 639): ";
antenna1x = GetNumber(0,639);
cout << "Enter the y coordinate for antenna 1 (0 to 479): ";
antenna1y = GetNumber(0,479);
cout << "Enter the range for antenna 1 (5 to 200): ";
range1 = GetNumber(5,200);
2. Draw the Map
The clear the screen (use clrscr()), and set up a nested loop to look at each point on the screen:
for (y = 0; y <= 479; y++)
{
for (x = 0; x <= 639; x++)
{
// check each point here
}
}
For each point, check the distance to each of the four antennas. If the distance to an antenna is within the range of that antenna, count it. Determine how many antennas are in range of the point. If it is in range of only one antenna, set the point using the color blue. If it is in the range of exactly two antennas, set the point green. If it is in range of three antennas, set it red. If in the range of four, set it yellow. If it is not in the range of any of the antennas, leave the point black. (You may choose any distinguishable color set.)
Write a function called Distance that is sent four values and it returns the distance as the answer. It should be used similar to the following line:
d = Distance(x1,y1,x2,y2);
The distance between two points is the square root of the the difference of the x's squared plus the difference of the y's squared. To compute the distance, you'll have to include the library math.h, and use its sqrt() function. This function expects to be sent a value of type double, and returns a double as the answer. You may have to typecast your computation before getting the square root. It would look something like this:
answer = sqrt(double( ));
3. Print a Summary on the Screen
As you go, keep track of how many points you set in each color. When you've completed scanning all the points, print to the screen the percentage of points that were reached by only one antenna, the percentage reached by exactly two, the percentage reached by exactly three, the percentage reached by exactly four, and the percentage reached by none.
I cant really seem to get what the program is asking for...i have a good idea about the first part of the program, but I still seem lost on the second part with the distance...If anyone can help me that would be great..thank you so much
--switch
There are two REQUIRED functions for you to write as part of this assignment: Distance and GetNumber.
1. Gather the Data
Prompt the user for four sets of x,y coordinates from (0 to 639, 0 to 479). These will be locations for four antennas. Also ask for the range of each antenna, from 5 to 200. This part of the program should look like this:
Enter the x coordinate for antenna 1 (0 to 639): 60
Enter the y coordinate for antenna 1 (0 to 479): 340
Enter the range for antenna 1 (5 to 200): 50
Enter the x coordinate for antenna 2 (0 to 639): etc...
Write a function called GetNumber that will prompt for a number and verify that it is between two values before returning the result. It should be used in your program similar to the following sample code:
cout << "Enter the x coordinate for antenna 1 (0 to 639): ";
antenna1x = GetNumber(0,639);
cout << "Enter the y coordinate for antenna 1 (0 to 479): ";
antenna1y = GetNumber(0,479);
cout << "Enter the range for antenna 1 (5 to 200): ";
range1 = GetNumber(5,200);
2. Draw the Map
The clear the screen (use clrscr()), and set up a nested loop to look at each point on the screen:
for (y = 0; y <= 479; y++)
{
for (x = 0; x <= 639; x++)
{
// check each point here
}
}
For each point, check the distance to each of the four antennas. If the distance to an antenna is within the range of that antenna, count it. Determine how many antennas are in range of the point. If it is in range of only one antenna, set the point using the color blue. If it is in the range of exactly two antennas, set the point green. If it is in range of three antennas, set it red. If in the range of four, set it yellow. If it is not in the range of any of the antennas, leave the point black. (You may choose any distinguishable color set.)
Write a function called Distance that is sent four values and it returns the distance as the answer. It should be used similar to the following line:
d = Distance(x1,y1,x2,y2);
The distance between two points is the square root of the the difference of the x's squared plus the difference of the y's squared. To compute the distance, you'll have to include the library math.h, and use its sqrt() function. This function expects to be sent a value of type double, and returns a double as the answer. You may have to typecast your computation before getting the square root. It would look something like this:
answer = sqrt(double( ));
3. Print a Summary on the Screen
As you go, keep track of how many points you set in each color. When you've completed scanning all the points, print to the screen the percentage of points that were reached by only one antenna, the percentage reached by exactly two, the percentage reached by exactly three, the percentage reached by exactly four, and the percentage reached by none.
I cant really seem to get what the program is asking for...i have a good idea about the first part of the program, but I still seem lost on the second part with the distance...If anyone can help me that would be great..thank you so much
--switch