You are not logged in.
yeah, but we also know that these are parabollas! thats a big deal because we can exactly determine the shape. Our only assumption is that the slope function be continuous, no sharp turns at the joint. Since this is intended to be a smooth track and since it passes through all the points listed, i'd say this assumption is almost certainly correct and if not, only off by a very small margin.
simple, j(x) = f(x-1), this means that whatever you input for j, the value of j(x) is equal to the value of inputing x-1 into f.
if you substitute, you will find that j(x) = f(x-1) = (x-1) + 1 = x.
whats confusing about these is that x is just a generic value that represents the input to the function. so when we say
f(x) = x + 1 and
j(x) = f(x-1)
the x's in these two function definitions have nothing to do with eachother.
I wasn't worried about the answer but simply developing a way to find the approximate cost of the roller coaster track.
if you are expected to know derivatives, then you can find the equations of the parabollas. Once you know that, you can select a handful of points on the parabolla, connect the points and use pythagoras to find the lengths. The next best thing is pretty much just to solve it exactly.
I agree thats much cleaner and understandable. Shouldn't it be this though?
(int *) *matrix = new int* [rows]; // array of pointers
for (i = 0; i < rows; i++) {
matrix[i] = new int[cols]; // defrerence the pointer and set it to point to the new array
}
also in the first line, did you add those parens in '(int *)' just for clarity or for another reason.
This works pretty nicely but if you wanted to create arrays of higher dimension, it would start to get pretty ugly, wouldn't you say?
i imagine they are showing you this only as a prep for how its done in calculus, namely, sum the distances from A to B, B to C and C to D, thats a simple answer. Judging from the picture, one might argue that if we mark M as the intersection of the lines passing through A-B and C-D respectively, then i think we'd all agree that A to B to M to C to D is a better approximation of the distance.
I'm not sure if this is a homework problem, or if you actually want to build a roller coaster
but i think we can actually solve this exactly using fairly simple calculus.
suppose the origin is centered at the bottom left of that diagram. Consider the left most parabolla, it is of the form ax^2 + bx + c = y; note we can find c = 30 just from the origin, for the remaining two variables we have a slope value at A, 2ax + b = tan(10 degrees) at x = 0 thus b = tan(10 deg). a sample point at B then allows us to determine the value of a = -1/8 tan(11) - 15/32. thus we can find the formula for that parabolla and by integrating with the help of obnoxious trig substitutions we can find the length of the portion from 0 to 8.
now we can figure out the rest of the length if we are willing to make one assumption and that is that the curve is differentiable, a smooth curve. if it is then we know the slope of the next parabolla at the starting point, (at B) and we also have two sample points. Continuing in this manner we should be able to find the exact length.
so we could figure it out. The question is, how bad do you need to know?
sorry i could have written that better, int array[3][2] does compile, i was just using that to show what the original array was before trying to create a pointer to it.
So you are casting the array as a pointer to a pointer, eh..hmm
well i just tried this:
int array[5][4];
array[1][1] = 6;
int ** matrix = (int**) array; // casting to an int pointer pointer
std::cout << " matrix[1][1]: " << matrix[1][1] << "\n"; // should print 6output: matrix[1][1]: 4214504
thats not good. I know your example was on the freestore but it should work here too, right?
and I'm using Borland C++ Builder X, released in 2003 it seems.
(edit) and how do you pass multi-d arrays as arguments to functions? do you just cast them? personally i don't mind doing that but its not exactly elegant.
I'm having some trouble figuring out how to make pointers to multidimensional arays. It was not explained in my book and my googling only produced a host of different solutions, some of which don't even work.
Anyway here's the problem:
here we create a pointer to a regular array
int * list = new int[10];
we merely create a pointer to the element type and assign the array to it. Easy and clean.
however,
int* list = new int[2][5];
this will not compile. neither will
int array[3][2];
int * list = array[2][0]; // this, or
int * list = array[0]; // this, or
list * list = array; // this
i saw someone claiming you needed pointers to pointers
int** list = new int[3][2]; // wouldn't compile
in the end I found the following works:
int (* list)[2] = array;
you can now use 'list' just as you would 'array', but the issue is, this oddly syntaxed declaration (which requires the parens) creates some sort of array of length 2, and this length must be determinable at compile time. This means you couldn't, for instance, dynamically set the size of the array at run time. to do that we need to put these on the freestore. But how do we do that?
my best guess was:
int (*) * list = new int(*)[size];
of course, THAT doesn't compile. so how on earth do we do this?
I wish i could find a good explanation of how C++ deals with multidimensional arrays internally and how the pointers work with them.
didn't my pointer point to a const Cat?
Cat friskey;
const Cat * someCat = myFunction(&friskey); // someCat is a pointer to a constant cat
someCat->meow(); // yes meow is a constant function
are you saying its bad to pass in '&friskey' as a parameter because its not a pointer to a constant cat? my book explicitly states this ability as not only legal but useful. If your compiler doesn't allow this, well...thats WEIRD!
um... thats not even the same problem you asked, Tony! ![]()
I knew it!
So would you agree then, Ricky, that declaring the return value to be a constant pointer is pointless? (sorry, bad pun)
Luca, again I'm inclined to point out that this is perfectly legal:
const int x = 5;
int y = x; // y is not constant
I think the purpose of declaring a pointer constant in a parameter list is to ensure that the parameter does not change within the body of the function. Moreover, when we declare the parameter to be a pointer to a constant object, we don' do this to ensure only a constant object is passed in, we merely do it to ensure no changes are made to the actual object within the body of the function. It doesn't care if the object passed in is constant or not, it treats it as constant within the function.
are you sure? try the following:
definition of my function:
const Cat* const myFunction(const Cat* const otherCat)
{
return otherCat;
}
now try this:
Cat friskey;
const Cat * someCat = myFunction(&friskey); // not a constant pointer!
someCat->meow();
that compiled and ran without so much as a warning from my compiler. If I don't declare the pointer someCat to be a pointer to a constant Cat it won't compile, but thats all.
I don't see why the compiler would care. So what if someCat can point to something else later?
this brings me back to my hazy understanding of how function returns work. As far as I understand, when you call a function, it creates a variable of its exact return type in place of where it was called and when the function returns, the value is copied from whatever is returned. So in a certain sense, its like saying:
const Cat* const returnValue = myFunction(); // return value is copied back into the calling function
const Cat* otherPointer = returnValue;
and why should this be bad? (note, this also compiles for me) all we said about returnValue is that its a pointer, it has an adress and that should not hold any other adress. I don't think that says anything we assign this to must not hold any other adress either.
Likewise we can say const int x = 5;
int y = x;
y is not constant, but who cares?
But do tell me if that compiles for you, Id like to know.
hey here's another question. I was reviewing my C++ book and i found this function declaration
const Cat * const function1(const Cat* const theCat);
does this declaration make ANY sense at all? okay, the fact that the parameter is a constant pointer to a constant cat is fine, the cat won't be changed, and the pointer will not be changed within the function. Its also fine that the pointer returns a pointer to a constant cat so you can't do something like function1(&myCat)->setAge(5); but the fact that it returns a constant pointer (that can't be redirected) isn't that useless? its not like we're going to say
function1(&myCat) = &otherCat;
that wouldn't work even if it was NOT constant, right?
does that make any sense ever?
what do you mean because of symmetry? i fail to see how x + y + z = 2 ⇒ x = y = z
i'm missing something here
aye, but that seems like... i'm not sure.
could we possibly prove that it is the exact answer?
I guess we can't be sure unless we can find an expression for the tangent of some integer that fits on one piece of paper.
Arnold Schwarzenegger indeed!
how'd you know?
1. Man. Alive
2. No he does not hail from the A continents
3. no he is not a scientist or a mathematician
4. yes he associated with movies or music
5. yes he is an actor
6. no he is not actively performing in movies or music
8. yes his first name, written in English, begins with a vowel
7. Was he a Hollywood actor when he was performing?
what exactly does this mean? did he ever work in hollywood? live there? make a movie there? what defines a Hollywood actor?
1. Man. Alive
2. No he does not hail from the A continents
3. no he is not a scientist or a mathematician
4. yes he associated with movies or music
5. yes he is an actor
6. no he is not actively performing in movies or music (at least as far as googling has shown)
sorry for being slow to respond:
1. Man. Alive
2. No he does not hail from the A continents
3. no he is not a scientist or a mathematician
4. yes he associated with movies or music
3. no he is not a scientist or mathematician
but for 2, by 'hails from' does that mean 'born in' or 'now lives in'?
I'd say so. I assume that would mean the question doesn't count and we ask a new one?
I guess i'll go next.
1. Man. Alive
happy new year, George Y and all!
I am the Gibbon (a type of monkey it appears)
Solitary, Modest, Inquisitive, Spontaneous, and a leader ![]()
ahhh... i probably never would have guessed that.
Ganesh: I don't know, really. I never thought of chess as a sport. Besides if siva.eas had said 'yes' i never would have thought that could include chess players.
Oh well. Who's next?
oh what the heck, lets end this
20. Is it Vanna White?
man, i'm REALLY curious now...
19. is she known for her accomplishments? (as opposed to just who she is)
curses! I was sure that was it!
16. is it...someone from this website?