Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C++ Project, need all the help i can get!
#21
Dudewitbow Wrote:totally slipped my mind. do you have access to any of the other data structures? (like locked mentioned, abilty to use vectors or deques?)

nope :S, didn't learn about any of that stuff so I wouldn't know how to use it Sad We're supposed to be able to do it with everything we learned so far in the course, mainly using two-dimensional arrays and functions for this last project.
Reply
#22
have you tried just writing another fuction that has 4 parameters with the same name?(so 2 floodlights create 4 parameters) so that when a function recieves 4 parameters, it knows when to use the second function and not the first


e.g

Function1(parameter, parameter)
{
//do stuff here
}

Function1(parameter, parameter, parameter, parameter)
{
//do stuff here, longer than above
}


is legal syntax for a function.


ALTERNATIVELY(probably youll end up using this way)

use an if statement that checks to see if measurement 3 and 4 are NOT a sentinel value(e.g initialize the data to a sentinel value like -1)
e.g

if(measure3 != -1) distance(measure3, measure4);// if measure3 is NOT the sentinel value, do the calculation of distance for the other 2 values

of course you may need another variable to hold the second distance value to be used.
Reply
#23
Dudewitbow Wrote:have you tried just writing another fuction that has 4 parameters with the same name?(so 2 floodlights create 4 parameters) so that when a function recieves 4 parameters, it knows when to use the second function and not the first


e.g

Function1(parameter, parameter)
{
//do stuff here
}

Function1(parameter, parameter, parameter, parameter)
{
//do stuff here, longer than above
}


is legal syntax for a function.


ALTERNATIVELY(probably youll end up using this way)

use an if statement that checks to see if measurement 3 and 4 are NOT a sentinel value(e.g initialize the data to a sentinel value like -1)
e.g

if(measure3 != -1) distance(measure3, measure4);// if measure3 is NOT the sentinel value, do the calculation of distance for the other 2 values

of course you may need another variable to hold the second distance value to be used.

hm, i do like your first idea a lot! but, i think i can totally throw out the function with only two parameters since option's A and B both have 4 parameters(2 measurements for each floodlight). so ill have:


double Distance(double measurement_1, double measurement_2, double measurement_3, double_measurement_4)
{
//now what goes in here since ill have two distances? 1 for each floodlight.. before when I had only two parameters it was just
Code:
double distance;
    distance = sqrt(measurement_1*measurement_1+measurement_2*measurement_2);
    return distance;
}
Reply
#24
the problem with the first idea is that probably with your current knowlege, you wouldnt be able to pass 2 values back. methods would include passing a parameter by reference, the other is using a data structure(neither of which you cant use atm I would think). the latter idea with an if check is more at your level. just remember to reset the value of distance after you are done using it.
Reply
#25
we've done call-by-reference, if that has anything to do with that…haha. but okay, I'll try working on the second option! Thank you so much for all the help! I greatly appreciate it Glitter

oh, one last question. I know you've already mentioned how to read in the data, only reading it to the givenorrandom part then having an if/else statement, but could you elaborate on this a bit more or draw it out for me? I'm having trouble grasping this. Like, after the if/else statement, how do i read in the data after the givenorrandom?
Reply
#26
InvictHero Wrote:we've done call-by-reference, if that has anything to do with that…haha. but okay, I'll try working on the second option! Thank you so much for all the help! I greatly appreciate it Glitter

oh, one last question. I know you've already mentioned how to read in the data, only reading it to the givenorrandom part then having an if/else statement, but could you elaborate on this a bit more or draw it out for me? I'm having trouble grasping this. Like, after the if/else statement, how do i read in the data after the givenorrandom?

basically what i meant by that is:

heres the 2nd part of the data you have on OP:

B
2
G
25 23.5
25 70.5
1000
30

C
3
R
400
35

the first loop works as normal. but I would recommend when inputing to have an if statement checking if the givenorrandom is one or the other. so if its given, read in the values for the numbers, else, randomize the values. what you dont want to do is input the wrong number for the wrong variable(e.g after R is inputed for givenorrandom, you dont want 400 to be read as a measurement1, as its supposed to be the power(?))
Reply
#27
Okay perfect! that cleared everything up then, thank you!
Reply
#28
So is does your assignment say to just work with the given input, or is that just example input and you need to have your code work for anything that follows that format? What you have right now will probably work for this specific input, but writing to an example is generally the wrong thing so I would expect you need to write this abstract enough to work with any correct input.

The best way to store the light's locations would be in their own array, size variable depending on the number of flood lights you're told exist. So you can make a 2d array by using

double** floodlights = new double*[num_floodlights];
for (int i = 0; i < num_floodlights; i++)
{
floodlights[i] = new double[2];
floodlights[i][0] = ~~measurementx~~
floodlights[i][1] = ~~measurementy~~
}

Where the stuff in tildes is data from the file. This lets someone build a system with two lights, five lights, or no lights, and it won't break.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)