Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ANSWER ALL PARTS Task 2: Serialize an array of integers to a JSON text-format file Extend the functionality of your integer array from Lab 5

ANSWER ALL PARTS

Task 2: Serialize an array of integers to a JSON text-format file

Extend the functionality of your integer array from Lab 5 to support saving and loading arrays from the filesystem in JSON, a common human- and machine-readable text format.

Sometimes it is useful for humans to be able to read your stored data, or to import your data into another program that does not understand your binary format. The most readable, portable XDR format is plain text. A popular syntax for text files is JSON (JavaScript Object Notation), which, as the name suggests, was originally an XDR format for web programs. It is easier to use and less verbose than the also-popular Extensible Markup Language (XML)and more expressive than the bare-bones Comma-Separated Values (CSV) formats you may have seen.

The down side of text formats is that they are:

inefficient in space, since e.g. a four-byte integer (int32_t) could require up to 12 bytes to represent its minimum value of -2147483647 as a decimal string;

inefficent in time, since parsing the text file to convert it back into a binary format is much more expensive than loading a binary file.

The standard library has two functions that can be very helpful for rendering text into files:

fprintf()

fscanf()

They work just like the familiar printf() and scanf() but read to and write from FILE* objects instead of standard input and standard output. You should probably use these to solve this task.

Notice from those man pages that another pair of functions snprintf() and sscanf() is also available to print and scan from C strings too. (sprintf() exists, but the lack of array length checking means this is not safe or secure to use. Always use snprintf()).

The header file "intarr.h" also contains these new function declarations:

/* LAB 6 TASK 2 */ /* Save the entire array ia into a file called 'filename' in a JSON text file array file format that can be loaded by intarr_load_json(). Returns zero on success, or a non-zero error code on failure. Arrays of length 0 should produce an output file containing an empty array. The JSON output should be human-readable. Examples: The following line is a valid JSON array: [ 100, 200, 300 ] The following lines are a valid JSON array: [ 100, 200, 300 ] */ int intarr_save_json( intarr_t* ia, const char* filename ); /* Load a new array from the file called 'filename', that was previously saved using intarr_save_json(). The file may contain an array of length 0. Returns a pointer to a newly-allocated intarr_t on success (even if that array has length 0), or NULL on failure. */ intarr_t* intarr_load_json( const char* filename ); 

Given:

typedef struct {

int* data;

unsigned int len;

} intarr_t;

We have to write following two functions. We can use fscanf(), fprintf(), snprintf(), ssanf().

1.) int intarr_save_json( intarr_t* ia, const char* filename );

(In this function, Save the entire array ia into a file called 'filename' in a JSON

text file array file format. Returns zero on success, or a non-zero error

code on failure. Arrays of length 0 should produce an output file

containing an empty array.

The JSON output should be human-readable.

Examples:

The following line is a valid JSON array:

[ 100, 200, 300 ]

The following lines are a valid JSON array:

[

100,

200,

300

]

)

2.) intarr_t* intarr_load_json( const char* filename );

( In this function, Load a new array from the file called 'filename', that was

previously saved using intarr_save(). The file may contain an array

of length 0. Returns a pointer to a newly-allocated intarr_t on

success (even if that array has length 0), or NULL on failure.)

/* Save the entire array ia into a file called 'filename' in a binary file format that can be loaded by intarr_load_binary(). Returns zero on success, or a non-zero error code on failure. Arrays of length 0 should produce an output file containing an empty array. */ int intarr_save_binary( intarr_t* ia, const char* filename ); /* Load a new array from the file called 'filename', that was previously saved using intarr_save_binary(). Returns a pointer to a newly-allocated intarr_t on success, or NULL on failure. */ intarr_t* intarr_load_binary( const char* filename ); 

Assignment #2 (Part B) Analysis modelling scenario & class...

Assignment #2 (Part B) Analysis modelling scenario & class based

Due Fri week 9 at 23:59 (Total Marks: 10 points)

Six deliverables

Deliverable #1 (1 Marks) due week 5 for professor review and feedback.

Based on the list of requirements you gathered in Part A of the project, develop a set of goal use cases per use case identify the actors (Operational stakeholders) involved and the requirements they relate to. Name each use case to reflect the functionality it serves using the name convention "Verb-Noun " group the uses cases under two or three sub-systems / modules. You can base your grouping based on the similar functional areas or based on types of operational stakeholders, who are your end users. Add the use case table to section # 3 of your SRS document.

Check out the safe home case study there is a good example of how use cases can be grouped.

Note: If you have abstract uses cases for example "Log into system" add it at the end of the table and do not enter the actors. Your actors should be operational stakeholders. Per project at least two different actors (operational stakeholders) are required, do not use the term end user, rather have a name for each role.

Below an Example for the use case table:

Use cases

Use Case name

List of related Requirements ID

Actor (s)

Brief Description

Create service request

FR05, FR04

Student, Faculty

The actor will click on the service request button , in response the software will present the actor with a form and the user will select the type and sub-type of the service request and enter the details, the software will automatically generated a unique service request # and send a confirmation e-mail with the service request number to the actor.

.....

.......

Deliverable #2 (2 mark) due week 6 for professor review and feedback

Select one use case with high priority and develop a textual detailed formal use case description, using the use case template in chapter #8 page 136. Supplement the use case with a swim lane activity diagram, explaining the flow of activities between the system and the actor(s). Add the use-case formal descriptions and the activity swim lane diagrams to section #4 of your SRS document.

Deliverable #3 (1 mark) due week 6 for professor review and feedback

Using "Microsoft Visio" draw a use case diagram illustrating all the use cases identified in deliverable 1 above grouped by sub-system. Add the output to section #4 of your SRS document.

Click on the following link for details on how to draw use case diagrams using Microsoft Visio: Visio use case diagram

Below is use case diagram example:

Image source: Object-Oriented Technology From Diagram to Code with Visual Paradigm for UML. Curtis H.K. Tsang, Clarence S.W. Lau and Y.K. Leung.

Deliverable #4 (2 mark) due week 8 for professor review and feedback

Based on the use case descriptions, use the "Noun" technique to identify a list of analysis classes related to the domain problem/opportunity of your project. Brainstorm with your team to identify the list of attributes related to each class and the class relationships, for example binary association, inheritance...etc. and describe these relationships, for example a customer places an order, an order belongs to one customer. Draw, using "Microsoft Visio" a first cut domain class diagram. Add the domain class diagram to Appendix E of your SRS document under class diagrams

Refer to Appendix 1 in your text book for examples on Class diagrams, and the below links on how to Microsoft Visio

Visio class diagrams

Visio detailed class diagrams

Deliverable #5 (2 mark) due week 8 for professor review and feedback

Brainstorm with your team to develop a set of Class responsibilities and collaboration "CRC cards" for all entity type classes. Add the CRC index cards to Appendix E of your SRS document under class diagrams.

Deliverable #6 (2 mark) due week 9 for professor review and feedback

Based on the responsibilities and collaborations identified in your CRC index cards update your first cut domain class diagram with the following:

a. Class attribute descriptions and visibilities

b. Signature methods with the respective parameters and visibilities

Write a report from the case study below that will provide Harriet with two options: a low-cost IT solution that should do the job and easily fits within their budget, and a better solution that will cost more but will continue to be sufficient for at least 3-5 years. This second solution could, if needed, go above budget, but you will need to justify the cost. The report should include:

An introduction that summarises Harriet's situation

A computer

A recommendation for accounting software

A rough proposal for a website

A recommended internet account provider and plan

It needs to be written with consideration of Harriet's particular circumstances and to take into account her current skills.

Case Study

Harriet Boone is an artisan hobbyist with a strong interest in woodworking. Harriet makes artistic wooden wearable items, such as earrings, brooches, hair pins, bracelets, and other ornaments. Now Harriet wants to make a living from her hobby and believes she can use several avenues to monetize her art: by selling the pieces locally, and by marketing her art online. Her idea is to film herself, and upload progress vlogs highlighting new pieces she's created, as well as tutorials for other artists to learn from.

Harriet has just moved to Adelaide, and although she has woodworking tools (and a small workshop in her garage), her technical equipment is limited to a GoPro and an old Nikon DLSR. She plans to use these cameras for filming, but she doesn't currently have her own computer or internet.

Harriet has got a little bit of savings that she's set aside for the computing side of her business totaling $2500. She will need to set up a website to start sales, and buy a computer with appropriate software to handle video editing and uploading, as well as to manage the usual small business tasks.

Harriet does have IT experience - while not particularly knowledgeable about computer hardware, she can use a computer, has basic experience with video editing, and has no problem using standard office software. However, she lacks any experience in using accounting software, and has never built nor maintained a website.

Task 2: Serialize an array of integers to a JSON text-format file

Extend the functionality of your integer array from Lab 5 to support saving and loading arrays from the filesystem in JSON, a common human- and machine-readable text format.

Sometimes it is useful for humans to be able to read your stored data, or to import your data into another program that does not understand your binary format. The most readable, portable XDR format is plain text. A popular syntax for text files is JSON (JavaScript Object Notation), which, as the name suggests, was originally an XDR format for web programs. It is easier to use and less verbose than the also-popular Extensible Markup Language (XML)and more expressive than the bare-bones Comma-Separated Values (CSV) formats you may have seen.

The down side of text formats is that they are:

inefficient in space, since e.g. a four-byte integer (int32_t) could require up to 12 bytes to represent its minimum value of -2147483647 as a decimal string;

inefficent in time, since parsing the text file to convert it back into a binary format is much more expensive than loading a binary file.

The standard library has two functions that can be very helpful for rendering text into files:

fprintf()

fscanf()

They work just like the familiar printf() and scanf() but read to and write from FILE* objects instead of standard input and standard output. You should probably use these to solve this task.

Notice from those man pages that another pair of functions snprintf() and sscanf() is also available to print and scan from C strings too. (sprintf() exists, but the lack of array length checking means this is not safe or secure to use. Always use snprintf()).

The header file "intarr.h" also contains these new function declarations:

/* LAB 6 TASK 2 */

/*

Save the entire array ia into a file called 'filename' in a JSON

text file array file format that can be loaded by

intarr_load_json(). Returns zero on success, or a non-zero error

code on failure. Arrays of length 0 should produce an output file

containing an empty array.

The JSON output should be human-readable.

Examples:

The following line is a valid JSON array:

[ 100, 200, 300 ]

The following lines are a valid JSON array:

[

100,

200,

300

]

*/

int intarr_save_json( intarr_t* ia, const char* filename );

/*

Load a new array from the file called 'filename', that was

previously saved using intarr_save_json(). The file may contain an array

of length 0. Returns a pointer to a newly-allocated intarr_t on

success (even if that array has length 0), or NULL on failure.

*/

intarr_t* intarr_load_json( const char* filename );

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

12 Customer/audience relationship management

Answered: 1 week ago