皮皮学,免费搜题
登录
搜题
【简答题】
阅读下列函数说明和C++代码,回答问题 [说明] 对多个元素的聚合进行遍历访问时,需要依次推移元素,例如对数组通过递增下标的方式,数组下标功能抽象化、一般化的结果就称为迭代器(Iterator)。模式以下程序模拟将书籍(Book)放到书架(BookShelf)上并依次输出书名。这样就要涉及到遍历整个书架的过程。使用迭代器Iterator实现。图5-1显示了各个类间的关系。以下是C++语言实现,能够正确编译通过。 [图5-1] [C++代码] template (1) > class Iterator{ public: virtual bool hasNext() = 0; (2) Object* next() = 0; }; class Book{ //省略具体方法和属性 }; class BookShelf{ private: vector books; public: BookShelf(){ } Book* getBookAt(int index){ return &booksindex; } int getLength(){ return books. size(); } }; template class BookshelfIterator : public (3) { private: BookShelf * bookShelf; int index; public: BookshelfIterator(BookShelf *bookShelf){ this->bookShelf = bookShelf; index = 0; } bool hasNext(){//判断是否还有下一个元素 if(index < bookShelf->getLength()){ return true; }else{ return false; } } Objeot* next(){//取得下一个元素 return bookShelf->getBookAt(index++); } }; int main() { BookShelf bookShelf; //将书籍上架,省略代码 Book *book; Iterator *it = new BookShelfIterator( (4) ); while( (5) ){//遍历书架,输出书名 book=(Book*)it->next(); /*访问元素*/ } return 0; }
拍照语音搜题,微信中搜索"皮皮学"使用
参考答案:
参考解析:
知识点:
.
..
皮皮学刷刷变学霸
举一反三
【简答题】There is little rain this year , ? A. isn’t it                   B.is there                    C.isn’t there
【单选题】There is plenty of rain in the southeast, there is little in the northwest.
A.
because
B.
therefore
C.
while
D.
as
【单选题】There is little juice in the glass, ? [     ]
A.
is there
B.
isn't there
C.
is it
【单选题】下列腹腔脏器,正常情况下不能触及的是
A.
横结肠
B.
肾脏
C.
脾脏
D.
膀胱
【单选题】下列腹腔脏器,正常情况下不能触及的是
A.
肝脏
B.
脾脏
C.
肾脏
D.
膀胱
E.
横结肠
【单选题】下列句子中,加点字解释正确的一项是 1先君子尝言 先君子:已死的父亲 2必躬造左公第 造:制造 3文方成草 草:草稿 4漏鼓移则番代 番代:轮换 5视学 京畿 视学:任学政 6后常流涕以语人 涕:鼻涕 7左公甥也 甥:外甥 8 奉檄守御 檄:古代官府用以晓谕或声讨的文高,此指军事公文
A.
13578
B.
12456
C.
13458
D.
12567
【简答题】为保证面层和基层不受路基水温状况变化所造成的不良影响,必要时要设置(          )。
【判断题】United, there is little we cannot do. Divided, there is little we can do. (alliteration)
A.
正确
B.
错误
【简答题】United, there is little we cannot do in host of co-operative ventures. Divided, there is little we can do, for we dare not meet a powerful challenge at odds and split asunder.
【单选题】United there is little we cannot do in a host of cooperative ventures. Divided there is little we can do.
A.
antithesis
B.
transferred epithet
C.
analogy
D.
alliteration
相关题目: