473,938 Members | 8,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Search function


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;

}
Jul 22 '05 #1
3 1773

"John J" <...@...> wrote in message
news:0e******** *************** *******@news.te ranews.com...

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;

}


Race r1;
Entry e1 (&r1, &y1,1,"22:30"); "

if(*e.getRace == r1)
cout << e << '\n';

-Mike
Jul 22 '05 #2

"John J" <...@...> wrote in message
news:0e******** *************** *******@news.te ranews.com...

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.


I don't think you've supplied enough information. The definition of the Race
class is essential, as is the relationship between Race and Entry. You've
already said that each Entry has a reference to a Race, presumably each Race
also has references to all the Entries for that race in some manner.

I actually think its questionable that Entry has a reference to Race,
creating circular references (Entry has reference to Race and each Race has
references to all its Entries) is something that shouldn't be done lightly,
in my opinion. Of course it all depends on how everything hangs together in
your final system but I'd be surprised if it is really necessary.

Probably the best thing is not to be shy and to post one of your failed
attempts. Seeing code tends to be much more informative than reading
descriptions of code.

john
Jul 22 '05 #3
John J wrote:
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;

}


Hello,

first of all you didn't tell us where do you store all entries which
is essential. I'll suppose that you use some kind of container - say list.

std::list<Entry > entry_list;

Then you have to create function or class which will be able to compare
some race with some entry and print the entry if it belongs to the race.
I suggest using class which is able to hold the information as well.
It's definition might look like this:

class PrintRaceEntrie s
{
private:
const Race& race_to_look_fo r;
std::ostream& target_stream;
public:
// constructor
PrintRaceEntrie s(const& Race rtlf, std::ostream& ts)
: race_to_look_fo r(rtlf), target_stream(t s) {};

// this function prints it's parameter it's getRace() equals to Race
// supplied in constructor of this class
void operator(const Entry& entry_in_questi on) {
if (entry_in_quest ion.getRace() == race_to_look_fo r)
target_stream << entry_in_questi on;
};
};
Following line will apply operator() of temporary created instance of
PrintRaceEntrie s to all items in entry_list.

std::for_each(e ntry_list.begin (), entry_list.end( ),
PrintRaceEntrie s(some_race, std::cout));

Easy, isn't is!?

Of course you can create many functors to implement different behaviour.
There are also other usefull algorithms which might come handy.

Please refer to STL documentation.

Ales

Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8754
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast, returned the hyperlinked page title, filename, and the body txt (30 preceding and following words) in context with the search word highlighted. Excellent.! See it working at: http://www.ipt.co.za Just search for "firearm"
4
2689
by: Ken Fine | last post by:
I'm looking to find or create an ASP script that will take a string, examine it for a search term, and if it finds the search term in the string, return the highlighted search term along with the words that surround it. In other words, I want the search term highlighted and shown in an excerpt of the context in which it appears. Any suggestions or pointers? This behavior is most often seen as part of a search engine. In my case, I want...
5
2649
by: pembed2003 | last post by:
Hi all, I need to write a function to search and replace part of a char* passed in to the function. I came up with the following: char* search_and_replace(char* source,char search,char* replace){ char* result; size_t l = strlen(source), r = strlen(replace), i; int number_of_replaces = 0; for(i = 0; i < l; i++){ if(source == search)
4
2181
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any help on this, Benny
6
6503
by: cthoes | last post by:
following program does the display of student details but i want to search for the particular student name from the added list of student. so it would be great any one can help me without using strcmp() function #include<stdio.h> #include<string.h> int main(){ int i,n;
0
10133
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
11287
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10655
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9854
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7380
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6073
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6292
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.