塔斯马尼亚大学KIT107课业解析

题意:

  玩具公司请你设计一款app,用于管理公司收集的弹珠、分析数据和阐释它们多样的分布。你需要显示每个成员的弹珠数、每种大小的弹珠数、每种样式的弹珠数等。 俱乐部一共有7名成员,分别是Scott Malcolm Tony Kevin Julia JohnPaul。游戏只统计这七名成员的弹珠信息。每名成员的弹珠分别存储在计算机化的集合中,方便使用。

解析: 

  背景:

  每颗弹珠存储以下信息:直径以毫米作为单位(double型)、花纹(enumeration类型)、材料(enumeration类型)、新旧(bool型)。弹珠集合按照直径的升序排列存储信息。 你将收到一个存储俱乐部收藏的弹珠基本信息的txt文件。

  任务:

  回答以下问题:

  a.对于七名成员的弹珠集合,你将使用哪种底层数据结构(数组还是链表)?说明原因。

  b.对于七名成员的弹珠集合,你将使用哪种抽象数据类型(二叉树、一般树、数组、栈、优先队列、双端队列、集合、列表等)?说明原因。

  c.对于俱乐部的弹珠集合,你将使用哪种底层数据结构(数组还是链表)?说明原因。

  d.对于俱乐部的弹珠集合,你将使用哪种抽象数据类型(二叉树、一般树、数组、栈、优先队列、双端队列、集合、列表等)?说明原因。

  完成下列函数: 

  1get_member()——查找俱乐部成员——以一名成员名字为输入,在MEMBERS数组中查找并返回索引值(数组不存在该名字返回 -1—— 调用strcmp()函数

  2add_existing()——加入一颗弹珠到成员弹珠集合——以一名成员的非空弹珠集合地址和一颗弹珠为输入,按直径升序把该弹珠加入该成员的弹珠集合中 —— 利用指针插入新结点

  3add_marble()——加入一颗弹珠到俱乐部弹珠集合——以一名成员的名字和弹珠的一颗弹珠为输入,如果该成员没有这个弹珠就把成员名字和弹珠存入club集合中,否则调用add_existing()函数

  4process_category()——统计与分类——以一名成员的弹珠集合为输入,接受以下4个参数分别对应不同的分类操作,返回

       ‘t’——计算弹珠集合的总数

       ‘m’——计算不同材质的弹珠数量——材质有plastic,wooden,glass之别

       ‘c’——计算不同花纹的弹珠数量——花纹有plain,swirled,cats-eye之别

       ‘a’——计算新老弹珠的数量——弹珠有old,new之别

  5show_graph()——可视化展现统计结果——以上述4个参数为输入,输出一串字符表示数量大小,分别统计所有类型并输出最多的成员名字

涉及知识点:

抽象数据类型,数组,文件读取

更多可加微信讨论

微信号:ITCSdaixie

KIT107 Programming 2019
Assignment 2
Due Date
The assignment is due at 3PM Wednesday September 18th 2019
Background
Marbles! Large ones, medium-sized ones, small ones. Cats-eye ones, plain ones,
swirly ones. Glass ones, wooden ones, plastic ones. Old ones, new ones. Marbles!
A Toy Company has asked you to develop an app to manage a club’s collection of
marbles, to analyse the data and illustrate various distributions. You will need to
show the number of marbles per member, the number per size and style, et cetera.
There are seven members in the Club: Scott, Malcolm, Tony, Kevin, Julia, John, and
Paul. Only marbles from these seven members will be stored. Marbles belonging to
others should be ignored. All marbles belonging to the same member should be
stored in the computerised collection together for ease of access.
Each marble should have its diameter in millimetres (a double), content (an
enumeration), material (an enumeration), and age (a bool) stored. The collection of
marbles for each member should be stored in increasing order of diameter (smallest
first).
2/9
A text file exists with the basic data of the marbles found at the Clubhouse. I will
give you code to read this into your program. You will need to illustrate (using a bar
chart and/or some print outs) various information.
a Which underlying data structure (array or linked-list) will you use as a basis to
model the collection of marbles for each of the seven members? In two–three
sentences, justify your answer.
b Which kind of abstract data type (binary tree, general tree, array, stack, priority
queue, double-ended queue, set, list, etc.) would you use to model the collection
of marbles for each of the members? In two–three sentences, justify your
answer by indicating the functionality required.
c Which underlying data structure (array or linked-list) will you use as a basis to
model the collection of members? In two–three sentences, justify your answer.
d Which kind of abstract data type (binary tree, general tree, array, stack, priority
queue, double-ended queue, set, list, etc.) would you use to model the collection
of members? In two–three sentences, justify your answer by indicating the
functionality required.
The types required to implement this include the following:
typedef struct {
char *name;
collection marbles;
} member;
typedef member members;
#define NUM_MEMBERS 7
const char *MEMBERS[] = { "Scott", "Malcolm", "Tony",
"Kevin", "Julia", "John", "Paul" };
members club;
In other words, you must create a struct (called member in the above example)
which combines the member name with your answer to (a) above to represent the
collection of marbles for that particular member, and then use that as a basis for
another type (used to create a variable called club in the above example) which uses
your answer to (c) above to create a collection of members.
A marble is defined as follows:
struct marble_int {
double diameter;
content look;
material made_of;
bool new;
};
3/9
typedef struct marble_int *marble;
and you may assume the existence of those types and the following types and
functions:
typedef enum {plain, swirled, cats_eye} content;
typedef enum {glass, wooden, plastic} material;
void init_marble(marble *e, double d, content c,
material m, bool n);
double get_diameter(marble e);
material get_look(marble e);
content get_material(marble e);
bool get_age(marble e);
void set_diameter(marble e, double d);
void set_look(marble e, content c);
void set_material(marble e, material m);
void set_age(marble e, bool n);
char *to_string(marble e);
A Visual Studio project is available on MyLO for you to download and use as a
starting point. This comprises the following files:
• marble.h and marble.c — the Marble ADT as specified above. These
files are complete;
• assig_two219.c — the file which contains the main() function and
other functions which implement the required task (including reading marbles
from the text file).
e You must complete assig_two219.c
Start by adding the collection and members types from above. You may
add other types, constants and variables as necessary.
Then, complete the following functions:
• get_member() — which takes a member name, locates it in the
MEMBERS array and returns its index (or –1 if it is not present);
• add_existing() — which takes the address of a non-empty
collection of marbles for a particular member and an marble to add to
that member’s collection and which adds the marble to the collection in
increasing order of diameter;
• add_marble() — which takes the name of a member and a marble
and which either stores the name and marble in club if there are none
for that member yet, or which calls add_existing() to do so if there
are already marbles for that member;
• process_category() — which takes a collection of marbles for a
particular member, a letter indicating which category should be
processed, and an ‘int’ indicating which value in the category the
processing should occur for. Possible letters, values and actions are:
4/9
o 't' — calculate the total number of marbles in the collection;
o 'm' — calculate the number of marbles of that particular
material (plastic, wooden, or glass);
o 'c' — calculate the number of marbles of that particular content
value (plain, swirled, or cats-eye); and
o 'a' — calculate the number of marbles of that particular age
value (old or new).
The answer (an int) should be returned.
• show_graph() — which takes a letter (see above), a string description
of the output to be displayed (see sample output), and a value for the
category (see above) or –1 if the category is total — and which displays
the histogram of, and totals (which can be obtained using
process_category() for each member); and
• main() — which should initialize club, call read_in_data(), and
call show_graph().
If your answer to (a) or (c) above is a linked-list then you will also need to write
node.h and node.c and add them to the project.
The project also contains the data file. This is just a text file which can be opened and
read with most applications. It contains details of marbles found in the Clubhouse,
but sometimes there are marbles which were left there by previous members.
Program specification
First you must obtain the marbles from a text file. The data must be stored in
appropriate collections. At the top level there should be 7 members and for each there
should be a collection of marbles (stored in ascending order of diameter).
As a marble is read from the file, the details should be checked for validity. If invalid
— i.e. not belonging to a current member — it should be counted, but not included in
the collection. If valid, its data should be stored in its members part of the collection.
Once the data have been read in and stored in the collections, output should be
provided as specified in the preceding section.
A histogram illustrating the results per member should be displayed with one asterisk
printed for every 25 marbles (other than for diameter — see sample output below).
Each histogram should state the count of ‘invalid’ marbles beneath it.
The output of your program should look something like the following (with the bold
added in this document for emphasis only):
5/9
Marbles -- total number of
Scott | ************************************************************************ 1822
Malcolm | ************************************************************************** 1858
Tony | **************************************************************************** 1911
Kevin | ************************************************************************** 1867
Julia | ************************************************************************** 1867
John | ************************************************************************* 1846
Paul | ***************************************************************************** 1942
Invalid marbles: 1887
And the most common member for total number of marbles is......Paul!
Marbles -- glass
Scott | ************************ 624
Malcolm | ************************* 634
Tony | ************************ 613
Kevin | ************************* 643
Julia | *********************** 594
John | *********************** 599
Paul | ************************* 648
Invalid marbles: 1887
And the most common member for glass marbles is......Paul!
Marbles -- wooden
Scott | *********************** 598
Malcolm | ************************ 622
Tony | ************************* 643
Kevin | *********************** 594
Julia | ************************** 664
John | ************************* 638
Paul | *************************** 681
Invalid marbles: 1887
And the most common member for wooden marbles is......Paul!
Marbles -- plastic
Scott | ************************ 600
Malcolm | ************************ 602
Tony | ************************** 655
Kevin | ************************* 630
Julia | ************************ 609
John | ************************ 609
Paul | ************************ 613
Invalid marbles: 1887
And the most common member for plastic marbles is......Tony!
Marbles -- solid colour
Scott | *********************** 598
Malcolm | ************************* 628
Tony | ************************ 623
Kevin | ************************* 631
Julia | *********************** 581
John | *********************** 587
Paul | ************************** 664
Invalid marbles: 1887
And the most common member for solid colour marbles is......Paul!
6/9
Marbles -- swirled colour
Scott | *********************** 575
Malcolm | ************************ 619
Tony | ************************ 614
Kevin | ************************ 617
Julia | ************************* 642
John | ************************ 620
Paul | ********************** 570
Invalid marbles: 1887
And the most common member for swirled colour marbles is......Julia!
Marbles -- cats_eye pattern
Scott | ************************* 649
Malcolm | ************************ 611
Tony | ************************** 674
Kevin | ************************ 619
Julia | ************************* 644
John | ************************* 639
Paul | **************************** 708
Invalid marbles: 1887
And the most common member for cats_eye pattern marbles is......Paul!
Marbles -- old
Scott | ************************************ 911
Malcolm | ************************************** 973
Tony | ************************************* 944
Kevin | ************************************** 950
Julia | ************************************ 914
John | ************************************* 930
Paul | **************************************** 1010
Invalid marbles: 1887
And the most common member for old marbles is......Paul!
Marbles -- new
Scott | ************************************ 911
Malcolm | *********************************** 885
Tony | ************************************** 967
Kevin | ************************************ 917
Julia | ************************************** 953
John | ************************************ 916
Paul | ************************************* 932
Invalid marbles: 1887
And the most common member for new marbles is......Tony!
Program Style
The program you write for this assignment must be contained in five files as follows:
• marble.h and marble.c for managing a marble;
• node.h and node.c for nodes of linked lists (if appropriate);
• assig_two219.c for the main algorithm which controls the reading of the
data, the management of the collections, the calculation of the results, and the
7/9
display of the histogram. No function should be longer than about half a
screen-full or so of code.
Your program should follow the following coding conventions:
• const variable identifiers should be used as much as possible, should be
written all in upper case and should be declared before all other variables;
• #defined symbols should only be used for constant values if const is
inappropriate, for example the size of an array.
• global variables should be used sparingly with parameter lists used to pass
information in and out of functions.
• local variables should only be defined at the beginning of functions and their
identifiers should start with a lower case letter;
• every if and if-else statement should have a block of code (i.e.
collections of lines surrounded by { and }) for both the if part and
the else part (if used)
• every do, for, and while loop should have a block of code (i.e. {}s)
• the keyword continue should not be used;
• the keyword break should only be used as part of a switch statement;
• opening and closing braces of a block should be aligned;
• all code within a block should be aligned and indented 1 tab stop (or 4 spaces)
from the braces marking this block;
• commenting:
o There should be a block of header comment which includes at least
 file name
 student name
 student identity number
 a statement of the purpose of the program
 date
o Each variable declaration should be commented
o There should be a comment identifying groups of statements that do
various parts of the task
o Comments should describe the strategy of the code and should not
simply translate the C into English
What and how to submit
What to submit
You must make both a paper and an electronic submission.
Paper submission
• A paper cover page (blanks can be collected from the Information and
Communications Technology Discipline Help Desk and downloaded from
MyLO).
• Written answers to parts (a)–(d) above.
• A landscape oriented print-out of assign_two219.c and any other
program files you have added to the solution. Your assignment will not be fully
marked unless these are present.
8/9
Electronic submission
• You should submit the entire Visual Studio project folder compressed as a ZIP
file.
How to submit
Paper submission
• Firmly staple together all of the required documents (with the signed cover
page on top) and place them in the appropriate submissions box near the ICT
Help Desk.
Electronic submission
• You should ZIP the Visual Studio project folder and then submit it to the
“Assignment 2” assignment drop-box on KIT107’s MyLO site.
Marking scheme

3
3

6
2
2

2
2
3
1
4

1
1
2
1
1
2

4
4
4
4
4
4
4
4

4



9/9
Plagiarism and Cheating:
Practical assignments are used in the ICT discipline for students to both reinforce and
demonstrate their understanding of material which has been presented in class. They
have a role both for assessment and for learning. It is a requirement that work you
hand in for assessment is substantially your own.
Working with others
One effective way to grasp principles and concepts is to discuss the issues with your
peers and/or friends. You are encouraged to do this. We also encourage you to discuss
aspects of practical assignments with others. However, once you have clarified the
principles, you must express them in writing or electronically entirely by yourself. In
other words you must develop the algorithm to solve the problem and write the
program which implements this algorithm alone and with the help of no one else
(other than staff). You can discuss the problem with other students, but not how to
solve it.
Cheating
• Cheating occurs if you claim work as your own when it is substantially the
work of someone else.
• Cheating is an offence under the Ordinance of Student Discipline within the
University. Furthermore, the ICT profession has ethical standards in which
cheating has no place.
• Cheating involves two or more parties.
o If you allow written work, computer listings, or electronic version of
your code to be borrowed or copied by another student you are an
equal partner in the act of cheating.
o You should be careful to ensure that your work is not left in a situation
where it may be stolen by others.
• Where there is a reasonable cause to believe that a case of cheating has
occurred, this will be brought to the attention of the unit lecturer. If the
lecturer considers that there is evidence of cheating, then no marks will be
given to any of the students involved. The case will be referred to the Head of
the Discipline of ICT for consideration of further action.
Julian Dermoudy, August 27th 2019.
Version 1: 19/8/2019
Version 2: typographical corrections  


51作业君 51作业君

扫码添加客服微信

添加客服微信: IT_51zuoyejun