![]() |
|
C++ Project, need all the help i can get! - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: C++ Project, need all the help i can get! (/showthread.php?tid=70970) Pages:
1
2
|
C++ Project, need all the help i can get! - InvictHero - 2014-05-01 Hey guys, It's crunch time for college students, good luck to you all! If any of you have time to help, it would be greatly appreciated. Here's my project: 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 ®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 Here's where I need your help. I'm pretty good with functions and inputting the data from the file, I'm just terrible at arrays. After I calculate the intensity of light(Fc), how do I put these values into an array? Any help with this at all would be greatly appreciated. I need more help with the array part of it, but I could use tips throughout the whole thing. Thank you! C++ Project, need all the help i can get! - Kabanaw - 2014-05-01 So first thing, you need to initialize the array. Fortunately, this is pretty simple, as you already know the size of both dimensions. Code: float[94][50] court;Should probably do it unless I'm mixing up c++ syntax. The next step is populating the array with values - which should be pretty simple to do once the data is loaded in. C++ Project, need all the help i can get! - InvictHero - 2014-05-01 Okay thanks! I have a question on reading in the data from the file as you can see from above, Option A and Option B both have two floodlights with given measurements. But Option C has three floodlights all with random values. how should I read the measurements in? Right now i have Code: lights >> option >> num_floodlights >> given_or_random >> measurement_1 >> measurement_2 >> measurement_3 >> measurement_4 >> power >> height;But as soon as it loops around for the last option, C, my data reading in will get messed up.. could i do this?: Code: while(option !=C) then do all the calculations and stuff in there then do a separate while loop for option C, like: Code: while(option=C) C++ Project, need all the help i can get! - Kabanaw - 2014-05-01 What would you do if you're given a file where A or B are random, or C is given? The important factor for deciding which values need to be loaded is whether the values are given or random. For that matter, what does your code do if you add another light to A or B? C++ Project, need all the help i can get! - InvictHero - 2014-05-01 I honestly have no idea…I'm at a loss right now. Could you look at all the code I have right now and tell me where I went wrong with the reading in of data? C++ Project, need all the help i can get! - Kabanaw - 2014-05-01 What's the text parser you're using? I've never seen that syntax - I could help more if I knew what exactly I was looking at. C++ Project, need all the help i can get! - InvictHero - 2014-05-01 oh oops, sorry! I'm using Microsoft Visual Studio 2012. C++ Project, need all the help i can get! - Kabanaw - 2014-05-01 So take things one at a time: First, differentiating between given and random. You know that up until that point, all the data is going to be the same. That line determines what will follow, though. If it's given, then you'll have to do one thing; if it's random, another. C++ Project, need all the help i can get! - InvictHero - 2014-05-01 hmmm, okay. I kind of have an idea of what to do, but we'll see if I can get it to work thank you for all the help
C++ Project, need all the help i can get! - Locked - 2014-05-01 Are you allowed to use the standard library? i.e. std::array or std::vector C++ Project, need all the help i can get! - Dudewitbow - 2014-05-01 are you allowed to write your own header files for class definitions? or are you just working with an array of like structs or something where the struct would be: struct LightingMode { char option; int floodlightCount; char givenOrRandom; double floodlightDistance[floodlightCount]; //its been awhile since i worked with arrays that aren't in a class without a constructor, not sure if syntax is legal int/double floodlightPower; double floodlightHeight[floodlightCount]; } //calculation functions goes here as for putting the values in the array, after calculating the value of light in a 2d cell, store the value in that arrays cell using a double for loop. for example double courtCells[cellHeight][cellWidth]; LightingMode first; for(int i = 0; i < cellHeight; i++) { for(int j = 0; j < cellWidth; j++) { courtCells[i][j] = Function1(First ,Function2(first)); } } where function 1 is the light level(that returns a double) whose parameter is a LightMode struct and an int value(distance), which is calculated by passing the LightMode struct into Funtion2(the distance calculating function whose parameter is a struct and returns an int) at least i think, not sure how far in your class youve gotten into in C++ using a while(fin.good()) loop or similar loop, I would input the data into the struct directly with fin(or whatever you decide to name it to the point where you get to fin >> givenOrRandom; where there's one if/else statement where it checks the char where its either given or random. so you must do one or the other if(givenOrRandom == C) do something else do the other thing I would personally have done this in a class header file(given my current knowlege, as a constructor could easily just do all the work for you) C++ Project, need all the help i can get! - Kabanaw - 2014-05-01 ^^^ I basically agree with everything in this post. If you've never done anything with header files, don't worry about it - you should be able to do everything you need to without involving another layer of complication. C++ Project, need all the help i can get! - Locked - 2014-05-01 There is no reason to make a class for this. These are mathematical pure functions and they don't require classes. C++ Project, need all the help i can get! - InvictHero - 2014-05-01 [MENTION=7833]Dudewitbow[/MENTION]; I don't believe were allowed to use and write our own header files, seeing that we've never learned about that! But this is a huuuuuge help, thank you so very much kind sir! this will shave off a few hours of my all nighter C++ Project, need all the help i can get! - InvictHero - 2014-05-01 okay so this is what I have so far, still need some help unfortunately comments are also included! Those big starred boxes are function comment blocks, don't know if thats a universal thing or just something my teacher likes to do Code: #include <iostream>C++ Project, need all the help i can get! - Dudewitbow - 2014-05-02 if you need further help, just ask a question(probably don't want to compile to see for errors). if its an error, post it. if you dont understand how to do something, post it as well. C++ Project, need all the help i can get! - InvictHero - 2014-05-02 Dudewitbow Wrote:if you need further help, just ask a question(probably don't want to compile to see for errors). if its an error, post it. if you dont understand how to do something, post it as well. I guess I need help with my distance function.. as you can see from my code, it's only calculating the distance for the first floodlight. given measurement_1(which is 25 in the data file) and measurement_2(which is 23.5 in the data file). In the data file, the last piece of data, according to the project handout, is "Distance (feet) the lights are mounted above the positions". So I'm confused as to how I code my distance(D) function. C++ Project, need all the help i can get! - Dudewitbow - 2014-05-02 InvictHero Wrote:I guess I need help with my distance function.. as you can see from my code, it's only calculating the distance for the first floodlight. given measurement_1(which is 25 in the data file) and measurement_2(which is 23.5 in the data file). In the data file, the last piece of data, according to the project handout, is "Distance (feet) the lights are mounted above the positions". So I'm confused as to how I code my distance(D) function. after you declare the # of floodlights from the second digit, you have to have the floodlight data be an array of doubles(even if there is 1 floodlight e.g //double floodlightPower[numFloodlight] ![]() so when you pass in the array, your calculation array should have the ability in a forloop manner to calculate both distances by using a for loop inside of the distance function. if numFloodlight is 1, then the loop passes once. if numFloodlight is 2, then it should pass twice. i'll leave it to you to figure out how the array will find out how many times it has to loop. C++ Project, need all the help i can get! - InvictHero - 2014-05-02 Dudewitbow Wrote:after you declare the # of floodlights from the second digit, you have to have the floodlight data be an array of doubles(even if there is 1 floodlight e.g //double floodlightPower[numFloodlight] The only problem with this is that in the floodlightPower array, numFloodlight has to be a constant value :/ so idk what to do.. C++ Project, need all the help i can get! - Dudewitbow - 2014-05-02 totally slipped my mind. do you have access to any of the other data structures? (like locked mentioned, abilty to use vectors or deques?) |