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 project… 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.
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 ple) 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 ple) 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
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:
image.png
image.png
Program Style
The program you write for this project 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);
· 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 project will not be fully marked unless these are present.
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 “project 2” project 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
·