COSC 471/571 Assignment 0906 Distributed: 9/6/2018 Due: 9/13/2018 I. Short Description: Modelling records in 1D array of chars II. Basic Manipulations (1) Store the following data in a 1D array of chars. Record 0: field 0: A field 1: a field 2: 0 Record 1: field 0: B field 1: b field 2: 1 Record 2: field 0: C field 1: c field 2: 2 (2) Output the data in the data structure. Each record begins on a new line. The output will look like this: A a 0 B b 1 C c 2 (3) Output the first 200 chars of data in the data structure. DO NOT format the outputted values. The output will look like this: A a 0 B b 1 C c 2 Wrap-around or truncated output is accepted. Very important! Do not output any data that was not explicitly inserted. Many compilers will automatically initialize memory before the executing program makes an assignment to it. Do not output any automatically initialized data. I.e., only output 200 chars of data in part (2). III. Data structure You are modelling a file of records using a 1D array of chars. Each record contains three fields. Each field is 20 chars in length, so each record is 60 chars in length. Therefore, record i starts at index i*60. You should include an int (or long) variable that gives the last location plus 1 in the 1D array where data has actually been stored. E.g., for the three records, stored one after the other starting at offset 0, last will have the value 181 (record 0 uses offsets 0 -- 59; record 1 uses offsets 60 - 119; record 2 uses 120 - 179). Use the value of last to recognize when the last record in the data structure has been accessed. Very important! Do not store anything except for the actual data. Very important! Do not store any string termination symbol in the data structure. Even though (2) *looks* as though there are three strings, there are actually NO strings in the data -- only chars. Field 0 is stored at offset 0 within a record. Because field 0 is 20 chars in length, field 1 is stored at offset 20 from the start of its record. Because field 0 is 20 chars and field 1 is 20 chars, field 2 is stored at offset 20 + 20 = 40 from the start of its record. IV. Inserting data one record at a time You must insert the data to the data structure using the following user-supplied commands: INSERT ("A", "a", "0") INSERT ("B", "b", "1") INSERT ("C", "c", "2") (Note, you can actually supply the commands at run-time using a prompt or using run-time arguments, or you can hard-code the commands in an array of strings) You will code the insert function to accept three string (or char array) arguments. The user-supplied command "INSERT" is case-insensitive. Notice, the three parameters to the insert function are strings. You will, of course, need to store the data without string termination symbols and at the proper offset. V. Outputting data one record at a time. You will write an output function that accepts a record number (in this case, 0, 1, or 2). Use that argument to index into the 1D array (recordNumber * 60), then output one record (i.e., 60 characters). Very important! Do not build one output string to be passed to whatever system library function you use to output (e.g., System.out.print() or System.out.println()). Instead, output each record immediately after retrieving it. VI. If you prefer to do this using random access file rather than a 1D array of chars, that is great! Go right ahead! Use file read, file write, file seek, etc. All other constraints still apply -- only the data structure is different. VII. Turn in (1) Hard copy of code. - Header must include your last name, assignment identifier (0906), URL of source code. If the code is in more than one file, then instructions on how to run the code must also be supplied. - Your code must be pretty-printed! Good alignment; good use of white space; No uncontrolled line-breaks. - No magic numbers! Clean and elegant code only! (2) Screen shot of execution showing input, if supplied at run-time, and output. (3) Language of implementation: - not perl - must be able to run locally - language must support random access file I/O