为了账号安全,请及时绑定邮箱和手机立即绑定

麻烦帮忙看看以下这个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 关注
  • 191 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信