最佳结果功能 [英] best result function

查看:52
本文介绍了最佳结果功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将以下代码编写到一个类中,以搜索并显示输入的所有种族的

结果(完整代码位于上一个帖子中)。我希望修改代码以便仅显示最佳结果。


任何人都可以建议对以下内容进行简单的修改,这将导致

只显示最佳结果?


感谢您的帮助


void Yacht :: best_result(ostream& out) )const


{


条目* e = NULL;


out<< 搜索此游艇的比赛显示以下结果:

<< endl;


if(nYEntries == 0)


{


out<< ; 这艘游艇没有进入比赛: <<结束;


}


其他


{


bool found_a_result = false; //还没有找到结果


for(int i = 0; i< nYEntries; i ++)


{


e = yacht_entries [i];


if(e-> getPlace()> = 1)


{


out<< * e;


found_a_result = true; //结果已经找到


}


}


if(!found_a_result) //如果没有结果


{


out<< 未找到任何结果 <<结束;


}


}


}

I''ve written the following code into a class to search for and display the
results of all races entered (The complete code is in a previous thread). I
wish to amend the code so as to display the best result only.

Can anyone suggest a simple amendment to the following that will result in
only the best result being displayed?

Thanks for any help

void Yacht::best_result (ostream& out) const

{

Entry* e =NULL;

out << "A search of races for this Yacht shows the following results:
" << endl;

if (nYEntries == 0)

{

out << "This Yacht has entered no races: " << endl;

}

else

{

bool found_a_result = false; // no result found yet

for (int i=0; i<nYEntries; i++)

{

e = yacht_entries[i];

if (e->getPlace() >= 1)

{

out << *e;

found_a_result = true; // a result has been found

}

}

if (!found_a_result) // if no result

{

out << "No results were found" << endl;

}

}

}

推荐答案



" John J" < ... @ ...>在消息中写道

news:45 ****************************** @ news.teranew s。 com ...

"John J" <...@...> wrote in message
news:45******************************@news.teranew s.com...
我已将以下代码编写到一个类中,以搜索并显示输入的所有种族的结果(完整代码位于上一个帖子中)。
我希望修改代码,以便只显示最佳结果。
I''ve written the following code into a class to search for and display the
results of all races entered (The complete code is in a previous thread). I wish to amend the code so as to display the best result only.




这是你必须把自己想象成一台电脑的地方。如果你在一台

计算机上并获得了一份结果列表,你会如何找到最好的一台?


记住计算机只能查看结果一次一个,

的重要概念是迄今为止最好的结果。当计算机依次查看每个结果时,它可以记住到目前为止最好的结果。到目前为止,使用

变量来存储最佳结果。当计算机查看了所有结果的结果时,到目前为止最好的结果将是整体效果最好的结果。


HTH

john



This is where you have to imagine yourself as a computer. If you where a
computer and were given a list of results how would you find the best one?

Remembering that a computer can only look at the result one at a time, the
important concept is that of the ''best result so far''. While the computer is
looking at each result in turn it can remember the best result so far. Use a
variable to store the best result so far. When the computer has looked at
all the results, the best result so far will be the best result overall.

HTH
john


我修改了代码几次;但是,每当我尝试输出

的新值时,我要么得到一个数字值(而不是条目对象

我希望返回)或一系列链接错误。


我在测试后做了我的修改(e-> getPlace()> = 1)并为变量分配* e

" bestplace"在同一个if循环中。我是不是错误地对待这个




谢谢

" John Harrison" <乔************* @ hotmail.com>在消息中写道

新闻:2g *********** @ uni-berlin.de ...
I''ve amended the code a couple of times; however, whenever I try and output
the new value, I either get a numberical value (rather than the Entry Object
I wish returned) or a series of link errors.

I''m doing my amendments after the test (e->getPlace() >=1) and assigning *e
to a variable "bestplace" in the same if loop. Am I going about this
incorrectly?

Thanks
"John Harrison" <jo*************@hotmail.com> wrote in message
news:2g***********@uni-berlin.de...

John J ; < ... @ ...>在消息中写道
新闻:45 ****************************** @ news.teranew s.com ...

"John J" <...@...> wrote in message
news:45******************************@news.teranew s.com...
我已将以下代码写入类中以搜索并显示
输入的所有种族的结果(完整代码位于之前的
I''ve written the following code into a class to search for and display the results of all races entered (The complete code is in a previous


线)。我

希望修改代码以便仅显示最佳结果。

这是你必须把自己想象成一台电脑的地方。如果您在某台计算机上并获得了结果列表,您将如何找到最佳结果?

记住计算机一次只能查看一个结果,
重要的概念是迄今为止最好的结果。虽然计算机
wish to amend the code so as to display the best result only.

This is where you have to imagine yourself as a computer. If you where a
computer and were given a list of results how would you find the best one?

Remembering that a computer can only look at the result one at a time, the
important concept is that of the ''best result so far''. While the computer



依次查看每个结果,但它可以记住到目前为止最好的结果。使用
变量来存储到目前为止的最佳结果。当计算机查看了所有结果时,到目前为止最好的结果将是最好的结果。

HTH
john


is looking at each result in turn it can remember the best result so far. Use a variable to store the best result so far. When the computer has looked at
all the results, the best result so far will be the best result overall.

HTH
john



John J写道:

我修改了代码几次;但是,每当我尝试输出新值时,我要么得到一个数字值(而不是我希望返回的条目对象)或一系列链接错误。

我在测试后做了我的修改(e-> getPlace()> = 1)并将* e
分配给变量bestplace。在同一个if循环中。我是不是错了?

I''ve amended the code a couple of times; however, whenever I try and output
the new value, I either get a numberical value (rather than the Entry Object
I wish returned) or a series of link errors.

I''m doing my amendments after the test (e->getPlace() >=1) and assigning *e
to a variable "bestplace" in the same if loop. Am I going about this
incorrectly?




没人知道,如果你没有显示给你麻烦的代码。


此外。如果你想在一个新闻组中提出更多相同的问题,请做一个交叉点。通过这种方式,其他

组中的人将会看到答案,而不必在另一个新闻组中回答已经回答的问题。

-

Karl Heinz Buchegger
kb ****** @ gascad.at


这篇关于最佳结果功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆