亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

麻煩幫忙看看以下這個c++函數要怎么寫?

麻煩幫忙看看以下這個c++函數要怎么寫?

慕桂英4014372 2021-12-07 05:07:17
virual Listing sort(string field); 要求:This is a new method. This method returns a copy of theinvoking Listing object sorted by the field name given in the parameter. Use anappropriate STL sorting function to sort the advertisements. To sort based onthe field name given by the parameter field, consider using anSTL sort function that uses a predicate to determine object equality. The fieldnames that can be passed into this function are "email,""start," "close," and "quantity." 其中listing中的其他定義我也給出來#ifndef LISTING_H#define LISTING_H#include <iostream>#include <vector>#include <iterator>#include <algorithm>#include <functional>#include "Advertisement.h"using namespace std;class Listing;class Listing {protected:typedef vector<Advertisement*> Container;public:typedef Container::iterator iterator;protected:Container objects;public:virtual ~Listing() {};virtual Advertisement* operator[](const int& number);virtual void add(Advertisement* ptr);virtual iterator begin();virtual iterator end();// return a sorted copy of this Listingvirtual Listing sort(string field);// return a filtered by keyword copy of this Listingvirtual Listing filter(string keyword);};#endif
查看完整描述

2 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

直接使用objects對象的add. begin(). end()等方法。
filter 實現 采用 std::remove_if接口,使用函數對象
sort 實現 采用 std::qsort() 接口

查看完整回答
反對 回復 2021-12-12
?
慕田峪7331174

TA貢獻1828條經驗 獲得超13個贊

這是一個新的方法。該方法返回一個對象排序的字段名在參數調用上市的副本。使用適當的STL排序函數進行排序的廣告。根據給定的參數字段的字段名進行排序,可以考慮使用的STL排序功能,使用謂詞來確定對象的平等。傳遞到該函數的字段名可以是“電子郵件”,“開始”,“關閉”和“量”。

查看完整回答
反對 回復 2021-12-12
  • 2 回答
  • 0 關注
  • 261 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號