the question says
"Create an array of space ship objects and write a program that continually updates their positions
until they all go off the screen. Assume that the size of the screen is 1024 pixels by 768 pixels."
I dont understand what it mean by "assume that the size of screen is 1024 by 768 , does it mean that I change the resolution of the console ?
or something else.
hard to say without context.
- long ago, that was the default screen resolution and it stayed there for many years: this assignment may be very old?
- are you doing graphics, or is it a simulation of a virtual screen? That is, do you draw anything here?
- if it is graphics, you can just make a 1024x768 area and draw in it; its going to fit on any modern screen with room to spare.
- if its the console, you may need to resize it.
- it could be as againtry said... are you to scale screen as if it were square and translate that?
The spaceship will be on the perimeter of a 1024 X 768 pixel console when x == 0 or x == 1024 or y == 0 or y == 768, x and y are screen coordinates derived from a transformation of the world coordinates.
If you are just starting off then make it so the spaceship world coordinates are just the same as screen coordinates, thus no transformation required.
First make a Spaceship class or struct with its x and y coordinates as properties.
struct Spaceship ... blah blah
Then create a Spaceship object (in main() ) and 'move' it around by changing its x and y values.
1 2 3 4 5 6 7
int main()
{
Space sh;
sh.x = ... blah blah
...
}
At each change in x,y position you can then draw it at that position. Use a character eg '*' for a start.
do I use space to move them or what.
Believe it or not, we are all, including your Spaceship, in space so I guess you meant the spacebar. You can use that if you like but to me that comes later - you're still at problem 1. Just type in the coordinates.
so if I changed its coordinates which understand , how to I change its position by pixels in console , thats the thing I don't really understand .
do I make a matrix , or something else .
in the console you really do it as characters, not pixels, so extend console to support the extra wide and extra long buffer, then draw it over and over. To draw pixels in the console requires graphics libraries and a LOT more. Something like * can be a 'pixel' or a 'spaceship' ... whatever you want.
@OP
You best check with your teacher but my understanding of the chapter and question is that it is not necessary to try and display the ships but process the information. (If it is required, you still have to go through the exercise of calculating the position.)
Here's a simple start which you can extend for the y_coordinate and even like the chapter talks about, make an array of 1000 spaceships with random movements and checke whether any 'go off the screen'. You can show that with the numbers.
oh, so question wont ask me to print the actual space ship on the screen , I thought I will have to print a character 'o' that represent the space ship across the console , ok ty .
oh , so question wont ask me to print the actual space shop on the screen , I thought I will have to print a character 'o' that represent the space ship across the console , ok ty .
Like I said, from reading the chapter and question I don't think you have to display movement on the screen but you should check that with your teacher.