数据结构课程设计网上拍卖系统实验课程报告(C)_第1页
数据结构课程设计网上拍卖系统实验课程报告(C)_第2页
数据结构课程设计网上拍卖系统实验课程报告(C)_第3页
数据结构课程设计网上拍卖系统实验课程报告(C)_第4页
数据结构课程设计网上拍卖系统实验课程报告(C)_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数据结构课程设计网上拍卖系统实验报告(C+)actively carry out the law on civil air defense education, drawn out of the air defense in Pingliang city Building under easy fare, daily special inspection and regulation, overfulfilled the province upper and lower knots of up to 500,000 yuan fee collection tasks. 5, further s

2、tandardize internal management, improve staff quality. Adhere to theactively carry out the law on civil air defense education, drawn out of the air defense in Pingliang city Building under easy fare, daily special inspection and regulation, overfulfilled the province upper and lower knots of up to 5

3、00,000 yuan fee collection tasks. 5, further standardize internal management, improve staff quality. Adhere to theactively carry out the law on civil air defense education, drawn out of the air defense in Pingliang city Building under easy fare, daily special inspection and regulation, overfulfilled

4、 the province upper and lower knots of up to 500,000 yuan fee collection tasks. 5, further standardize internal management, improve staff quality. Adhere to the数据结构课程设计总结报告 专 业 班 级 学 号 姓 名 日 期 东北大学软件学院PAGE PAGE 13Clientstring fname;string lname;string email;string passwd;vector offerings;vector bids

5、;void addBid (int item);void addOffering (int item);bool verifyPasswd(string passwd);一个client除了一些基本的客户信息外,还分别拥有该客户发布的所有广告offerings及所有的竞标bids。这里的get,set方法都省去不写。addBid()方法是将Client所竞标的广告的id添加到Client的bids集合里。addOffering()方法是将Client所发布的广告的id添加到Client的offerins集合里。verifyPasswd()方法用来Client登录时验证密码的。Advertise

6、mentint number;/广告的唯一标示符即idint quantity;/提供的竞标的数量string title;string seller_email;string body;Date start;Date close;priority_queue bids;priority_queue& getBids(void);vector getTopDutchBids (void) const;Adervitisement的属性除了一些基本的信息外,还拥有截至目前为止该广告的所有竞标情况即:priority_queue bids;getBids()方法可以获得截至目前为止的该广告的所有竞

7、标bidsgetTopDutchBids()方法返回值是vector,该vector里存放的是所有成功的bids,但bid里并非所有的quantity都竞标上了。Dateint month;int day;int year;int hour;int minute;int second;bool operator= (const Date &rhs);bool operator(istream& in, Date& date)Date类中重载了操作符=和,为了判断时间的大小Group mapobjects;Client *operator(const string& email);void ad

8、d(Client* ptr);iterator begin();iterator end();Group是Client的集合,使用map实现在这里重载了,通过email可以直接获得相应的Client句柄,其他三个方法都是对这个集合的基本操作,添加遍历等Listingvector objectsAdvertisement* operator(const int& number);void add(Advertisement* ptr);iterator begin();iterator end();Listing sort(string field);Listing filter(string

9、keyword);Listing类的属性值只有一个,就是Advertisement的集合。方法有:通过重载操作符,可以通过Advertisement的唯一标识符number获得相应的Advertisement对象句柄,这里是Advertisement*类型的指针对该集合的一些操作方法,添加和遍历Sort()方法是按不同的关键字进行排序,方便客户对数据进行分析和决策Filter()方法是搜索含有Keyword的广告,方便客户从大量的广告中筛选客户需要的Categoryint number;int parent;string name;map sub_categories;map items;Ca

10、tegory(int parent, string name);map:iterator itemsBegin();map:iterator itemsEnd();map:iterator subCategoriesBegin();map:iterator subCategoriesEnd();void addSubCategory(int);void addItem(int);bool operator=(const Category& rhs);Category的相关属性有本身的id和客户父亲的id,客户的name,sub_categories是该分类下的所有子分类,items是该分类下所

11、有的广告方法有:Category的构造方法;Items集合和sub_categories集合的遍历,添加;重载操作符=;Categoriesmap objects;static const int TOP_LEVEL;static const int NO_PARENT;Category* operator(const int& number);void add(Category* ptr);iterator begin();iterator end();findOfferings (int category, Listing:iterator start, Listing:iterator

12、finish, Listing &matches);void findOfferingsRecursive (int category, Listing:iterator start,Listing:iterator finish, Listing &matches);Categories的属性有category的集合对象objects;以及两个静态常量TOP_LEVEL和NO_PARENT,用来初始化最开始的category的number和parent属性值Categories的方法有的重载,通过category相应的属性值number可以获得相应的category*;Add方法,向obje

13、cts中添加category;findOfferings(),查找当前分类下的所有广告;findOfferingsRecursive(),采用递归的方法查找当前分类下的所有广告及当前分类下的所有子分类的所有广告;Bidstring email;float amount;int quantity;Date date;bool operator (const Bid &rhs) const;bool operator= (const Bid &rhs) const;Bid的基本属性及操作符,=的重载2、程序设计介绍顺序按照上面类的先后顺序:Advertisement中的getTopDutchBid

14、s()方法:思路和代码:vector Advertisement:getTopDutchBids (void) constvector winBids;/里面存放竞标成功的bidint totalWinQuantity=0;/记录所有成功bid的属性值quantity之和priority_queue copyOfBids(this-bids);/复制一份Advertisement的bids,否则会丢失竞标失败的相关信息,避免对原数据的直接修改while(totalWinQuantitygetQuantity()©OfBids.size()!=0)/这里总共有两个限制条件,缺一不可:/1

15、.totalWinQuantity=Advertisement所提供的quantity时退出循环/2.要对优先权队列进行操作,必须保证其不为空,否则会抛异常totalWinQuantity+=copyOfBids.top().getQuantity();/累加bid的quantitywinBids.push_back(copyOfBids.top();/将amount最大的bid添加到优先权队列winBids中copyOfBids.pop();/弹出amount最大的bid,取amount次大的bidreturn winBids;复杂度分析:时间复杂度分析:最好的情况while循环一次,最坏的

16、情况N(其中N为this-getQuantity()和copyOfBids.size()其中较小的一个)空间复杂度分析:需在栈区申请vector,int, priority_queue类型的变量各一个Bidhistory中displayBidHistory方法的实现:思路:displayBidHistory分别传了两个参数,一个是引用型的输出流,一个是Advertisement*,首先要显示的是该广告的一些基本信息,发布者的名字可以通过广告中的email获得,接下来显示竞标情况:如果没有相应的竞标,则返回,给出相应的提示“该条广告目前没有任何竞标”如果有竞标,假如广告提供的quantity=1

17、,则显示该bid的amount和email假如广告提供的quantity1,遍历存放所有成功bid的集合winBids,假如没有遍历到最后一个bid遍历中需要将总共成功的quantity累加到winQuantity中,每遍历一次显示该bid的quantity,成功的quantity和失败的quantity,此时总的quantity是客户需要的quantity,失败的quantity等于0如果客户需要的大于提供的quantity,则成功的quantity为广告提供的quantity否则成功的quantity等于客户需要的quantity若遍历到最后一个bid,令left= advertiseme

18、nt-getQuantity()-winQuantity如果bid.getQuantity()getEmail();ossseller :getFname() getLname();ossstart: getStart();ossclose: getClose();ossquantity: getQuantity();ossthe number of bids: getBids().size();vector winBids;priority_queue copyOfBids(ad-getBids();winBids=ad-getTopDutchBids();int winQuantity=0

19、;int theWinQuantityOfLastBid=0;oss;if(winBids.empty()ossthe ad dont have any bid until now!;return;if(ad-getQuantity()=1) ossthe winning bid is: ;vector:iterator it=winBids.begin();ossamount: (*it).getAmount();ossemail: (*it).getEmail();winQuantity=(*it).getQuantity();else ossthe winning bids are:;f

20、or(vector:iterator it=winBids.begin();it!=winBids.end();it+)ossemail: (*it).getEmail();ossamount: (*it).getAmount();osstotal quantity:(*it).getQuantity();cout(*it).getQuantity()(*it).getQuantity()endl;if(it!=winBids.end()-1)osswin quantity:(*it).getQuantity();winQuantity+=(*it).getQuantity();osslose

21、 quantity: 0;else/最后一个bid的处理情况int temp= ad-getQuantity()-winQuantity;if(*it).getQuantity()=temp)/osswin quantity:(*it).getQuantity();winQuantity+=(*it).getQuantity();osslose quantity: 0;else osswin quantity:temp;winQuantity+=temp;osslose quantity:(*it).getQuantity()-temp;ossthe amount of items in th

22、e ad that have not been bid on is: getQuantity()-winQuantityendl;复杂度分析:时间复杂度:最好的情况是1,最坏的情况是N(N=(vector) winBids.size()空间复杂度:主要是在栈区申请一个vector和priority_queue类型的变量Date类中重要方法的实现:输入流操作符的重载istream &operator(istream& in, Date& date) 实现方法采用getline()对字符串进行分割部分代码如下:char temp10;int temp1;in.getline(temp,4,/);

23、temp1=atoi(temp);date.setMonth(temp1);in.getline(temp,4,/);temp1=atoi(temp);date.setDay(temp1);这个方法实现起来不是很难,在这里提到输入流的重载是为了说明思维惯性的问题。当和同学们讨论时,发现有一个同学是这样实现的:思路比较独特int month; streammonth; date.setMonth(month); char temp1; /读入第一个“/” streamtemp1; /舍去不要 int day; streamday; date.setDay(day); char temp2; st

24、reamtemp2; 他没有使用分隔符,而是按照顺序读取,择我所需,以一颗“平常心”对待那些分隔符,觉得这种思路比较简单明了,但当时的我不太容易想得到,因为受思维惯性的影响,一直在想如何使用分隔符,看来编程人员非常需要灵活变通和淡定的心态。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. Us

25、e an appropriate STL sorting function to sort the advertisements. The field names that can be passed into this function are email, start, close, and quantity.,仔细阅读之后知道了这个方法体的大概构架,sort函数第三个参数是个判断条件,为了避免写多个判断条件,可以使用函数对象SortBy来简化程序。代码实现:Listing Listing:sort(string field)Listing sortedList;/ a copy of t

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

27、 SortBypublic:/the default value is private!string field;SortBy(string field):field(field)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 ret

28、urn false; else if(pare(lowest)=0)/在成功的bids里选取amount最小的if(!ad1-getTopDutchBids().empty()&!ad2-getTopDutchBids().empty()&(ad1-getTopDutchBids().back()getTopDutchBids().back() return true;else return false; ;下面是lowest的第二种实现方法:在一个广告的所有bids里选取amount最小的,先拷贝一份priority_queuecopyOfBids 然后pop() 直到最后一个,即可获得最小

29、的amount./*float low1=-1.0,low2=-1.0;priority_queue copyOfBids1(ad1-getBids(),copyOfBids2(ad2-getBids();if(!copyOfBids1.empty() low1=copyOfBids1.top().getAmount();while(!copyOfBids1.empty() if(low1copyOfBids1.top().getAmount() low1=copyOfBids1.top().getAmount(); copyOfBids1.pop(); if(!copyOfBids2.emp

30、ty() 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里面,tota

31、lBids是该广告所有的bid,它存放在priority_queue里,那么这个lowest是winBids里的lowest还是totalBids里的lowest,这里我选择前者理由有二:后者的空间复杂度和时间复杂度都比前者高。因为后者是使用priority_queue 进行存储的,要取得最小amount,必须一直pop()直到最后一个元素,这提高了时间复杂度,再者不能因为比较大小就对原数据进行修改,所以必须copy一份原先的bids,这又提高了空间复杂度,所以从程序的运行效率来看应该选前者。前者更具有现实的指导意义。对于竞标,人们总想着拿最低的价格换取最多或最好的物品,广告竞标成功的最高和最

32、低价格对于下一次相同广告的竞标将具有非常好的参考价值。所以真正代码的实现时我采用前者。这提醒我们程序员编码前要做好需求分析!Listing filter(string keyword)的实现思路:实现起来和sort有点类似,同样采用函数对象的方法,难点在于remove_if用法,通过msdn上该函数的定义及对经典例子的分析,对这个函数有了进一步的认识。对msdn上经典例子的分析如下:提供程序的运行结果如图所示:再配合msdn上的解释:Eliminates elements that satisfy a predicate from a given range without disturbin

33、g the order of the remaining elements and returning the end of a new range free of the specified value.由此可见,使用remove_if,并不能把符合条件的元素删除掉,必须配合使用erase方可彻底删除。实现:Listing Listing:filter(string keyword) Listing filtedList; TheAdHasNoKeyword theAdHasNoKeyword(keyword); filtedList.objects=this-objects; Listin

34、g:Container:iterator delete_end=remove_if(filtedList.objects.begin(),filtedList.objects.end(),theAdHasNoKeyword);filtedList.objects.erase(delete_end,filtedList.objects.end(); return filtedList; TheAdHasNoKeyword和SortBy实现类似,在这里就不粘贴了。Category类重要方法的实现:findOfferings方法的分析:思路:findOfferings (int category,

35、Listing:iterator start, Listing:iterator finish, Listing &matches);该函数主要是将当前分类下所有的广告添加到Listing类型的matches中,其中start和finish是用来遍历系统中所有广告的集合advertisements,所以此方法可以这样来实现,遍历该category下所有广告的id(相当于遍历category的items属性值),对于每一个id再在advertisements中查找与此id相对应的advertisement对象,将其添加到matches中实现:for(map:iterator itercag=th

36、is-objectscategory-itemsBegin();itercag!=this-objectscategory-itemsEnd();itercag+)for(Listing:iterator iter=start;iter!=finish;iter+)if(*iter)-getNumber()=itercag-second)matches.add(*iter);break;复杂度分析:时间复杂度:设N为此分类下的广告数目,M为所有广告的数目,则复杂度为NM无空间复杂度.findOfferingsRecursive()方法的分析:思路:该方法是要实现查找当前分类下所有的广告及子分类

37、下所有的广告的功能,上面findOfferings已经实现查找当前目录下的所有广告,所以可以采用递归的方法。实现:Category* cag;cag=this-objectscategory;findOfferings(category,start,finish,matches);for(map:iterator itersub=cag-subCategoriesBegin();itersub!=cag-subCategoriesEnd();itersub+)findOfferingsRecursive(itersub-second,start,finish,matches);复杂度分析:时间

38、复杂度:设该分类的层数总共有P层,则该递归函数递归的深度为P,设每层的分类又有Q类,而findOfferings的复杂度为NM,所以findOfferingsRecursive()的复杂度为PQNM第三章 系统测试拍卖现场:按照quantity进行排序:查找含有关键字“篮球”的所有广告:显示“学习用品”类下的所有广告:对“体育用品”进行拍卖篮球:quantity=1 bid1.getAmount()=1 bid2.getAmount()=2运行结果: 乒乓球:quantity=10Bid1.getAmount()=5 Bid1.getQuantity()=3Bid2.getAmount()=6 Bid2.getQuantity()=4Bid3.getAmount()=7 Bid3.getQuantity()=5运行结果:竞标情况:Bid4.getAmount()=8 Bid4.getQua

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论