Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a + Open for reading and appending ( writing at end of file ) . The file is created if it does not exist. The

a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
The fopen() function must:
instantiate a FILE object
initialize it according to the file modes
allocate a file stream buffer within the FILE object
open a file using the corresponding OS system call, (e.g., open in Unix)
Binary vs. text files: Linux doesn't differentiate between text and binary files, so 'b' type for fopen() has no effect
Figure 2. Differences between file-opening modes using stdio.h functions vs. system calls.
5. Our stdio.cpp File
In addition to stdio.h, you will also find stdio_template.cpp on Canvas to support with this program. The file stdio_template.cpp has already implemented: printf, setvbuf, setbuf, fopen, and feof.
Note that printf accepts only %d, and that the other functions are partially implemented -- just enough to be able to run the driver and performance test programs. No need to implement the rest of the function.
Also on canvas are the files driver.cpp and eval.cpp. These should not be modified and are only used to test your implementation of stdio. They should include stdio.h; they don't need to be aware of the existence of stdio.cpp. Note that stdio.cpp is included at the bottom of stdio.h, so that it is possible to compile a user program like this:
% g++ driver.cpp
% g++ eval.cpp
6. Statement of Work
Step 1: Copy the source code and compile script from canvas to a Linux system.
Files: compile.sh, eval.cpp, driver.cpp, stdio.h and stdio_template.cpp
Step 2: Rename stdio_template.cpp to stdio.cpp. Implement all missing functions; noted by,//complete it in the file.
Step 3: Build the eval and driver executables using the compile.sh build script.
Step 4: Test your implementation of stdio.h using the driver executable and the texts provided on canvas: hamlet.txt, othello.txt
Execute: ./driver hamlet.txt > output_hamlet.txt
Compare output_hamlet.txt, test1.txt, test2.txt, test3.txt to versions on canvas
Execute: ./driver othello.txt > output_othello.txt
Compare output_othello.txt, test1.txt, test2.txt, test3.txt to versions on canvas
Step 5: Test your implementation of stdio.h using the eval executable to test different read/write combinations and sizes. The set of tests which should be run can be executed by running the eval_tests.sh script.
Execute: ./eval_tests.sh > eval_test_out.txt
The tests which are run are the following:
./eval r u a hamlet.txt read hamlet.txt with unix I/O at once.
./eval r u b hamlet.txt read hamlet.txt with unix I/O every 4096 bytes.
./eval r u c hamlet.txt read hamlet.txt with unix I/O one by one character.
./eval r u r hamlet.txt read hamlet.txt with unix I/O with random sizes.
./eval r f a hamlet.txt read hamlet.txt with your stdio.cpp at once.
./eval r f b hamlet.txt read hamlet.txt with your stdio.cpp every 4096 bytes.
./eval r f c hamlet.txt read hamlet.txt with your stdio.cpp one by one character.
./eval r f r hamlet.txt read hamlet.txt with your stdio.cpp with random sizes.
./eval w u a test.txt write to test.txt with unix I/O at once.
./eval w u b test.txt write to test.txt with unix I/O every 4096 bytes.
./eval w u c test.txt write to test.txt with unix I/O one by one character.
./eval w u r test.txt write to test.txt with unix I/O with random sizes.
./eval w f a test.txt write to test.txt with your stdio.cpp at once.
./eval w f b test.txt write to test.txt with your stdio.cpp every 4096 bytes.
./eval w f c test.txt write to test.txt with your stdio.cpp one by one character.
./eval w f r test.txt write to test.txt with your stdio.cpp with random sizes.
Step 6: Replace the first line of the eval.cpp,(i.e.,stdio.h) with to use the Unix-original stdio.h rather than your own, recompile it with ./compile.sh, and rerun the eval_tests.sh script.
Execute: ./eval_tests.sh > eval_test_org_out.txt
7. What to Turn in
Criteria Grade
Code Source code that adheres good modularization, coding style, and an appropriate amount of comments. Use google coding guidelines: google.github.io/styleguide/cppguide.html
5 pts
Correctness
Execution output from some of the above tests + possibly other non-published tests
Correct screenshots of the diff command in Step 4 comparing your output files vs. the originals
diff output_hamlet.txt Originals/output_hamlet.txt
diff output_othello.txt Originals/output_othello.txt
diff test1.txt Originals/test1.txt
diff test2.txt Originals/test2.txt
diff test3.txt Originals/test3.txt
Output files from running eval_tests.sh with your and the original stdio implementations: eval_test_out.txt, eval_test_org_out.txt
20 pts

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

More Books

Students also viewed these Databases questions