10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 1/9 CS 3113: Project 2 For this project, we will implement a miniature database with a front-end that is...

i ust attached the file


10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 1/9 CS 3113: Project 2 For this project, we will implement a miniature database with a front-end that is accessible using a web browser. The file will contain a set of records that describe assignments for a course, including the name of the assignment, its type, the maximum number points that can be earned, the number of points actually earned, and whether the record is valid Your program can be executed to insert or change data in the database using command line arguments Your program can also be used in server (front-end) mode: under certain conditions, it will produce HTML-formatted output that shows the following: A list of the valid database records The weighted score given the valid records A list of the invalid records Objectives By the end of this project, you will be able to: Read/write C structures from/to a file Create/delete a named pipe Create programs that wait for the named pipe to be opened and produce output to the named Create programs that can generate HTML code that is usable by a web browser Back-End Database Your database will be stored in a file called grades.bin. Every time your program begins execution, you will open this file for both reading and writing. If the file does not exist on open, then you should create it. Much like your project 1 implementation, your file is composed of fixed-size blocks of data. Each block contains one instance of the AssignmentRecord structure, as defined in record.h: #ifndef RECORD_H #define RECORD_H // Maximum size of assignment name #define NAME_SIZE 23 // Name types typedef enum {EXAM=0, HOMEWORK, QUIZ, PROJECT} AssignmentType; // Name Strings char *type_names[] = {"EXAM", "HOMEWORK", "QUIZ", "PROJECT"}; // Record of a single assignment typedef struct { char valid; char name[NAME_SIZE]; int type; // AssignmentType float max_score; float score; 10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 2/9 }AssignmentRecord; #endif Notes: #ifndef/#define/#endif are used in many header files to ensure that the contents of the header are only loaded once during compilation (even if there are multiple includes of the same file) NAME_SIZE defines the maximum number of characters in the name of an assignment (including the null terminator byte) AssignmentType and type_names define the set of possible assignment types and their corresponding string names AssignmentRecord defines all of the data that we need to describe a single assignment The key idea that you will be making use of is that you can read/write bytes of an entire record all at once. This makes implementation of simple databases easy (but, in the general case, one has to be very careful about architecture-dependent differences of type representations) Back-End Commands Your program can be executed with a number of different sets of command-line parameters. Here are the ones that are specific to the back-end: Append a new record onto the database file: ./project2 append NAME ASSIGNMENT_TYPE MAX_SCORE ACTUAL_SCORE NAME is the string name for the assignment. This argument can be longer than what will fit in a single AssignmentRecord. You must handle this situation by truncating the name before copying it into the record ASSIGNMENT_TYPE is one of the type_names defined above. It is an error if the provided argument is not one of these strings MAX_SCORE is the maximum score for this assignment (a floating point number) ACTUAL_SCORE is the actual score that was earned for this assignment (also a float) If all of the arguments are valid, then the database file is modified with this new record placed at the end. All appended records are automatically valid All unused characters in the name field of the AssignmentRecord must be set to zero (this is not generally required, but will facilitate automatic testing). Change the score of an existing record: ./project2 score INDEX SCORE INDEX is the record number to be changed SCORE is the new score It is an error if the specified record does not exist, or if the record number or score cannot be parsed. If there is no error, then the score for the record is changed (and nothing else) 10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 3/9 Change a record to be valid: ./project2 valid INDEX INDEX is the record number to be changed It is an error if the specified record does not exist, or if the record number cannot be parsed. If there are no errors, then the record's valid flag is set to one (1) Change a record to be invalid: ./project2 invalid INDEX INDEX is the record number to be changed It is an error if the specified record does not exist, or if the record number cannot be parsed. If there are no errors, then the record's valid flag is set to zero (0) Not required, but strongly suggested for debugging purposes: ./project2 text Iterate over the records in the database and print out their details. Front-End Interface The front-end interface will generate a web page in the HyperText Markup Language (HTML). For correctness testing purposes, we are prescribing the output very precisely. Because the output is very narrow (and does not use HTML in complicated ways), you should write your own code to generate the output (i.e., don't use external libraries to generate the output). Below are the program commands that you must support for the front end. Both generate identical output: Testing: ./project2 html Prints the full HTML output to STDOUT and terminates. Server mode: ./project2 server Enters an infinite loop. Each time through the loop, your program: Opens in write mode a named pipe called grades.html. This system call will block until a process opens the file for reading Reroute the pipe file descriptor to file descriptor 1. This means that all writes to STDOUT will to be sent to the pipe instead. Note: the previous open() system call will allocate the first available file descriptor to return. Sometimes, this can already be 1. Print the full HTML output to STDOUT Close both the pipe file descriptor and STDOUT (if they are the same, you should only close it once) Sleep for 1 second Repeat https://en.wikipedia.org/wiki/HTML 10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 4/9 Notes: All HTML output must be to STDOUT After generating the end of HTML output, your program must perform a "flush" to make sure that the output data are not left in a buffer: fflush(stdout); Initial State When grades.bin does not exist, starting the server will result in the file being created with no records. The initial file and the response from ./project2 html are as follows: Database file (zero length) The resulting HTML (as viewed with a browser) The resulting HTML (the raw text that the program generates) A Bit of HTML The job of HTML is to describe the content that goes into a web page and to provide general information about how it should be rendered. The details of rendering, however, are left to the specific web browser that you are using. Markup commands in HTML are surrounded by <> pairs. The commands often form a "container" that define both the beginning and end of the formatting command. For example,

indicates that bold formatting should start at that point and

indicates that bold formatting should stop. Specifically: this is in bold is implemented using the HTML code:
this is in bold
Looking at the raw text file above, you will notice certain markup commands ... defines the beginning and ending of a HTML document ... defines the beginning and ending of the header material ... defines the title (this often appears in the tab in the web browser) ... defines the body of the web page


...


defines a level-1 header (often rendered as bold and large); there are corresponding commands for levels 2, 3, ... ...

defines a table (in this case, the table has a border parameter value of 2, meaning thick lines) defines the beginning of a row in the table (the ending markup can be also be included, but its existence is implied). defines a column in the current row (again, the ending can also be included, but it is implied). In our web page, the first row of each table is bolded to indicate that this is a header row. https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_initial.bin https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_initial.html https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_initial.html.txt 10/14/2020 CS 3113: Project 2 https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/project2.html 5/9

    ...

indicates the beginning and ending of a list

  • indicates the beginning of a list item (again, the ending is implied)


    indicates the beginning of a new paragraph (again, the ending is implied)

    HYPERLINK NAME

    indicates a hyperlink (the name is displayed and the link will take the user to the indicated URL) Examples The following represents a sequence of commands, starting from the initial state. For each step, we link to both the database and html files (all are contained in the distributed tar file). ./project2 append "Project 1" PROJECT 100 89.0 adds the Project 1 record to the database. The quotes in the command line force all of "Project", SPACE and the number one to appear as a single string (as argv[2]). The resulting state is: Database file The resulting HTML (as viewed with a browser) The resulting HTML (the raw text that the program generates) Notes: Index is the record number being displayed in the corresponding row Scores and max scores are shown with exactly two decimal places Average score is computed only over the valid records. It is the sum of scores divided by the sum of max scores, and is displayed as a percentage with two decimal places ./project2 append "Project 2" PROJECT 100 85.0 adds the Project 2 record to the database. The resulting state is: Database file The resulting HTML (as viewed with a browser) The resulting HTML (the raw text that the program generates) ./project2 invalid 0 Changes record 0 to be invalid. The resulting state is: Database file The resulting HTML (as viewed with a browser) The resulting HTML (the raw text that the program generates) ./project2 append "Project 1 (new project assignment)" PROJECT 110 98.0 adds the Project 1 (new project assignment) record to the database. The resulting state is: Database file The resulting HTML (as viewed with a browser) The resulting HTML (the raw text that the program generates) https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step1.bin https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step1.html https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step1.html.txt https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step2.bin https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step2.html https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step2.html.txt https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step3.bin https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step3.html https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step3.html.txt https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step4.bin https://cs.ou.edu/~fagg/classes/cs3113_f20/projects/grades_step4.html https://cs


  • Oct 14, 2021
    SOLUTION.PDF

    Get Answer To This Question

    Related Questions & Answers

    More Questions ยป

    Submit New Assignment

    Copy and Paste Your Assignment Here