题意:
玩具公司请你设计一款app,用于管理公司手机的弹珠、分析数据和阐释它们多样的分布。你需要显示每个成员的弹珠数、每种大小的弹珠数、每种样式的弹珠数等。 俱乐部一共有7名成员,分别是Scott Malcolm Tony Kevin Julia John和Paul。游戏只统计这七名成员的弹珠信息。每名成员的弹珠分别存储在计算机化的集合中,方便使用。
解析:
背景:
每颗弹珠存储以下信息:直径以毫米作为单位(double型)、花纹(enumeration类型)、材料(enumeration类型)、新旧(bool型)。弹珠集合按照直径的升序排列存储信息。 你将收到一个存储俱乐部收藏的弹珠基本信息的txt文件。
任务:
回答以下问题:
a.对于七名成员的弹珠集合,你将使用哪种底层数据结构(数组还是链表)?说明原因。
b.对于七名成员的弹珠集合,你将使用哪种抽象数据类型(二叉树、一般树、数组、栈、优先队列、双端队列、集合、列表等)?说明原因。
c.对于俱乐部的弹珠集合,你将使用哪种底层数据结构(数组还是链表)?说明原因。
d.对于俱乐部的弹珠集合,你将使用哪种抽象数据类型(二叉树、一般树、数组、栈、优先队列、双端队列、集合、列表等)?说明原因。
完成下列函数:
1、get_member()——查找俱乐部成员——以一名成员名字为输入,在MEMBERS数组中查找并返回索引值(数组不存在该名字返回 -1)—— 调用strcmp()函数
2、add_existing()——加入一颗弹珠到成员弹珠集合——以一名成员的非空弹珠集合地址和一颗弹珠为输入,按直径升序把该弹珠加入该成员的弹珠集合中 —— 利用指针插入新结点
3、add_marble()——加入一颗弹珠到俱乐部弹珠集合——以一名成员的名字和弹珠的一颗弹珠为输入,如果该成员没有这个弹珠就把成员名字和弹珠存入club集合中,否则调用add_existing()函数
4、process_category()——统计与分类——以一名成员的弹珠集合为输入,接受以下4个参数分别对应不同的分类操作,返回
‘t’——计算弹珠集合的总数
‘m’——计算不同材质的弹珠数量——材质有plastic,wooden,glass之别
‘c’——计算不同花纹的弹珠数量——花纹有plain,swirled,cats-eye之别
‘a’——计算新老弹珠的数量——弹珠有old,new之别
5、show_graph()——可视化展现统计结果——以上述4个参数为输入,输出一串字符表示数量大小,分别统计所有类型并输出最多的成员名字
涉及知识点:
抽象数据类型,数组,文件读取
更多可加微信讨论
微信号:tiamo-0620
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