📄 2006年上半年软件设计师下午试题.htm
字号:
//订单列表类<BR> private:<BR> vector<order>orders;<BR> public:<BR> OrderList():<BR> //Begin()返回指向订单列表第一个元素的迭代器(指针)<BR> virtual
vector<Order>::iterator
OrderList::Begin();<BR> //End()返回指向订单列表最后一个元素之后的迭代器(指向一个不存在的元素)<BR> virtual
vector<order>::iterator orderList::End();<BR> void addOrder(Order
t); //在订单列表中加入一份订单<BR> //其他成员省略<BR> }; </P>
<P style="MARGIN-TOP: 0px"> Class
SalesSystem{ <BR> private:<BR> ProductList
catalog; //产品目录<BR> OrderList
sales; //订单列表<BR> public:<BR> SalesSystem();<BR> void
statistic(); //统计所有产品的定购情况 <BR> //其他成员省略<BR> } ; </P>
<P style="MARGIN-TOP: 0px"> //在订单中查找识别码为tid的产品的定购数量,若该产品没有被定购,则返回0<BR> int
Order::getOrderedAmount(string tid)<BR> { for(int
k=0;k<items.size();k++){<BR> if (__(1)__=tid) <BR> return
__(2)__;<BR> }<BR> return 0;<BR> } </P>
<P
style="MARGIN-TOP: 0px"> //方法statistic()依次统计产品目录中每个产品的订购总量,并打印输出<BR> //每个产品的识别码、描述、订购总量和订购金额<BR> void
SalesSystem::statistic()<BR> { unsigned iht
k,t,ordered_qty.p; <BR> vector<Order>::iterator it;Product
p;<BR> tout<<"产品识别码\t描述\t\t定购数量\t金额"<<endl;<BR> for(k=0;k<catalog.getProductAmount();k++){ //遍历产品列表:<BR> p
= __(3)__;
//从产品列表取得一件产品信息存入变量p<BR> ordered_qty:0:<BR> //通过迭代器变量it遍历订单列表中的每一份订单<BR> for(it=sales.Begin();__(4)__;it++{<BR> //根据产品识别码获得产品p茬当前订单中被定购的数量<BR> t
__(5)__ (p.getProductld());<BR> ordered_qty +=
t;<BR> } <BR> cout<<p.getProductld()<<"\t\t"<<p.getProductDescriptiOn<)<<"\t\t";<BR> cout<<ordered_qty<<"\t\t"<<p.getProductPrice()*ordered_qty<<endl;<BR> }<BR> }
</P>
<P
style="MARGIN-TOP: 0px"><B>试题七</B>(15分) <BR> 阅读下列说明、图以及Java程序,将应填入__(n)__处的字句写在答题纸的对应栏内。<BR><B>[说明] </B><BR> 某订单管理系统的部分UML类图如图7-1所示
</P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 6px" align=center><IMG height=227
src="2006年上半年软件设计师下午试题.files/gc06_1x7.gif" width=607 border=0><BR>图7-1
订单管理系统的部分类图 </P>
<P
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"> 图7-1中,Product表示产品,ProductList表示所销售产品的列表,Order表示产品订单,0rderltem表示产品订单中的一个条目,OrderList表示订单列表,SalesSystem提供订单管理系统的操作接口。各个类的部分属性和方法说明如表7-1所示。
</P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 5px" align=center>表7-1 </P>
<TABLE cellSpacing=0 cellPadding=2 width=756 border=1>
<TBODY>
<TR>
<TD align=middle width=103>
<P style="MARGIN-TOP: 0px">类 </P></TD>
<TD align=middle width=216>
<P style="MARGIN-TOP: 0px">成员 </P></TD>
<TD align=middle width=417>
<P style="MARGIN-TOP: 0px">说明 </P></TD></TR>
<TR>
<TD width=103>
<P style="MARGIN-TOP: 0px">ProductList </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">ArrayList(Product) products </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px"> </P></TD></TR>
<TR>
<TD width=103 rowSpan=4>
<P style="MARGIN-TOP: 0px">Product String </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">String code </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">产品编号 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">description </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">产品描述 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">double price </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">产品单价 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">Boolean equals(Object object) </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">若两个产品相同则返回true,否则返回false </P></TD></TR>
<TR>
<TD width=103 rowSpan=3>
<P style="MARGIN-TOP: 0px">Orderltem </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">Product product </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">订单项中的产品 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">int quantity </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">产品的订购数量 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">Product getProduct() </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">获取订单项中的产品 </P></TD></TR>
<TR>
<TD width=103>
<P style="MARGIN-TOP: 0px">Order </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">ArrayList(Orderlten) items </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">订单中包含的订单项 </P></TD></TR>
<TR>
<TD width=103 rowSpan=3>
<P style="MARGIN-TOP: 0px">OrderList </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">ArrayList(Order)orders </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">订单 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">void addOrder(0rder order) </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">向订单列表中添加新订单 </P></TD></TR>
<TR>
<TD width=216>
<P style="MARGIN-TOP: 0px">int getNumberOfOrders() </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">获取订单列表中的订单总数 </P></TD></TR>
<TR>
<TD width=103 rowSpan=3>
<P style="MARGIN-TOP: 0px">SalesSystem </P></TD>
<TD width=216>
<P style="MARGIN-TOP: 0px">ProductList catalog </P></TD>
<TD width=417>
<P style="MARGIN-TOP: 0px">产品目录 </P></TD></TR>
<TR>
<TD width=216>OrderList sales</TD>
<TD width=417>订单列表</TD></TR>
<TR>
<TD width=216>void statistic()</TD>
<TD width=417>依次统计产品目录中每个产品的订购总量,并打印
出每个产品的编号、说明、订购总量和订购金额</TD></TR></TBODY></TABLE>
<P
style="MARGIN-TOP: 6px"> 可以使用类java.util。ArrayList<E>来实现对象的聚集关系,如图7-1中OrderList与Order之间的聚集关系。<BR> for-each循环提供了一种遍历对象集合的简单方法。在for-each循环中,可以指定需要遍历的对象集合以及用来接收集合中每个元素的变量,其语法如下;<BR> for(用来接收集合中元素的变量:需要遍历的对象集合)<BR> 如果要使用for-each循环来遍历对象集合,那么包含该对象集合的类必须实现接口java.util.Iterable<T>。<BR> Java程序7-1和Java程序7-2分别给出了类OrderList和方法statistic的Java代码。
</P>
<P style="MARGIN-TOP: 6px"><B>[Java程序7-1]</B><BR> import
java.util.*;<BR> public class OrderList __(1)__ {<BR> private
ArrayList<Order> orders;<BR> public OrderListO {<BR> this.orders =
new ArrayList(Order) 0;<BR> }<BR> public void addOrder(Order order)
{<BR> this.orders, add (order);<BR> }<BR> public Iterator<Order>
iteratorO {<BR> return __(2)__;<BR> }<BR> public int getNunberOfOrders()
{<BR> return this.orders, size();<BR> }<BR> } </P>
<P style="MARGIN-TOP: 6px"><B>[Java程序7-2]<BR> </B>import
java.util.*;<BR> public class SalesSystem {<BR> private ProductList
catalog;<BR> private OrderList sales;<BR> private static PrintWriter stdOut
= new PrintWriter(System.out,true);<BR> public void
statistic(){<BR> for(Product product : __(3)__{<BR> int number = 0;
’<BR> for(Order order : __(4)__ {<BR> for(__(5)__ :
order){<BR> if<product.equals(item.getProduct()))<BR> numbe r +=
item.getQuantity();<BR> }<BR> }<BR> stdOut.println(product.getCode()
+ " "<BR> + product.getDescription() + " "<BR> + number + " " +
number *product.getPrice());<BR> }<BR> }<BR> //其余的方法未列出<BR> } </P>
<P align=center><A
href="http://www.oldchild.net/stgc.htm">回目录</A> <A
href="http://www.oldchild.net/">老顽童整理校对</A> 2006年8月 </P></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -