I am new to the concept of using headers. When I try to delete any of my includes the program breaks even more, but says the class type is being defined more than once.
#ifndef HORSE_H
#define HORSE_H
#include <iostream>
usingnamespace std;
// use header to declare horse class,
class Horse
{
private:
string name;
string rider;
int maxRunningDistPerSecond;
int distanceTraveled;
int racesWon;
public:
void setName(string);
void setRider(string);
int getMaxRunningDistPerSecond() const;
int getDistanceTraveled() const;
int getRacesWon() const;
};
#endif
#include <iostream>
#include "Horse.h"
usingnamespace std;
// define horse class with all information to be stored
class Horse
{
private:
string name;
string rider;
int maxRunningDistPerSecond;
int distanceTraveled;
int racesWon;
public:
void setName(string input)
{
name = input;
}
void setRider(string input)
{
rider = input;
}
int getMaxRunningDistPerSecond() const;
int getDistanceTraveled() const;
int getRacesWon() const;
};
#include "stdafx.h"
// A Horse racing simulation program
#include <iostream>
#include <string>
#include "Horse.h"
usingnamespace std;
int main()
{
int numHorses = 0;
Horse horseArr[20] {};
// determine number of horses in race
cout << "How many horses are in the race?";
cin >> numHorses;
while (numHorses < 1 || numHorses > 20)
{
cout << "Please enter valid number of Horses";
cin >> numHorses;
}
// create Class array for numHorses and get fill in horse and rider names
for (int i = 0; i < numHorses - 1; i++)
{
cout << "Please enter the name of Horse " << i+1 << " : ";
string input;
getline(cin, input);
horseArr[i].setName(input);
cout << "Please enter the name of Rider for Horse " << i + 1 << " : ";
getline(cin, input);
Horse setRider(string input);
}
return 0;
}