J
John J
I am in the process of writing 3 associated classes to store details of
yacht racing information. Below is a section of code from my Entry class. An
entry object is created as follows "Entry e1 (&r1, &y1,1,"22:30");"
The &r1 is a reference to an associated Race object (Race class) and &y1 is
a reference to an associated Yacht object (Yacht class). The 1 is a place
ie, 1 = first, and "22:30" is the finish time.
I wish to add a function to the Race class that will search all entry
objects (class below) and display all the Yachts that entered a specified
race; however, all my attempts at a search function have failed. I'd
appreciate some advice on this.
#include <iostream>
#include <string>
#include "Entry.h"
using namespace std;
//Construct an Entry
Entry::Entry (Race* r, Yacht* y, int pl, string ti)
{
which = r;
what = y;
place = 0;
time = "";
}
//Access functions
int Entry::getPlace () const
{
return place;
}
string Entry::getTime () const
{
return time;
}
Race* Entry::getRace () const
{
return which;
}
Yacht* Entry::getYacht () const
{
return what;
}
//Overload of operator<< for output of an Entry
ostream& operator<< (ostream& out, const Entry& e)
{
out << "Finish Place: " << e.place << endl
<< "Finish Time: " << e.time << endl
<< "Race Nr (date): " << *(e.which)
<< "Yacht: " << *(e.what) << endl;
return out;
}
yacht racing information. Below is a section of code from my Entry class. An
entry object is created as follows "Entry e1 (&r1, &y1,1,"22:30");"
The &r1 is a reference to an associated Race object (Race class) and &y1 is
a reference to an associated Yacht object (Yacht class). The 1 is a place
ie, 1 = first, and "22:30" is the finish time.
I wish to add a function to the Race class that will search all entry
objects (class below) and display all the Yachts that entered a specified
race; however, all my attempts at a search function have failed. I'd
appreciate some advice on this.
#include <iostream>
#include <string>
#include "Entry.h"
using namespace std;
//Construct an Entry
Entry::Entry (Race* r, Yacht* y, int pl, string ti)
{
which = r;
what = y;
place = 0;
time = "";
}
//Access functions
int Entry::getPlace () const
{
return place;
}
string Entry::getTime () const
{
return time;
}
Race* Entry::getRace () const
{
return which;
}
Yacht* Entry::getYacht () const
{
return what;
}
//Overload of operator<< for output of an Entry
ostream& operator<< (ostream& out, const Entry& e)
{
out << "Finish Place: " << e.place << endl
<< "Finish Time: " << e.time << endl
<< "Race Nr (date): " << *(e.which)
<< "Yacht: " << *(e.what) << endl;
return out;
}