I need to write a program that prints 100 stars on the screen (at random places), and then the stars disappear slowly – one after another. I’m not allowed to use loops nor recursions.
I’ve tried to play with the constructors and the destructors but I can’t get the stars to disappear one after another (and not all together).
Any ideas?
Thanks,
Li
Sorry – forgot to mention i’m using c++
My current access violating useless code:
class star {
int x;
int y;
public:
star(){
x = rand()%80;
y = rand()%80;
PaintcharOnRandomLocation('*',x,y);
};
~star(){
PaintcharOnRandomLocation(' ',x,y);
};
};
class printAll{
star* arr;
public:
printAll(){
arr = new star[100];
};
~printAll(){
delete[] arr;
};
};
void doNothing(printAll L){
};
void main()
{
srand ( time(NULL) );
doNothing(printAll());
getch();
};
Seems the only way possible without loops/recursion is something like this:
This is really just a dumb trick because the compiler has to run the constructor for each star to initialise the array and then the destructor for EACH star as it goes out of scope.
It is also a bad trick as all the workings that go in the main function are opaque and invisible. It would obviously be better to use a loop in this context and putting the delay inside a destructor like this is really confusing and unmaintainable.