It can be taken as lecturing plus discussion—the discussion being a follow-up of the lecturing.
查看答案
阅读下列函数说明和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;
}
(2011年考试真题)事业单位当年经营收入扣除经营支出后的余额,无论是正数还是负数,均直接计入事业基金。()
听力原文:Woman: May I help you?
Man: Yes, I would like to place an order for toner cartridges. We have a standing agreement with your company, so we will need the same amount as last time.
Woman: Let me key in your information into my computer. I will pull up our records for you. Do you have an order number? What name is the order listed under?
Man: It should be under Smith. The number is 184796 A.
Woman: Yes, Mr. Smith. I have an order for three cases of cartridges, is that what you would like to refill?
Man: Yes.
Woman: Is there the correct billing address?
Man: No, please post the bill to 124 Hildrod Lane, Milton County, 98830.
Woman: I will send you an invoice in the next few days. Your order should be delivered before the end of the day on Monday.
Man: Thank you.
(1)
计算该企业2009年铁路运输合同应纳印花税(运输合同印花税税率为0.5‰,保管合同印花税税率为1‰);