Hello, everyone. I currently am having some trouble with C++, mostly the Object Oriented aspect of it. I have been working on a series of problems on one homework assignment and I am left stumped to the point that everything I have learned somehow makes no sense.(hard to explain) I had to take a cpp file which has the class and the main in it, and then split it into three files. a header, main and core file. The core file will use a constructor which calls on two variables(i think this is the right term for this). The header will be like any header would, and the main would execute the whole program. The problem I am currently having which maybe caused by another error but right now I only have two. I somehow am unable to call upon the function which has a return of Void. I'm running the Microsoft Visual C++ 2008 Express Edition compiler incase that makes any difference. Below I'll post the code for each of the files. I have another problem from the same assignment but this one has been plaguing me right form the start. By the way, I am in a Game Programming degree course in case that helps in where I am coming from.
I have looked online and seen mixed answers on how to do this, and any help i tried to get from other sites, was not really helpful. I've gone through tutorials both online and in my course book, but somehow something is not adding up right. Thank you ahead of time for any help I get, I'll surely be looking on here more and asking more questions to future homework assignments.
Main file:
Code:
#include <iostream>
using namespace std;
#include "Asteroids.h"
int main()
{
Asteroid firstAsteroid;
Asteroid secondAsteroid;
firstAsteroid.displayStats(1,20);
secondAsteroid.displayStats(3,4);
char wait;
cin>> wait;
return 0;
}
Core file:
Code:
#include <iostream>
using namespace std;
class Asteroid
{
int astSize;
int astSpeed;
int AsteroidNumber;
public:
Asteroid ( int Size, int Speed, int AsteroidNumber )
{
setSpeed( Size);
setSize (Speed);
}
int getSize()
{
return astSize;
}
int getSpeed()
{
return astSpeed;
}
void displayStats( int AsteroidNumber)
{
cout<< "Asteroids " << endl;
cout<< " Asteroid number " << AsteroidNumber << endl;
cout<< " Size " << astSize << endl;
cout<< " Speed " << astSpeed << endl;
}
void setSize(int Size)
{
astSize = Size;
}
void setSpeed(int Speed)
{
astSpeed = Speed;
}
};
header:
Code:
#define Asteroids_h
class Asteroid
{
public:
int astSpeed;
int astSize;
int AsteroidNumber;
Asteroid () {}
void displayStats(int astSize, int astSpeed, int AsteroidNumber);
void setSize( int astSize);
void setSpeed(int astSpeed);
int setSpeed()
{
return astSpeed;
}
int setSize()
{
return astSpeed;
}
};