Hacettepe University Department Of Computer Engineering Bil236

Transkript

Hacettepe University Department Of Computer Engineering Bil236
Hacettepe University
Department Of Computer Engineering
Bil236 Programming Laboratory
Experiment 3
Subject
Submission Date
Due Date
Programming Environment
Advisors
Data Structures - Trees
12.3.2009
29.3.2009
Microsoft Visual C# 2008 Express Edition
Assoc. Prof. Dr. Mustafa EGE / R.A. Ahmet Selman BOZKIR
AIM
In this experiment you will have a chance to learn trees, a very important data structure concept,
and manipulating of it. In computer science, a tree is a widely-used data structure that emulates a
tree structure with a set of linked nodes. It is an acyclic and connected graph. Most of the
literatures also include the constraint that a graph's edges must be undirected to be a tree
In this work you’re expected to implement a program that manipulates the product/category tree
of amazon.com web site. You’ll be given two input files: “urunler.txt”, containing a sample
subset of categories and products of amazon.com and “islem.txt” which contains some
commands that will be executed against products/categories. A sample tree structure of
amazon.com is given below:
Amazon
Books
Computers
Home_&_Garden
Lord_of_the_rings
Textbooks
Accesories
Magazines
Medicine
Man’s_Journal
Halo_3
Software
Antivirus
Hardware
OS
Kitchen_&_Dining
Mixers
Blenders
Fashion
Norton_360
NOD_32
MixBlend
Your program will construct this structure by reading the plain text file (urunler.txt) given to
you and make some operations on this structure by reading and processing the commands in
“islem.txt”. Every command result must be outputted to “output.txt”. The filenames are
constant and your program mustn’t take any parameter at startup. However, no GUI is expected
1
from you. Therefore, your only work is to read input files, process them and reflecting the results
to output file.
EXPERIME-T
The main purpose of this experiment is improving your tree-programming skills. So your
first step will be on building a category/product tree with the records in your input file:
“urunler.txt”. You will find two different record types that have different numbers of attributes in
urunler.txt. Names of those entities are explained below:
•
urunler.txt
The category and product records are stored linearly in this plain text file and they have
different numbers of attributes separated with commas.
The format of the file is:
For categories : <name of parent item> <name of item> <type of item>
For products: <name of parent item> <name of item> <type of item> <price> <# in stock>
ame of parent item: This attribute descript parent
category of item.
ame of item:
The name of product or category
or product itself.
Type of item:
“P” stands for product
“C” stands for category.
Price:
Indicates the start-up price
of item
# in Stock:
Amount of items in stock of
Amazon.com
Category entities consist of 3 attributes while products consist of 5 attributes. Category and
product entities can be given in mixed order and there is no guarantee that any product can be
given after creation of parent category. Therefore, your logic must handle this situation. Also a
category can hold infinite number of products and categories. By the way, the root category’s
name is “Amazon” so all top level categories and products must be located under “Amazon”
category.
Your second input file, “islem.txt” consists of some commands that will process on “urunler.txt”.
Result of every operation must exist in outpu.txt. Example inputs and output will given further in
this document. Here is the list of commands:
2
RISE:
Raises the products’ prices.
RISE <category name(s)> <product name(s))> <amount to add>
Ex: RISE NOD_32 Microsoft_Mouse Books 14
Ex: RISE Software MixBlend 12
RISE command rise all the sub-items of a parent category. Also you should
consider that a product’s price can only be raised at most one time in a
command session. This means that your logic should be aware of price
update times and never allows any other price change of a product in same
command session.
DISCOU-T:
Discounts the products’ prices.
DISCOUNT <category name(s)><product name(s))><amount to discount>
Ex: DISCOUNT Halo_3 Software NOD_32 13
Ex: DISCOUNT Textbooks 12
DISCOUNT command is the reverse version of RISE command. All the
restrictions and rules are exists for the DISCOUNT command as well as
RISE.
SELL:
SELL stands for to sell one specific product or a series of products.
SELL <product name(s))> <# of products to sell>
Ex: SELL NOD_32 Microsoft_Mouse 5
SELL command stands for selling operation. It must check the stock
availability of product(s) and then sell requested numbers of good given in
command text. If the stock quantitiy of that product is lower than demand
than it must raise an error message that denotes this error.
RETUR-:
RETURN, returns the product(s) to back with specified quantitiy.
RETURN <product name(s))> <# of products to return back>
Ex: RETURN Halo_3 Microsoft_Mouse 2
RETURN command stands for refunding. It must check the selling list of
product(s) and then return requested numbers of good given in command
text. If the return quantity of that product is lower than selling than it must
raise an error message that denotes this error. Otherwise it must decrease
the selling number and return the product (s) to stock again.
LIST:
LIST, lists the contents of category in a tree-like fashion style.
LIST <category name(s))>
Ex: LIST Home_&_Garden
3
Ex: LIST Books Amazon
The original price, current price and stock number of every product must
be denoted in the syntax form of “product name [OP CP SN ]” where OP
stands for original price, CP for current price and finally SN for stock
number respectively.
REPORT:
REPORT command reports the summary and details of purchases in given
product categories.
REPORT <category name(s))>
Ex: REPORT Computers Books
REPORT command must dump all the purchased items’ information and
calculate total profit, loss and revenue. Revenue is the total money made by
selling the goods.
Here is a sample islem.txt and corresponding output:
RISE NOD_32 Microsoft_Mouse 14
SELL Kingston_1GB_RAM Norton_360 3
SELL MixBlend 4
RISE Books 5
DISCOUNT Halo_3 Software NOD_32 13
RISE Kitchen_&_Dining 9
SELL Man's_Journal 7
LIST Amazon
SELL Halo_3 13
REPORT Computers
RETURN Halo_3 4
REPORT Amazon
||| Komut: RISE NOD_32 Microsoft_Mouse 14
NOD_32 adli urune 14 lira zam yapildi. Yeni fiyati 48 lira oldu.
Microsoft_Mouse adli urune 14 lira zam yapildi. Yeni fiyati 54 lira oldu.
-----------------------------------------------------------------------------||| Komut: SELL Kingston_1GB_RAM Norton_360 3
Stokta sadece 2 adet Kingston_1GB_RAM var. Satis yapilamaz.
Norton_360 adlı üründen 3 adet satildi. Stokta 3 adet kaldi.
-----------------------------------------------------------------------------||| Komut: SELL MixBlend 4
MixBlend adlı üründen 4 adet satildi. Stokta 8 adet kaldi.
-----------------------------------------------------------------------------||| Komut: RISE Books 5
Fashion adli urune 5 lira zam yapildi. Yeni fiyati 11 lira oldu.
Man's_Journal adli urune 5 lira zam yapildi. Yeni fiyati 17 lira oldu.
Lord_of_the_Rings adli urune 5 lira zam yapildi. Yeni fiyati 29 lira oldu.
-----------------------------------------------------------------------------||| Komut: DISCOUNT Halo_3 Software NOD_32 13
Halo_3 adli urunde 13 lira indirim yapildi. Yeni fiyati 87 lira oldu.
Norton_360 adli urunde 13 lira indirim yapildi. Yeni fiyati 17 lira oldu.
NOD_32 adli urunde 13 lira indirim yapildi. Yeni fiyati 35 lira oldu.
Windows_XP adli urunde 13 lira indirim yapildi. Yeni fiyati 77 lira oldu.
Mac_OSX adli urunde 13 lira indirim yapildi. Yeni fiyati 127 lira oldu.
------------------------------------------------------------------------------
4
||| Komut: RISE Kitchen_&_Dining 9
MixBlend adli urune 9 lira zam yapildi. Yeni fiyati 52 lira oldu.
Cuisineart_HM-50 adli urune 9 lira zam yapildi. Yeni fiyati 48 lira oldu.
KithcenAid_KHB300 adli urune 9 lira zam yapildi. Yeni fiyati 90 lira oldu.
-----------------------------------------------------------------------------||| Komut: SELL Man's_Journal 7
Man's_Journal adlı üründen 7 adet satildi. Stokta 23 adet kaldi.
-----------------------------------------------------------------------------||| Komut: LIST Amazon
Amazon
|---Books
|
|---Textbooks
|
|
|---Medicine
|
|---Magazines
|
|
|---Fashion [6 11 10]
|
|
|---Man's_Journal [12 17 23]
|
|---Lord_of_the_Rings [24 29 20]
|---Computers
|
|---Software
|
|
|---Antivirus
|
|
|
|---Norton_360 [30 17 3]
|
|
|
|---NOD_32 [34 35 12]
|
|
|---Operating_Systems
|
|
|
|---Windows_XP [90 77 10]
|
|
|
|---Mac_OSX [140 127 14]
|
|
|---Halo_3 [100 87 20]
|
|---Accesories
|
|
|---Microsoft_Mouse [40 54 3]
|
|---Hardware
|
|
|---Kingston_1GB_RAM [40 40 2]
|---Home_&_Garden
|---Kitchen_&_Dining
|---Blenders
|---MixBlend [43 52 8]
|---Mixers
|---Cuisineart_HM-50 [39 48 3]
|---KithcenAid_KHB300 [81 90 4]
-----------------------------------------------------------------------------||| Komut: SELL Halo_3 13
Halo_3 adlı üründen 13 adet satildi. Stokta 7 adet kaldi.
-----------------------------------------------------------------------------||| Komut: REPORT Computers
Computers ürün kategorisine ait satışlar
1.Norton_360 [3 adet]
2.Halo_3 [13 adet]
-----------------------------------Toplam Kar: 0 Zarar:169 Toplam Ciro:1221
-----------------------------------------------------------------------------||| Komut: RETURN Halo_3 4
Halo_3 adlı üründen 4 adet geri iade yapıldı. Stokta 11 adet var.
-----------------------------------------------------------------------------||| Komut: REPORT Amazon
Amazon ürün kategorisine ait satışlar
1.Norton_360 [3 adet]
2.MixBlend [4 adet]
3.Man's_Journal [7 adet]
4.Halo_3 [9 adet]
-----------------------------------Toplam Kar: 35 Zarar:117 Toplam Ciro:1164
5
GE-ERAL RULES & LIMITATIO-S:
•
•
•
•
•
Your program should use OOB paradigm, so you must use “classes” and “interitance”
and even “polymorphism”. Using structures are prohibited.
Your programming approach can’t be based on collecting the data in linear form. You
have to make a tree based data structure.
Your program may only use System, System.IO and System.Collections built-in
namespace libraries. Usage of other namespaces is prohibited.
You cannot use any third party predefined C# data structure code or library in your
project.
“urunler.txt” and “islem.txt” files will be consisting of different kinds of command texts
and some of those commands may be invalid. So your program must handle those invalid
requests and print or append an error message to output file as well as console
environment.
-OTES:
•
•
•
SAVE all your work until the experiment is graded.
The assignment must be original, INDIVIDUAL work. Downloaded or modified source
codes will be considered as cheating. Also the students who share their works will be
punished in the same way.
You can ask your question via course’s news group.
news://news.cs.hacettepe.edu.tr/dersler.bil236
SUBMISSO-S:
•
•
•
•
•
The experiment code will be tested in Microsoft Visual C # 2008 Express Edition. This
package can be downloaded from Microsoft’s site. Please ensure that your code is well
working. If your program crashes at the startup it will be graded with -25 points.
Your submission will be in the format below
<Bil236_0809_3_StudentID>
|-- report
|-- report.pdf
|-- source
|-- StudentID.sln
|-- StudentID
|-- StudentID.csproj
|-- StudentID.csproj.user
|-- Amazon.cs
|-- Properties
|-- AssemblyInfo.cs
You
have
to
use
“Online
Experiment
Submission
System”.
http://submit.cs.hacettepe.edu.tr Other type of submissions especially by e-mail WILL
NOT BE ACCEPTED.
Submission deadline is 29.3.2009, 17.05 pm. -o further extension will be given!!!
Do not forget to sign the "submission paper" after you submit your experiment.
6

Benzer belgeler