[SOLVED] COP4600 -P2

30.00 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

5/5 - (3 votes)

POSIX Standards & Bindings

 

Structure

The project is broken into four main parts:

 

  • Create a C++ function that reads a text file via POSIX calls and returns a pointer to its contents
  • Create a short program that uses the function above to display a file via the command line
  • Create a simple Android GUI application that accepts a text file name as input and has a text box
  • Bind the function via the NDK to that the application to display the contents of the file in the text box

Figure 1: A function is called from a text program, and separately, bound to the GUI application.

 

While exact implementation may vary, the library functions must match the signatures laid out in this document.

 

Specification

Students will write several sections of code according the following specifications.

 

File Reader Library

The files read_file.h / read_file.cpp will contain declaration / definition of this function:

 

char *read_file(const char *filename)

Makes POSIX calls to read the contents of filename from disk to be stored in a null-terminated character array (C-style string). The array should be allocated dynamically. A pointer to the array will be returned. The caller will be expected to free the memory allocated for the array. If the file is not found, it should return nullptr.

 

 

Text Program

The text program, once built, should have the name displayfile and should take exactly one command line argument – the filename of the file to be displayed on the screen. It should use the read_file() function. If a file cannot be found, the text program should print “Error: File Note Found”:

 

$ ./displayfile /sdcard/example.txt

Contents of

Hello world!                                            /sdcard/example.txt

This is the last line of the file.         Hello world!      

$                                          This is the last line of the file.       

  

$ ./displayfile nope.txt

Error: File Not Found                         Note that nope.txt does not exist.

$                                           

 

 

GUI Program

The GUI program skeleton provides three GUI elements (without functional code). Students must add code as necessary to elicit the following behavior:

 

  • One-line text box where the file to be displayed will be typed by the user, named filenameBox
  • Button to submit the filename (which should trigger the read and display), named submitButton
  • Multi-line text box where the file will be displayed when the button is pressed, named displayBox

 

Students should modify the Java source to invoke the C++ functions. A simple example of transmitting a string from C++ to Java is included in the project base code. You must use the exact same source files created in the File Reader Library for this task to receive credit, comments and includes are no exception. As in the text program, if a file cannot be found, then the GUI must display the error message in the text box (“Error: File Not Found”).

 

NOTE: You will need to add any new C++ source files to the CMakeLists.txt build file! When accessing files, it must be the absolute path starting with /mnt/ubuntu/<abs_path>, do NOT prepend this in your code!

 

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.