2026年noip题目分析结构体与类的使用技巧.docxVIP

  • 0
  • 0
  • 约7.55千字
  • 约 22页
  • 2026-05-09 发布于福建
  • 举报

2026年noip题目分析结构体与类的使用技巧.docx

第PAGE页共NUMPAGES页

2026年noip题目分析结构体与类的使用技巧

一、选择题(共5题,每题3分,共15分)

题目1:

阅读以下C++代码,分析结构体`Student`和类`Classroom`的使用,选择正确的描述。

cpp

includeiostream

usingnamespacestd;

structStudent{

stringname;

intage;

floatscore;

};

classClassroom{

public:

voidaddStudent(Students){

students.push_back(s);

}

floatgetAverageScore(){

if(students.empty())return0;

floatsum=0;

for(autos:students)sum+=s.score;

returnsum/students.size();

}

private:

vectorStudentstudents;

};

intmain(){

Classroomc;

Students1={Alice,17,92.5};

c.addStudent(s1);

coutc.getAverageScore()endl;

return0;

文档评论(0)

1亿VIP精品文档

相关文档