辅导讲解C cluster、 C structure 数据程序讲解,讲解C语言数据、讲解留学生CAssignment 调试C/C++编程
- 首页 >> C/C++编程KIT107 Programming 2018
Assignment 2
Due Date
The assignment is due at 3PM Wednesday September 19th 2018
Background
Ah, the Donald. Everyone’s favourite President. A modern politician who shares his,
um, ‘thoughts’ with us each day via Twitter. You could follow his thoughts too
(@realdonaldtrump) but let’s face it, you’ve got better things to do. Like this
assignment… So I’ll do it for you.
I’ve archived my favourite 4000ish President Trump tweets into a single text file.
That’s all of them from 30/12/’16 up to 14/8/’18. The file consists of one tweet per
line; each tweet consists of the date and time, a tab character, and then the text of the
tweet.
You will need to store the collection of tweets in monthly clusters (January–
December) and within each cluster the tweets should be stored in the order they are
added (i.e. first ones at the front, last ones at the back). You will need to provide
some summary data (e.g. number of tweets per month, total number of tweets), and an
ability to display all tweets containing a certain string, e.g. “fake news” or “dog”, or
for a certain month.
a Which underlying data structure (array or linked-list) will you use as a basis to
model the collection? 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? 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 cluster of tweets for each month? In two–three sentences, justify
your answer.
2/7
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 cluster of
tweets for each month? In two–three sentences, justify your answer by
indicating the functionality required.
The types required to implement this include the following:
typedef ??? cluster;
typedef struct {
char *name;
cluster tweets;
} month;
typedef ??? collection;
collection archive;
In other words, you must create a struct (called month in the above example)
which combines the month’s name with your answer to (c) above to represent the
cluster of tweets for that particular month, and then use that as a basis for another type
(used to create a variable called archive in the above example) which uses your
answer to (a) above to create a collection of months. Therefore, you must
define both cluster and collection.
A tweet is defined as follows:
struct tweet_int {
char date[30];
char text[300];
};
typedef struct tweet_int *tweet;
and you may assume the existence of those types and the following functions:
void init_tweet(tweet *tp, char *t_name, char *t_text);
char *get_date(tweet t);
char *get_text(tweet t);
void set_date(tweet t, char *t_name);
void set_text(tweet t, char *t_text);
char *to_string(tweet t);
A Visual Studio project is available on MyLO for you to download and use as a
starting point. This comprises the following files:
• tweet.h and tweet.c — the Tweet ADT as specified above. These files
are complete;
• assig_two218.c — the file which contains the main() function and
other functions which implement the required task (including reading tweets
from the text file).
e You must complete assig_two218.c by adding the month, cluster, and
collection types from above, the archive variable (which may be
defined globally), and also functions to store tweets read from the file in your
3/7
collection and to search and display the results. Function stubs are already
present; you must complete these and may add others.
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
with most applications.
Program specification
First you must obtain the from a text file. The data must be stored in appropriate
collections. At the top level there should be 12 months and for each there should be a
cluster of the tweets (stored in the order encountered).
As a tweet is read from the file, the tweet should be stored in the appropriate
collection and cluster (depending upon the month).
Once the data have been read in and stored in the collections, summary information
(see below) should be provided and the user should be prompted to enter a search
string. All tweets containing that search string — case insensitive — should then be
displayed in order or month (but regardless of year) and the number of tweets
displayed should should be printed. Hint: the code contains a function, lower(), to
convert text to lower-case so that case-insensitive comparison may be made. The
comparison can be made using strstr() which looks for its second parameter
within its first.
The output of your program should look something like the following:
4/7
Program Style
The program you write for this assignment must be contained in five files as follows:
• tweet.h and tweet.c for managing a tweet;
• node.h and node.c for nodes of linked lists (if appropriate);
5/7
• assig_two218.c for the main algorithm which controls the reading of the
data, the management of the collections, the searching, and the display of the
results. There should be at least three functions excluding
the main() function within this file. 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 be used for constant values if const is
inappropriate
• 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).
• Written answers to parts (a)–(d) above.
• A landscape oriented print-out of assig_two218.c and any other program
files you have added to the solution. Your assignment will not be fully marked
unless these are present.
6/7
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
Task/Topic Maximum
mark
Design
ADTs chosen wisely 3
Data structures correct and justified 3
Program operates as specified
node.c correctly completed (if required, or array equivalent) 6
assig_two218.c correctly completed —
• initialise_archive() to initialise the archive variable 2
• add_existing() to
o add a tweet to a non-empty cluster 2
o in first-in-first-out order 2
• add_tweet() to
o add a tweet to an empty cluster 3
o call add_existing() to add a tweet to a non-empty cluster 1
• show_summary() to display the summary for menu option 1 5
• show_month() to display all relevant tweets for menu option 2 4
• show_selection() to display all relevant tweets for menu option 3 5
Program Style
Does not unnecessarily repeat tests or have other redundant/confusing code 4
Uses correctly the C naming conventions 4
Alignment of code and use of white space makes code readable 4
Always uses blocks in branch and loop constructs 4
Meaningful identifiers 4
Variables defined at the start of functions 4
Header comments for the program (author, date etc.) 4
Each variable declaration is commented 4
Comments within the code indicate the purpose of sections of code (but DO NOT just duplicate
what the code says)
4
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
7/7
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
School for consideration of further action.
Julian Dermoudy, August 20th 2018.