Hi im new to C++ and im trying to call a function in to a for loop. -
- void DrawLine(int x1, int y1, int x2, int y2, unsigned int color)
-
{
-
-
int dx, dy; // dy / dx is the slope
-
int x, y; // loop and point variables
-
-
// calculate changes in y and x between the points
-
dy = y2 - y1;
-
dx = x2 - x1;
-
-
if (Abs(dy) > Abs(dx)) {
-
// since there is a greater change in y than x we must
-
// loop in y, calculate x and draw
-
for (y=y1; y != y2; y += Sign(dy)) {
-
x = x1 + (y - y1) * dx / dy;
-
PGraphics->AddPoint(x, y, color);
-
}
-
}
-
else {
-
// since there is a greater (or equal) change in x than y we must
-
// loop in x, calculate y and draw
-
for (x=x1; x != x2; x += Sign(dx)) {
-
y = y1 + (x - x1) * dy / dx;
-
PGraphics->AddPoint(x, y, color);
-
}
-
}
-
-
// draw the last pixel
-
PGraphics->AddPoint(x2, y2, color);
-
-
// draw the points
-
PGraphics->Draw();
-
}
-
-
-
void DrawStuff() {
-
COLORREF green = RGB(0, 255, 0); // green color to draw with
-
COLORREF purple = RGB(255, 0, 255); // purple color to draw with
-
-
char str[32]; // string to store user input
-
int h, k; // parabola vertex
-
double a; // parabola constant - might be a decimal
-
int x, y; // loop and point variables
-
int xPrev, yPrev; // previous point for drawng line segments
-
int ymin, ymax; // limits for y loop
-
RECT rect; // rectangle for the output window
-
-
// get the user input from the edit boxes and
-
// convert string input to integer
-
GetDlgItemText(HDialog, IDC_EDIT_VERTEXX, str, 32);
-
h = atoi(str);
-
GetDlgItemText(HDialog, IDC_EDIT_VERTEXY, str, 32);
-
k = atoi(str);
-
GetDlgItemText(HDialog, IDC_EDIT_CONSTA, str, 32);
-
a = atof(str); // use atof to allow user to enter a decimal
-
-
// get the rect for this window
-
GetClientRect(HOutput, &rect);
-
-
// use the rectangle info to set up y loop limits
-
ymin = -(rect.bottom - rect.top) / 2;
-
ymax = (rect.bottom - rect.top) / 2;
-
-
// clear the scene and add an axis
-
PGraphics->ClearScene(RGB(0, 0, 0));
-
PGraphics->AddAxis(RGB(150, 150, 150), 10);
-
-
yPrev = ymin;
-
xPrev = (int)( a * (yPrev-k) * (yPrev-k) ) + h;
-
-
// loop in y, calculate x and draw
-
for (y = ymin; y <= ymax; y++) {
-
x = (int)( a * (y-k) * (y-k) ) + h;
-
PGraphics->AddPoint(x, y, green);
-
}
-
-
// draw the points
-
PGraphics->Draw();
-
}
-
What im trying to do is take the DrawLine function (that I put in bold) and have it referenced right before the for loop in the DrawStuff (that i put in bold) This way the DrawStuff will know to use DrawLine to draw more points in a line.
Thanks in advance!
4 2304
The only wat that DrawStuff can know to use DrawLine is for you to a) call Drawline inside DrawStuff or b) have a function pointer argument in DrawStuff that contains the adress of the correct DrawLine function. - void DrawStuff()
-
{
-
DrawLine(etc...);
-
for (etc...
-
{
-
///or DrawLine(etc...);
-
}
-
}
Do you mean to spell ymin like ymi.n
Hi weaknessforcats,
Appreciate you helping me out with this I was wondering if you could give me a little more detail if your example or possibly give me a couple websites with some examples I could look at.
Thanks for the help!
Whodgson,
its supposed to be ymin. :) It refers to the min value of y
Hi weaknessforcats,
Appreciate you helping me out with this I was wondering if you could give me a little more detail if your example or possibly give me a couple websites with some examples I could look at.
It may be you are no clear on how a function call works.
Your program excutes statements in sequence. A B C D. If you have steps that are used in several places, you code A XXX B XXX C XXX D XXX. Those XXX instrcutions are repeated as many times a needed.
A function call is a way of coding XXX only once. These instructions are put together using a name an argument list and a pair of braces: - void MyFunction()
-
{
-
XXX
-
-
}
The code now looks like:
A MyFunction() B MyFunction() C MyFunction() D MyFunction().
The last thing is when you use a variable as an argument to a function, the compiler makes a copy of it. The copy is the argument variable of the function being called. This is done to protect the original variable.
You can find all sorts of information about this from just about any book on C.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Charles Soto |
last post by:
I've got a main loop script that calls two other scripts that do no
user interaction. All they do is send a couple of mysql update
statements. Then they use header() to call the main loop again. ...
|
by: TTroy |
last post by:
Hi,
I'm just wondering why people/books/experts say "the function returns a
pointer to.." or "we have to send scanf a pointer to.." instead of "the
function returns the address of.." or "we have...
|
by: Kevin Schultz |
last post by:
Hello all. I am interfacing my computer to the outside world for an
experiment and we would like to know how much time the calling function
takes. The specs say this should happen on the order of a...
|
by: Jack Addington |
last post by:
I am working on app that currently all resides on the same machine but plan
to pull the database off and try to move all the datafunctionality to a
remote machine. I have a data function that is...
|
by: Bern McCarty |
last post by:
I have run an experiment to try to learn some things about floating point
performance in managed C++. I am using Visual Studio
2003. I was hoping to get a feel for whether or not it would make...
|
by: Chris Morse |
last post by:
WARNING: Verbosity: skip to the very bottom paragraph for succinct
version of my question.)
Hi-
I can't seem to find an answer to this. I am playing around with a
variation of the ".NET...
|
by: Paul Hasell |
last post by:
Hi,
I'm trying to invoke a web method asynchronously but just can't seem to get
it to tell me when it has finished! Below is the code I am (currently) using:
private void...
|
by: Riko Wichmann |
last post by:
hi everyone,
I'm googeling since some time, but can't find an answer - maybe because
the answer is 'No!'.
Can I call a function in python inline, so that the python byte compiler
does...
|
by: Eric |
last post by:
When I run my script it gives error on the following line:
strEmail = Right(strEmail, (Len(strEmail) - 1))
I enclose my code and the sample text file too
Thanks,...
|
by: crater |
last post by:
Today I ran into a problem that had me completely baffled.
A function that I have just written, processes data in any one of 4
different data grids.
Within a for() loop I need to call another...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |