Hey guys,
Brand new to the forums, thanks for hearing me out on my troubles in advance! Lets get right into it..
Program Description: Write a program that calculates the intensity of light onto a NBA basketball court. A standard NBA basketball court is 94 feet long and 50 feet wide. We will assume that every square foot is represented by a cell in a two-dimensional array (or matrix). Given certain criteria that you read in from a data file, you will need to calculate the intensity of light at each square foot of the court.
Your program must have the following 4 functions:
A. Calculate the intensity of light (see formulas below)
B. Calculate the distance from the light to the floor
C. Random number generator
D. Print out the results
Formulas: Fc=Cp/D^2 D=sqrt(b^2+h^2)
Where: Fc = is the level of light the candle (floodlight) produces
D = the distance the lamp is from the surface
Cp = the candle power of the lamp (in watts)
• Use the second formula to calculate the distance (D) from the light to each position (cell) on the basketball court.
Here's the data file and what each number/character gives:
Data file:
A
2
G
25 23.5
25 70.5
400
20
B
2
G
25 23.5
25 70.5
1000
30
C
3
R
400
35
What each line means:
o Option letter (to be echoed back out)
o Number of floodlights installed
o Character to determine if the measurements are (G)iven or (R)andom. (If random then you need to randomly produce the position of that number of floodlights.)
o For each given floodlight, the number of feet across the court (in the 50’ direction) then the number of feet (in the 94’ direction)
o Power of the floodlights in watts
o Distance (feet) the lights are mounted above the positions
Now here is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <fstream> //required for file streaming
#include <cctype>
#include <ctime>
using namespace std;
/************************************
Function Name: Rand_Float
This function generates a random value
between a and b.
Passed: a = min value
b = max value
Returned: random double value
************************************/
double Rand_Float(double a, double b)
{
return ((double)rand()/RAND_MAX)*(b-a) + a;
}
/*************************************
Function Name: Distance
This function calculates the distance from
the light to the floor
Passed: measurement_1 = base
measurement_2 = height
Returned: distance
**************************************/
double Distance(double measurement_1, double measurement_2)
{
double distance;
distance = sqrt(measurement_1*measurement_1+measurement_2*measurement_2);
return distance;
}
double Intensity(int power, double Distance)
{
double intensity;
intensity = power/(Distance*Distance);
return intensity;
}
int main()
{
//Declare objects
srand(time(0));
char option;
int num_floodlights;
char given_random;
double measurement_1, measurement_2, measurement_3, measurement_4;
double distance;
double intensity;
int power;
int height;
int loop(0);
const double a(70.5);
const double b(1);
const int NROWS(94);
const int NCOLS(50);
double court[NROWS][NCOLS];
int i, j;
//Create Objects
ifstream lights;
ofstream lightoption;
//Open Files
lights.open("C:\\Users\\Jordan\\Documents\\lights.txt");
lightoption.open("C:\\Users\\Jordan\\Documents\\lightoption.txt");
//Check File
if(lights.fail())
{
cout << "Error in opening file!" << endl;
system("pause");
return 0;
}
//Read in values
lights >> option >> num_floodlights >> given_random >> measurement_1 >> measurement_2 >> measurement_3 >> measurement_4 >> power >> height;
//While loop that will run through the first two options of light placement
while(option != 'C')
{
for (i=0;i<NROWS;i++)
{
for (j=0;j<NCOLS;j++)
{
//Call the functions
distance = Distance(measurement_1, measurement_2);
intensity = Intensity(power, distance);
court[i][j]=intensity;
cout << setprecision(2) << "\t" << court[i][j];
}
}
//Read in next option
lights >> option >> num_floodlights >> given_random >> measurement_1 >> measurement_2 >> measurement_3 >> measurement_4 >> power >> height;
}
system("pause");
return 0;
}
| |
I'm having some trouble with what seems to be my distance. My output for Options A and B are the same in every cell. something like 0.34 for the Option A and 0.85 for Option B. Also, I need help with reading in the data for Option C..as you can see, I still have a lot of work ahead of me and this is due at noon Friday (tomorrow).