ImageVerifierCode 换一换
格式:DOCX , 页数:22 ,大小:163.62KB ,
资源ID:9762465      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/9762465.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(数据结构课程设计网上拍卖系统实验报告C++.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

数据结构课程设计网上拍卖系统实验报告C++.docx

1、数据结构课程设计网上拍卖系统实验报告C+数据结构课程设计网上拍卖系统实验报告(C+)数据结构课程设计总结报告 专 业 班 级 学 号 姓 名 日 期 东北大学软件学院Clientstring fname;string lname;string email;string passwd;vector offerings;vector bids;void addBid (int item);void addOffering (int item);bool verifyPasswd(string passwd);一个client除了一些基本的客户信息外,还分别拥有该客户发布的所有广告offerings

2、及所有的竞标bids。这里的get,set方法都省去不写。addBid()方法是将Client所竞标的广告的id添加到Client的bids集合里。addOffering()方法是将Client所发布的广告的id添加到Client的offerins集合里。verifyPasswd()方法用来Client登录时验证密码的。 Advertisementint number;/广告的唯一标示符即idint quantity;/提供的竞标的数量string title;string seller_email;string body;Date start;Date close;priority_queu

3、e bids;priority_queue& getBids(void);vector getTopDutchBids (void) const;Adervitisement的属性除了一些基本的信息外,还拥有截至目前为止该广告的所有竞标情况即:priority_queue bids;getBids()方法可以获得截至目前为止的该广告的所有竞标bidsgetTopDutchBids()方法返回值是vector,该vector里存放的是所有成功的bids,但bid里并非所有的quantity都竞标上了。Dateint month;int day;int year;int hour;int minu

4、te;int second;bool operator= (const Date &rhs);bool operator(istream& in, Date& date)Date类中重载了操作符=和,为了判断时间的大小Group mapobjects;Client *operator(const string& email);void add(Client* ptr);iterator begin();iterator end();Group是Client的集合,使用map实现在这里重载了,通过email可以直接获得相应的Client句柄,其他三个方法都是对这个集合的基本操作,添加遍历等Lis

5、tingvector objectsAdvertisement* operator(const int& number);void add(Advertisement* ptr);iterator begin();iterator end();Listing sort(string field);Listing filter(string keyword);Listing类的属性值只有一个,就是Advertisement的集合。方法有:通过重载操作符,可以通过Advertisement的唯一标识符number获得相应的Advertisement对象句柄,这里是Advertisement*类型的

6、指针对该集合的一些操作方法,添加和遍历Sort()方法是按不同的关键字进行排序,方便客户对数据进行分析和决策Filter()方法是搜索含有Keyword的广告,方便客户从大量的广告中筛选客户需要的Categoryint number;int parent;string name;map sub_categories;map items;Category(int parent, string name);map:iterator itemsBegin();map:iterator itemsEnd();map:iterator subCategoriesBegin();map:iterator

7、subCategoriesEnd();void addSubCategory(int);void addItem(int);bool operator=(const Category& rhs);Category的相关属性有本身的id和客户父亲的id,客户的name,sub_categories是该分类下的所有子分类,items是该分类下所有的广告方法有:Category的构造方法;Items集合和sub_categories集合的遍历,添加;重载操作符=;Categoriesmap objects;static const int TOP_LEVEL;static const int NO_

8、PARENT;Category* operator(const int& number);void add(Category* ptr);iterator begin();iterator end();findOfferings (int category, Listing:iterator start, Listing:iterator finish, Listing &matches);void findOfferingsRecursive (int category, Listing:iterator start,Listing:iterator finish, Listing &mat

9、ches);Categories的属性有category的集合对象objects;以及两个静态常量TOP_LEVEL和NO_PARENT,用来初始化最开始的category的number和parent属性值Categories的方法有的重载,通过category相应的属性值number可以获得相应的category*;Add方法,向objects中添加category;findOfferings(),查找当前分类下的所有广告;findOfferingsRecursive(),采用递归的方法查找当前分类下的所有广告及当前分类下的所有子分类的所有广告;Bidstring email;float a

10、mount;int quantity;Date date;bool operator (const Bid &rhs) const;bool operator= (const Bid &rhs) const;Bid的基本属性及操作符,=的重载2、程序设计介绍顺序按照上面类的先后顺序:Advertisement中的getTopDutchBids()方法:思路和代码:vector Advertisement:getTopDutchBids (void) constvector winBids;/里面存放竞标成功的bidint totalWinQuantity=0;/记录所有成功bid的属性值qua

11、ntity之和priority_queue copyOfBids(this-bids);/复制一份Advertisement的bids,否则会丢失竞标失败的相关信息,避免对原数据的直接修改 while(totalWinQuantitygetQuantity()©OfBids.size()!=0)/这里总共有两个限制条件,缺一不可:/1.totalWinQuantity=Advertisement所提供的quantity时退出循环/2.要对优先权队列进行操作,必须保证其不为空,否则会抛异常totalWinQuantity+=copyOfBids.top().getQuantity();/

12、累加bid的quantitywinBids.push_back(copyOfBids.top();/将amount最大的bid添加到优先权队列winBids中copyOfBids.pop();/弹出amount最大的bid,取amount次大的bidreturn winBids;复杂度分析:时间复杂度分析:最好的情况while循环一次,最坏的情况N(其中N为this-getQuantity()和copyOfBids.size()其中较小的一个)空间复杂度分析:需在栈区申请vector,int, priority_queue类型的变量各一个Bidhistory中displayBidHistory

13、方法的实现:思路:displayBidHistory分别传了两个参数,一个是引用型的输出流,一个是Advertisement*,首先要显示的是该广告的一些基本信息,发布者的名字可以通过广告中的email获得,接下来显示竞标情况:如果没有相应的竞标,则返回,给出相应的提示“该条广告目前没有任何竞标”如果有竞标,假如广告提供的quantity=1,则显示该bid的amount和email假如广告提供的quantity1,遍历存放所有成功bid的集合winBids,假如没有遍历到最后一个bid遍历中需要将总共成功的quantity累加到winQuantity中,每遍历一次显示该bid的quantit

14、y,成功的quantity和失败的quantity,此时总的quantity是客户需要的quantity,失败的quantity等于0如果客户需要的大于提供的quantity,则成功的quantity为广告提供的quantity否则成功的quantity等于客户需要的quantity 若遍历到最后一个bid,令left= advertisement-getQuantity()-winQuantity如果bid.getQuantity()getEmail();ossseller :getFname() getLname();ossstart: getStart();ossclose: getCl

15、ose();ossquantity: getQuantity();ossthe number of bids: getBids().size();vector winBids;priority_queue copyOfBids(ad-getBids();winBids=ad-getTopDutchBids();int winQuantity=0;int theWinQuantityOfLastBid=0;oss;if(winBids.empty() ossthe ad dont have any bid until now!; return;if(ad-getQuantity()=1) oss

16、the winning bid is: ; vector:iterator it=winBids.begin(); ossamount: (*it).getAmount(); ossemail: (*it).getEmail(); winQuantity=(*it).getQuantity();else ossthe winning bids are:; for(vector:iterator it=winBids.begin();it!=winBids.end();it+) ossemail: (*it).getEmail(); ossamount: (*it).getAmount(); o

17、sstotal quantity:(*it).getQuantity(); cout(*it).getQuantity()(*it).getQuantity()endl; if(it!=winBids.end()-1) osswin quantity:(*it).getQuantity(); winQuantity+=(*it).getQuantity(); osslose quantity: 0; else/最后一个bid的处理情况 int temp= ad-getQuantity()-winQuantity; if(*it).getQuantity()=temp)/ osswin quan

18、tity:(*it).getQuantity(); winQuantity+=(*it).getQuantity(); osslose quantity: 0; else osswin quantity:temp; winQuantity+=temp;osslose quantity:(*it).getQuantity()-temp; ossthe amount of items in the ad that have not been bid on is: getQuantity()-winQuantityendl;复杂度分析:时间复杂度:最好的情况是1,最坏的情况是N(N=(vector)

19、 winBids.size()空间复杂度:主要是在栈区申请一个vector和priority_queue类型的变量Date类中重要方法的实现:输入流操作符的重载istream &operator(istream& in, Date& date) 实现方法采用getline()对字符串进行分割部分代码如下:char temp10; int temp1; in.getline(temp,4,/); temp1=atoi(temp); date.setMonth(temp1); in.getline(temp,4,/); temp1=atoi(temp); date.setDay(temp1);这个

20、方法实现起来不是很难,在这里提到输入流的重载是为了说明思维惯性的问题。当和同学们讨论时,发现有一个同学是这样实现的:思路比较独特 int month; streammonth; date.setMonth(month); char temp1; /读入第一个“/” streamtemp1; /舍去不要 int day; streamday; date.setDay(day); char temp2; streamtemp2; 他没有使用分隔符,而是按照顺序读取,择我所需,以一颗“平常心”对待那些分隔符,觉得这种思路比较简单明了,但当时的我不太容易想得到,因为受思维惯性的影响,一直在想如何使用分

21、隔符,看来编程人员非常需要灵活变通和淡定的心态。Listing类中重要方法的实现:Listing Listing:sort(string field)方法的分析:思路:根据指导书提供的思路,This method returns a copy of the invoking Listing object sorted by the field name given in the parameter. Use an appropriate STL sorting function to sort the advertisements. The field names that can be pa

22、ssed into this function are email, start, close, and quantity.,仔细阅读之后知道了这个方法体的大概构架,sort函数第三个参数是个判断条件,为了避免写多个判断条件,可以使用函数对象SortBy来简化程序。代码实现:Listing Listing:sort(string field) Listing sortedList;/ a copy of the invoking Listing sortedList.objects=this-objects; SortBy sortBy(field); std:sort(sortedList.

23、objects.begin(),sortedList.objects.end(),sortBy); return sortedList; 函数对象(也称“算符”)是重载了“()”操作符的普通类对象。从语法上讲,函数对象与普通的函数行为类似,实现时需要注意几点:1,里面所有的属性方法是public.2,因为要使用外界的参数field,该函数对象得写构造函数3,对操作符()的重载函数对象SortBy的实现:class SortBypublic:/the default value is private! string field; SortBy(string field):field(field)

24、 bool operator()(Advertisement* ad1,Advertisement* ad2) if(pare(email)=0) if(ad1-getEmail().compare(ad2-getEmail()getBids().empty()&!ad2-getBids().empty()&(ad1-getBids().top()getBids().top() return true ;else return false; else if(pare(lowest)=0)/在成功的bids里选取amount最小的 if(!ad1-getTopDutchBids().empty(

25、)&!ad2-getTopDutchBids().empty()&(ad1-getTopDutchBids().back()getTopDutchBids().back() return true;else return false; ;下面是lowest的第二种实现方法:在一个广告的所有bids里选取amount最小的,先拷贝一份priority_queuecopyOfBids 然后pop() 直到最后一个,即可获得最小的amount./*float low1=-1.0,low2=-1.0;priority_queue copyOfBids1(ad1-getBids(),copyOfBids

26、2(ad2-getBids();if(!copyOfBids1.empty() low1=copyOfBids1.top().getAmount(); while(!copyOfBids1.empty() if(low1copyOfBids1.top().getAmount() low1=copyOfBids1.top().getAmount(); copyOfBids1.pop(); if(!copyOfBids2.empty() low2=copyOfBids2.top().getAmount(); while(!copyOfBids2.empty() if(low2copyOfBids2.top().getAmount() low2=copyOfBids2.top().getAmount(); copyOfBids2.pop(); if(low10)&(low20) return true; else return false;*/需要说明的是SortBy中lowest的排序,就是这个lowest究竟怎么理解,对于一个广告,它有很多bid,设winBids是成功的bid,它存放在向量vector里面,totalBids是该广告所有的bid,它存放在priority_queue里,那么这个lowest是winBids里的lowest还是totalBid

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1