Im trying to figure out how to utilise a program that uses Aggregation of Classes, Im having trouble calling the operations of the Classes in my main. Could anyone assist where Im going wrong?!
horse.h
#include <iostream>
#include "distance.h"
using namespace std;
class Distance;
class Horse
{
private :
Distance wonby;
public :
Horse(Distance);
void setWinningDistance(Distance);
Distance getWinningDistance();
};
distance.h
#include <iostream>
using namespace std;
class Distance
{
private :
int yards;
public :
Distance(int = 0);
void setDistance(int);
int getyards();
};
distance.cpp
#include ".\distance.h"
#include <iostream>
using namespace std;
Distance::Distance(int y)
{
yards = y;
}
void Distance::setDistance(int newyards)
{
yards = newyards;
}
int Distance::getyards()
{
return yards;
}
horse.cpp
#include ".\horse.h"
#include <iostream>
using namespace std;
Horse::Horse(Distance w)
{
wonby = w;
}
void Horse:: setWinningDistance(Distance w)
{
wonby = w;
}
Distance Horse::getWinningDistance()
{
return wonby;
}
main.cpp (This is where Im having trouble, Im not calling the operations correctly or maybe assigning Horse h1 wrongly?! I know the first line is correct as that compiles at least)
#include "horse.h"
#include <stdlib.h>
int main(int argc, char* argv[])
{
int p,d;
Horse h1(Distance(p));
cout << "Please enter the value "<< endl;
cin >> p;
h1.setWinningDistance(Distance(p));
d = h1.getWinningDistance();
cout << d << endl;
system("Pause");
}
Thanks for any input, is my structure for an aggregation class correct also?