我已将strudent
定义为:
struct student{
char name[50];
int roll;
int marks;
};
我正在尝试打印student
s
marks
字段中struct student s[5];
int i;
cout << "Enter information of students : " << endl;
for(i=0;i<3;++i)
{
cout <<"Enter roll no : ";
cin>>s[i].roll;
cout << "Enter name : ";
cin >> s[i].name;
cout << endl << "Enter marks : ";
cin >> s[i].marks;
cout << endl;
}
for(int j=0;j<3;j++)
{
if(s[j].marks>60)
{
cout<<s[j].roll<<" "<<s[j].name<<" = "<<s[j].marks<<" is Passed"<<endl;
}
else
{
cout<<s[j].roll<<" "<<s[j].name<<" = "<<s[j].marks<<" is Failed"<< endl;
}
}
cout<<endl;
cout<<endl;
int max=s[0].marks;
for(int k=0; k<3; k++)
{
if(s[k].marks>max)
{
max=s[k].marks;
}
cout<<s[k].roll<<" "<<s[k].name<<" "<<max<<" is top in the class:"<<endl;
}
的{{1}}:
var $div = $('<div>');
$div.load('modules/dyo/views/test.html', function(){
var html=this;
$elem.append(html);
$fullLoader = $elem.children().children('.fpd-full-loader').hide();
$mainContainer = $elem.children().children('.fpd-main-container');
$productStage = $mainContainer.children('.fpd-product-stage').height(options.stageHeight);
$elementTooltip = $productStage.children('.fpd-element-tooltip').html(options.labels.outOfContainmentAlert);
$mainContainer.children('.fpd-context-dialog').remove().clone().prependTo($sidePanel);
$contextDialog = $body.find('.fpd-context-dialog').addClass('fpd-hidden');
$contextLoader = $contextDialog.find('.fpd-context-loader');
$colorPicker = $contextDialog.find('.fpd-color-picker');
$colorPicker1 = $contextDialog.find('.fpd-color-pickerrr');
$swatchPicker = $contextDialog.find('.fpd-color-swatch');
$elem.trigger('templateLoad', [this.url]);
});
现在我打印所有的学生!我只想要名字,并且在所有人中都有最高分的学生名单。我做错了什么?
答案 0 :(得分:1)
你说你:想要在所有学生中名列前茅的学生的姓名和名单
为此,您需要找到具有最高分数的学生的索引。但在我给你一个如何做到这一点的例子之前,我需要初始化整个 var phantom = require('phantom');
// var page = new WebPage();
// var system = require('system');
// var sBlob = system.args[1];
var sUrl = 'file:///C:/Users/editor.html?Blob='+sBlob;
phantom.create(function(ph) {
ph.createPage(function(page) {
page.open(sUrl, function(status) {
console.log("opened diagram? ", status);
page.evaluate(function() {
return document.getElementById("GraphImage").src;
}, function(result) {
console.log(result)
ph.exit();
});
});
});
}, {
dnodeOpts : {
weak : false
}
});
数组。这意味着:
s
)for(i = 0; i < sizeof(s) / sizeof(s[0]); ++i)
)一旦完成,您就可以有效地使用max_element
找到具有最高分的学生:
student s[3]
const auto it = max_element(cbegin(s), cend(s), [](const auto& lhs, const auto& rhs){ return lhs.marks < rhs.marks; });
现在指向具有最高分的学生,您可以这样打印:
it
您可以在此处查看此实例:http://ideone.com/JcPQMI