

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A programming assignment for the operating systems course cs570 in spring 2004. The goal is to learn about file manipulation using win32 api. The assignment consists of three parts: creating and reading a binary file (part a), random access to a binary file (part b), and file mapping and random access (part c). Students are required to write three programs (p31.cpp, p32.cpp, and p33.cpp or p34.cpp) using functions like srand(), rand(), createfile(), writefile(), closehandle(), setfilepointer(), readfile(), getfilesize(), getfiletime(), filetimetolocalfiletime(), filetimetosystemtime(), createfilemapping(), mapviewoffile(), unmapviewoffile(), flushviewoffile(), and closehandle().
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


The goal of this assignment is to learn about file manipulation using Win32 API.
A good description of the related system services is given in "Win32 System Services" by Marshall Brain 2 nd edition: pages 24-58, and 76-83; 3 rd^ edition: pages 21-46 and 59-64).
Please create a new directory for this assignment.
The assignment has three parts:
Write two programs p31.cpp and p32.cpp. First program generates N=25 random numbers (4-byte integers) and stores them into file with the fixed name d3. The seed of the random number generator should be set to your masc number. For example, if your login name is masc1234, then use srand(1234);
The second program, p32, reads and prints the entire contents of the file d3 (don't make assumption about the number of integers in file, read until EOF.) At the end print a small report which informs us about the size of the file and the time of its creation (the time should be displayed in format: dd/mm/yyyy hh:mm).
HINT: For p31.cpp use: srand(), rand(), CreateFile(), WriteFile(), CloseHandle(); For p32.cpp use: CreateFile(), ReadFile(), GetFileSize(), GetFileTime(), FileTimeToLocalFileTime(), FileTimeToSystemTime(), CloseHandle().
Write the program p33.cpp that does the following:
Using the program p32 from part A, before and after invoking p33, can help you to check the validity of both programs
HINT: Use: CreateFile(), atoi(), SetFilePointer(), ReadFile(), WriteFile(), CloseHandle().
Write program p34.cpp, which does the modification of the m-th, value similarly as in program p33.cpp, only it does this by file mapping. Once the file d3 is mapped into memory, its content is treated as an array of integers (could be array of any other type). The modification is done in memory and the modified memory is flushed back to disk. Again, the validity of p34 can be verified by using p32.
HINT: Use: CreateFile(), CreateFileMapping(), MapViewOfFile(), UnmapViewOfFile(), FlushViewOfFile(), CloseHandle().
Please do development for the three parts independently, exactly in this order: p31.cpp, then p32.cpp, and then p33.cpp. After you are sure that everything works properly, and your sources are nicely formatted and commented, generate the final documentation for the grader:
turnin3 > results
Then FTP file results3 to rohan, so you can mail it to the grader:
mail grade570 < results
File turnin3.bat you can find in http://medusa.sdsu.edu/cs570/Projects/Assignments.htm Don't forget to update your banner (assignment # and date). Results can be sent only once.
END a3.