Skip to main content
留学咨询

辅导案例-KIT107-Assignment 2

By May 15, 2020No Comments

1/10 KIT107 Programming 2020 Assignment 2 Due Date The assignment is due at 3PM Wednesday April 29th 2020 Background Yoyos! Thought to be invented in China at least 2500 years ago, these were a huge worldwide craze in many centuries — most recently perhaps in the 1970s. Some 1970s yoyos are shown below. You’ve been asked to measure the craze across the world, looking at where manufacturing started through to markets large and small. You need to develop an app to store the time-series data, to analyse it, and to illustrate various distributions. You will need to show the number of yoyos sold per country (in alphabetical order of country name) in a bar graph which also shows the country with the maximum sales, the accumulated number of sales for all countries at a specified week of the sales period, and time-series data (with data displayed in a table of columns from earlier dates on the left to later dates on the right) for all countries you name. See the section entitled Program Specification for details. 2/10 The data is organised by country (and is presented in alphabetical order) and by ‘date’ (ascending order of week number and year). For each week the data value is a cumulative number of yoyos sold (in hundreds) for that country. You don’t know how many weeks of sales has been recorded nor how many countries yoyo sales have been registered in. Regardless, you will only store the country if there are yoyo sales in that country, and, you will not store weeks of data prior to any yoyo sales in that country. A text file exists with the required data in it. I will give you code to read this into your program. Based only on the information above: a Which underlying data structure (array or linked-list) will you use as a basis to model the collection of sales for each of the countries? 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 sales for each of the countries? 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 countries? 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 countries? In two–three sentences, justify your answer by indicating the functionality required. To implement this you would need to define the following: typedef struct { char country_name[35]; collection sales; } country; countries craze; and hence, you must create a struct (called country in the above example) which combines the country name with your answer to (a) above to represent the collection of sales for that particular country, and then use that as a basis for another type (used to create a variable called craze in the above example) which uses your answer to (c) above to create a collection of countries. In other words, given the linked-list node from lectures: struct node_int; typedef struct node_int *node; struct node_int { void *data; 3/10 node next; }; you would either define collection and/or countries as a linked-list, e.g. typedef node collection; and/or typedef node countries; or you would define collection and/or countries as an array, e.g. typedef country countries[200]; and/or typedef sale collection[200]; A sale is defined as follows: struct sale_int { char *date; int num_sold; }; typedef struct sale_int *sale; and you may assume the existence of all types (except collection and countries) and the following types and functions: void init_sale(sale *s, char *d, int n); char *get_date(sale s); int get_num_sold(sale s); void set_date(sale s, char *d); void set_num_sold(sale s, int n); char *to_string(sale s); A Visual Studio project is available on MyLO for you to download and use as a starting point. (If you are not using Visual Studio, then just grab the source files from within the folder.) This starting point comprises the following files: • node.h and node.c — the Node ADT from lectures as the building blocks for linked lists (should you need them). These files are complete; • sale.h and sale.c — the Sale ADT as specified above. These files are complete; • assig_two120.c — the file which contains the main() function and other functions which implement the required task (including reading sales from the text file). e You must complete assig_two120.c Start by adding the collection and countries types from above. You may add other types, constants and variables as necessary. Then, complete the missing functionality. 4/10 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 sales. Program specification First you must obtain the sales from a text file. The data must be stored in appropriate collections. At the top level there will be a collection of an unknown number of countries and for each country there should be a collection of an unknown number of time-stamped sales (stored in ascending order of time). As a sales datum is read from the file, the details should be checked. If there have been no sales, then it should not be included in the collection. If positive, its data should be stored in its country’s part of the collection (adding that country to the collection if it is the first actual sale encountered for that country). Once the data have been read in and stored in the collections, the following should occur: i. A histogram (bar chart) illustrating the sales per country at the end of the sales period should be displayed with one asterisk printed for every 3500 yoyos. Each bar should name the country and indicate the number of sales. At the end of the histogram, your program should state the name of the country which has sold the most yoyos together with the number of sales. You can assume that this value is unique. ii. The user should enter a string containing a partial/whole country name. You should then search the collection extracting each country which contains the partial/whole country name in its name. For each matching country, you should display the entire time series data of sales with each week’s output separated by a character. iii. The user should enter an integer year and an integer week. You should then search the collection extracting each country which contains sales for the specified week in the specified year. For each matching country, you should display that week’s sales. Sample output (shortened to fit on pages by deleting rows/columns) is shown on the following pages (with … indicating the deleted portion). 5/10 Final sales ———– Afghanistan | 104 Albania | 8 Algeria | 3640 * Andorra | 98 Angola | 2631 Antigua and Barbuda | 407 Argentina | 119 Armenia | 14 Australia | 92472 ************************** Austria | 305 Azerbaijan | 228 Bahamas | 58 Bahrain | 6 Bangladesh | 9 Barbados | 5170 * Belarus | 28 Belgium | 476 Belize | 8 Benin | 308 Bhutan | 283 Bolivia | 56 Bosnia and Herzeg
ovina | 9478 ** Brazil | 179 … Ukraine | 207 United Arab Emirates | 1 United Kingdom | 25 United States of America | 121478 ********************************** Uruguay | 57695 **************** Uzbekistan | 113 Venezuela | 4 Vietnam | 394 West Bank and Gaza | 16 Zambia | 38105 ********** Zimbabwe | 987 Maximum Sales were 121478 in United States of America. 6/10 Sales by selected country ————————- Enter partial/whole country name: ia Albania | 2 on 1974 week 14 … 8 on 1974 week 28 Algeria | 4 on 1973 week 18 … 3640 on 1974 week 28 Armenia | 1 on 1974 week 16 … 14 on 1974 week 28 Australia | 2 on 1973 week 23 … 92472 on 1974 week 28 Austria | 1 on 1974 week 2 … 305 on 1974 week 28 Bolivia | 1 on 1974 week 4 … 56 on 1974 week 28 Bosnia and Herzegovina | 1 on 1973 week 14 … 9478 on 1974 week 28 Bulgaria | 3 on 1974 week 8 … 48 on 1974 week 28 Cambodia | 4 on 1974 week 8 … 331 on 1974 week 28 Colombia | 2 on 1974 week 2 … 1155 on 1974 week 28 Croatia | 2 on 1974 week 11 … 95 on 1974 week 28 Czechia | 1 on 1974 week 22 … 11 on 1974 week 28 Equatorial Guinea | 1 on 1973 week 48 … 657 on 1974 week 28 … Romania | 1 on 1974 week 16 … 10 on 1974 week 28 Russia | 1 on 1974 week 5 … 1187 on 1974 week 28 Saint Lucia | 1 on 1973 week 49 … 4015 on 1974 week 28 Saudi Arabia | 1 on 1973 week 51 … 451 on 1974 week 28 Serbia | 2 on 1974 week 28 Slovakia | 1 on 1974 week 8 … 231 on 1974 week 28 Slovenia | 1 on 1973 week 19 … 99 on 1974 week 28 Somalia | 1 on 1973 week 44 … 412 on 1974 week 28 Syria | 1 on 1973 week 23 … 3447 on 1974 week 28 Tanzania | 3 on 1974 week 14 … 141 on 1974 week 28 Tunisia | 3 on 1973 week 17 … 2320 on 1974 week 28 Zambia | 2 on 1973 week 16 … 38105 on 1974 week 28 7/10 Snap shot of sales —————— Enter year: 1973 Enter week: 22 Algeria | 9 on 1973 week 22 Bhutan | 9 on 1973 week 22 Bosnia and Herzegovina | 4 on 1973 week 22 China | 11 on 1973 week 22 Ethiopia | 1 on 1973 week 22 Fiji | 2 on 1973 week 22 Georgia | 1 on 1973 week 22 Holy See | 4 on 1973 week 22 Japan | 8141 on 1973 week 22 Jordan | 1 on 1973 week 22 Malaysia | 10 on 1973 week 22 Mauritania | 14 on 1973 week 22 Slovenia | 1 on 1973 week 22 Spain | 2 on 1973 week 22 Tunisia | 8 on 1973 week 22 United States of America | 5 on 1973 week 22 Uruguay | 4 on 1973 week 22 Uzbekistan | 1 on 1973 week 22 Zambia | 5 on 1973 week 22 Zimbabwe | 1 on 1973 week 22 8/10 Program Style The program you write for this assignment must be contained in five files as follows: • sale.h and sale.c for managing a sale; • node.h and node.c for nodes of linked lists (if appropriate); • assig_two120.c for the main algorithm which controls the reading of the data, the management of the collections, the calculation of the results, and the 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 an electronic submission. Electronic submission • You should submit a folder of all header and program files compressed as a ZIP file. Do not submit a RAR file. 9/10 How to submit Electronic submission • You should ZIP the 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 main() function shows abstraction of algorithm 2 Countries added in alphabetical order 2 Sale added — • As the first for a country 2 • For an existing country 2 • In increasing order by timestamp (earliest first) 3 • Discarding ‘no sales’ (Zeroes) 1 Histogram displayed — • With title 1 • With country name 1 • With asterisks (when appropriate) 2 • With total 1 • With ‘winning’ details 2 Sales listed for selected countries — • With partial matching of input 2 • Showing country name 2 • Showing list of sales in columns in ascending order 2 Snap shot of sales shown — • With matching of year and week 3 • With country name 1 • With sale figure 1 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 Varia
bles defined at the start of functions only 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 10/10 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 Academic Integrity 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, April 2nd 2020.

admin

Author admin

More posts by admin