CS609 Assignment 1 Solution Fall 2026

CS609 System Programming is the VU course where you stop writing programs that only work on paper and start writing programs that talk directly to the operating system. Assignment 1 for Fall 2026 asks for a C++ program called TextFileAnalyzer that uses the Windows API to open a text file, read its contents, and report how many bytes it read. It is a practical assignment, and it tests whether you understand file handling at the system level rather than just at the language level.
The solution file linked below contains the complete C++ source code for TextFileAnalyzer, together with an explanation of how it works. It uses CreateFileA to open the file, ReadFile to read it in blocks of 4096 bytes, prints the file contents, and prints the total number of bytes read. It also includes error handling for the cases where the file cannot be opened or read, which is exactly the kind of detail that earns marks in a system programming assignment.
What Does the Solution File Cover?
The file contains a complete .cpp source file for the TextFileAnalyzer program. It is source code, not a ready made executable, so you need a Windows C++ compiler to build and run it. The program follows a clear sequence: open the file, read it block by block, display what it reads, count the total bytes, and close the file cleanly at the end.
How Does the Program Open and Read the File?
The program opens the file with CreateFileA, requesting read access and asking Windows to open an existing file. If the returned handle is invalid, the program reports an error and stops instead of crashing. Reading is done with ReadFile in blocks of 4096 bytes. The program loops until ReadFile reports zero bytes read, which means the end of the file has been reached. Each block is printed as it is read, and a running total keeps track of how many bytes have been read so far.
What Does the Program Print at the End?
After the reading loop finishes, the program prints the total number of bytes read from the file. This total should match the size of the file in bytes for a normal text file, which gives you a simple way to check that the program worked correctly. The file handle is then closed with CloseHandle, which releases the operating system resource properly.
How Is Error Handling Done?
Error handling appears at both risky points in the program. If CreateFileA fails, for example because the file path is wrong or the file does not exist, the program prints an error message and exits cleanly. If ReadFile fails during the loop, the program reports the read error instead of printing garbage or looping forever. This structure is important because system level code must always check the result of every API call.
How Do You Download the Solution File?
You can download the complete .cpp source file from Google Drive using the link below. Remember that it is source code, so you still need to compile it before you can run it.
How Should You Use This Solution?
Download the .cpp file, open it in a Windows C++ compiler such as Visual Studio or a MinGW based setup, and build the project. Run the resulting program with a text file of your own and check that the printed contents and the total byte count match the file. Fill in your own name and student ID on your submission, and read the code until you can explain each API call, because viva style questions often focus on why CreateFileA and ReadFile are used the way they are.
- Download the .cpp source file from the link above.
- Open it in a Windows C++ compiler such as Visual Studio.
- Build the program and fix any compiler specific warnings.
- Run it against a small test text file first.
- Fill in your own name and student ID on your submission.
- Read the code until you can explain every API call yourself.
For more study material, you can download course handouts from the VU handouts page and compact revision notes from the VU short notes page. For practice with similar system programming questions, visit the VU midterm past papers page.
Frequently Asked Questions
Is this file an executable program?
No. The file is C++ source code with a .cpp extension. You must compile it with a Windows C++ compiler before you can run it. If you try to run the .cpp file directly, nothing will happen.
Which compiler should I use?
Visual Studio on Windows is the simplest choice, since the Win32 API headers are included with it. A MinGW based g++ setup on Windows also works. The code uses standard Win32 API calls, so any Windows C++ compiler with the Windows SDK should build it.
What happens if the file does not exist?
CreateFileA returns an invalid handle, and the program prints an error message and exits cleanly. It does not crash and does not print meaningless output, which is the correct behavior for system level code.
Can I submit this solution file as it is?
Use it as a study reference. Add your own name and student ID, test the compiled program yourself, and make sure you understand the code before submitting. Submitting code you cannot explain is risky in this course.
Last updated: October 2026.



