New Function

Hello Hello!

can you explain me what this function does line by line please

Polyline drawFunction(const vector<double>& inValues,
double inScaleX, double inScaleY)
{
Polyline lLine;
for(int i = 0; i < inValues.size(); ++i) {
lLine += Point(i*inScaleX, inValues[i]*inScaleY);
}
return lLine;
}

thank you very much
Welcome here!

It is rewarding to use the source code tag from format notation.

Like this:
1
2
3
4
5
6
7
8
9
Polyline drawFunction(const vector<double>& inValues,
double inScaleX, double inScaleY)
{
  Polyline lLine;
  for(int i = 0; i < inValues.size(); ++i) {
    lLine += Point(i*inScaleX, inValues[i]*inScaleY);
  }
return lLine;
}


Ok, this is a function. Here is a description about functions:

http://www.codersource.net/c++_tutorial_functions.html

(But you can find more info of course.)

This drawFunction return a Polyline type value. You didn' write down what is it. It is possible that is a class.

drawFunction has some argument: const vector<double>& inValues is a container. You can store many object in this container. Some info about vector:

http://www.cplusplus.com/reference/stl/vector/
http://www.cplusplus.com/reference/stl/vector/push_back/

double inScaleX, double inScaleY arguments allow us that the points can be scaled with these values. (I think.)

4. line: iLine object is created.
5. line: It is a statement, called for. Some info:

http://www.hitmill.com/programming/cpp/forLoop.htm

Here all double type value are evaluated from vector (look at the size method of vector) and iLine object is added with some values. I don't know the Point class.

At least iLine object is returned in the 8.line.
The point of the class is pretty obvious. Is this your homework?
It is trying to draw a 3D sphere with lighting and shadows.
Last edited on
thank you every body it answers to my questions :)
Topic archived. No new replies allowed.