how do I write this Void function I am lost
trying to be able to call it in my mian but can't and not sure how to write it so I can call it
Well, some depends on the rest of the program... but... a void... hmm... So no returns. it is just drawing something at the point passed to it?
What language you using?
void drawship (double x, double y) << Declared variables... but never used. Huh?
C++
instructions say top return the void but not sure
For this assignment you will write a program that does some simple animation. A space ship will initially be drawn on the left side of the window, and then appear to *slide* to the right at a constant speed. Once the ship moves outside of the window, you will print the message "goodbye!" to the middle of the window. To draw the ship, you are required to use a function. The function will be passed a Point that represents the bottom center of the ship. The other points used to draw the lines for your ship, should be relative to this point's position. The function should return void. When the ship moves from left to right, it should do so slowly enough that it can be seen. A simple while loop that moves the ship EVERY iteration would move the ship across the screen so fast that the movement wouldn't be visiable. So, you'll need to figure out how to manage the speed of the animation inside the loop. Also the amount the ship moves each time it is redrawn needs to be picked carefully, a large value will result in *jerky/flickery* motion. You are not allowed to simply move the ship a very small amount each time to get the ship to move slowly. For example, moving the ship 0.0000001 units each loop iteration. If you do this, you will get 0 out of 30 points for the rubric item that requires you to make the movement smooth.
this is my assignment
previous assignemnt had to do with drawing my ship an dmoving it others ways.. but not using fuction. we just covered function so this assignment we have to use them
OK, so the passed values are where the ship's bottom center is now.
OK, so you plan to use what you have done so far, the drawing parts, and change it to a function? A void returns nothing, so if you need to change the values they must be passed by reference. But if it is just goint to use those values, how you passed them is fine.
correct
Are you using a particular library for the drawing?
using my ship i have used in past projects.. it s build up project .
yeah a graphics libary provided by the professor
library*
we are using visual studio 2010 also to write this code
OK, so I am going to assume the function calls to draw are valid because they call the library and you have declared that in the main. So, what is giving you trouble?
when I call it I it doesn't draw the ship .not even sure if I am calling it write heres my whole code of what I have.
I try to cwin << drawship ; but it doesn't not work to call function
or am I doing it wrong?
is there another way to call it?
also whats in my main so far is my landscape and the good bye message
Did you call it with passed values?
what do you mean past values?
passing the variables. You defined it with variables, they must be passed when you call it.
Point l(-8,0); is a call to a function in the library. That call is passing the values of -8 and 0. In fact, it may be doing more because of what it is, but that is another issue. You arte defining your own function. it must have a structure and have data passed to it properly.
so I should not define the variables in function and just call the function with values I want in the main?
Well, you need to use math to change them, or draw them where it is supposed to be at. Se, you want to call it with a position it needs to draw the ship at. That position is all relative to the one point you pass. The problem defines that point as "The function will be passed a Point that represents the bottom center of the ship."
so what ever may the bottom center of the ship will be that point i start with?
I need to pull up my graph I used to draw myship and see what point that is
Yah, you start from there, and then if some point is say 3 to the left of that, you designate it as -3 on the x axis. If it is 7 higher, it is +7 on the y axis. That makes sense?
makes sense
Then you just call it with the point, it displays it for that mment, it returns to the main, you have your built in pause, call it with the next point, etc.
I get it. kind of like my previous project with moving up down left or right
Yah, you use that as the basis for this, with all the drawing parts of the ship happening in the sub. Wish I had all my code somewhere easy... I backed it up and have not cataloged all the disks yet. Othewise I could show you code from stuff like this: http://www.youtube.com/watch?v=eym2HQjHaWQ It would work as an example.
video is private
Thank you for your help. I can see light at the end of the tunnel
Hmmm.... it is supposed to work for anyone I give the link to.... I wonder if they changed that on me...
Yah, they were all unlisted and now all are privete! http://youtu.be/3ECTLheNiaY I relisted that just now. Int the background you can see some of the code. Hehe.
its working
And here is a reference to functions in general, with some short examples: http://www.cplusplus.com/doc/tutorial/functions/
I'll just have to play with it now and trouble shoot. I have a start point on where begin to call my function
One big thing to note about functions is what happens with their variables. If you set a variable in the main, you can't just use it in the function. You need to pass it. Otherwise the function has no information on it. Also, the variables inside a function only live as long as the function does. Soon as the function closes, they are gone. This is called the scope of the variable. Global variables break the rules of scope, but they also open things up to bugs and attacks. So they should be avoided in general.
Yah, now that you know what they are talking about, the rest of it should not be too hard.
thanks again. when I get it to work I'll send you the exe file so you can see the outcome
Kk. Without the library, it might not be portable.
I can send you library
This is another good reference: http://thenewboston.org/list.php?cat=16 Really basic stuff, about 10 min long for a lot of them. Just get the core info on a topic you have issues with.
nice I will definitely be diggin in to this
Join our real-time social learning platform and learn together with your friends!