Programming Assignment 1 | Operating Systems | CS 570, Assignments of Operating Systems

Material Type: Assignment; Class: OPERATING SYSTEMS; Subject: Computer Science; University: San Diego State University; Term: Spring 2004;

Typology: Assignments

Pre 2010

Uploaded on 03/28/2010

koofers-user-yum
koofers-user-yum 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The goal of this assignment is to understand the concepts and to learn how to create and use dynamic link libraries in
95/98/NT/w2k environment. A good description of the related system services is given in "Win32 System Services” by
Marshall Brain (pages 741 through 752 2nd edition, 585-598 3rd edition).
The assignment has three parts:
PART A - Create a static library
A1. Create source files x.cpp and x.h which implement the functions:
double add(double a, double b); // Add two doubles
double sub(double a, double b); // Subtract two doubles (a-b)
and source files y.cpp and y.h which implement the functions:
double mul(double a, double b); // Multiply two doubles
double divide(double a, double b, int* err); // Divide two doubles (a/b)
Operand err is a pointer to an error code which has value 1 in case the second operand has the magnitude less than
0.1e-10, otherwise err is set to 0. Be sure you supply the extern "C" statements in x.h and y.h.
A2. Use the files x.cpp and y.cpp to create two static libraries xs.lib and ys.lib.
A3. Write the main program (p11.cpp), which prompts the user to enter two doubles, then computes their sum,
difference, product and quotient, using the library functions specified above. The output results should be accompanied
by proper labels (like: "The sum of a and b is: "). Also, in case of division, the program is checking the error code and
is issuing an error message if the division wasn't completed successfully. The program should repeat the prompt-enter-
compute cycle as long there are valid data present at the standard input. If anything different than numbers is presented
at the input, the program should exit with a proper error message.
A4. For compilation, creation of libraries and for linking use commands cl, lib, and link respectively. You may do
the job by using a simple (commented!) batch file (p11.bat), or a (commented) make file (p11.mak).
Instruction what to turn in is given at the end of this file.
PART B - Create a dynamic link library (linked at load time)
B1. Use x.obj and y.obj to create libraries x.dll and y.dll. For this you need to supply the definition files
x.def and y.def.
B2. Using link command create p12.exe which can be dynamically linked with x.dll and y.dll at load time.
For this use the same source file p11.cpp from the part A.
B3. After you have created all dll and exe files, rename one of the dll files and try to run p12.exe. See what will
happen.
B4. Return the correct name to the renamed dll file and run p12.exe again. This time you should get successful
loading and execution.
B5. Change one of the library sources. For example you may change the comments in x.cpp (e.g. add comment:
CS570 Operating Systems Spring 2004
Programming Assignment #1 Assigned: January 26 Due: February 4
pf2

Partial preview of the text

Download Programming Assignment 1 | Operating Systems | CS 570 and more Assignments Operating Systems in PDF only on Docsity!

The goal of this assignment is to understand the concepts and to learn how to create and use dynamic link libraries in 95/98/NT/w2k environment. A good description of the related system services is given in "Win32 System Services” by Marshall Brain (pages 741 through 752 2 nd^ edition, 585-598 3 rd^ edition).

The assignment has three parts:

PART A - Create a static library

A1. Create source files x.cpp and x.h which implement the functions:

double add(double a, double b); // Add two doubles double sub(double a, double b); // Subtract two doubles (a-b)

and source files y.cpp and y.h which implement the functions:

double mul(double a, double b); // Multiply two doubles double divide(double a, double b, int* err); // Divide two doubles (a/b)

Operand err is a pointer to an error code which has value 1 in case the second operand has the magnitude less than 0.1e-10, otherwise err is set to 0. Be sure you supply the extern "C" statements in x.h and y.h.

A2. Use the files x.cpp and y.cpp to create two static libraries xs.lib and ys.lib.

A3. Write the main program (p11.cpp), which prompts the user to enter two doubles, then computes their sum, difference, product and quotient, using the library functions specified above. The output results should be accompanied by proper labels (like: "The sum of a and b is: "). Also, in case of division, the program is checking the error code and is issuing an error message if the division wasn't completed successfully. The program should repeat the prompt-enter- compute cycle as long there are valid data present at the standard input. If anything different than numbers is presented at the input, the program should exit with a proper error message.

A4. For compilation, creation of libraries and for linking use commands cl, lib, and link respectively. You may do the job by using a simple (commented!) batch file (p11.bat), or a (commented) make file (p11.mak).

Instruction what to turn in is given at the end of this file.

PART B - Create a dynamic link library (linked at load time)

B1. Use x.obj and y.obj to create libraries x.dll and y.dll. For this you need to supply the definition files x.def and y.def.

B2. Using link command create p12.exe which can be dynamically linked with x.dll and y.dll at load time. For this use the same source file p11.cpp from the part A.

B3. After you have created all dll and exe files, rename one of the dll files and try to run p12.exe. See what will happen.

B4. Return the correct name to the renamed dll file and run p12.exe again. This time you should get successful loading and execution.

B5. Change one of the library sources. For example you may change the comments in x.cpp (e.g. add comment:

CS570 Operating Systems Spring 2004

Programming Assignment #1 Assigned: January 26 Due: February 4

"// Updated version 0.1, 2/21/2003") then create new x.obj and x.dll. Run the old (unchanged) p12.exe and see how the new version of the dll file does not affect the application.

PART C - Use dynamic link libraries (linked at run-time)

C1. Write a new program p13.cpp which uses pointers to the library functions instead of direct function calls: The program should explicitly load the libraries x.dll and y.dll (use system call LoadLibraryEx()) and check if the libraries are available. An appropriate message should be output (to cout, don't use cerr if a particular library doesn't exist. In similar way the program should check and report the error messages if a particular function in x.dll or y.dll doesn't exist (after system calls GetProcAddress()).

This time the file p13.obj doesn't have to be linked with x.lib and y.lib in order to create p13.exe, because you call the library functions via pointers.

Use x.dll and y.dll unchanged, i.e. as created in Part B.

C2. After you create p13.exe, rename x.dll or y.dll, or both, and try to execute p13.exe. See if your program reports a correct error message. Then get back to the original name of the renamed dll file and run p13.exe again. Program should work correctly.

What to turn in

After the coding and testing of all three parts is successfully completed, run the script file "turnin1.bat" and redirect data to the file "results1":

turnin1 > results

Then send the file "results1" to the grader via e-mail ([email protected]) by the due date indicated above (mail sent after the midnight will be penalized 20 points for each delayed working day.) Please do not send attachments, you may FTP the file “results1” to rohan.sdsu.edu, then run the command:

mail grade570 < results

The script file "turnin1" takes care of data input by redirecting data from data files "data11", "data12" and "data13".

Before you generate the file "results1" update your banner file "banner.txt"

You can send the file "results1" only once! The second shipment will be dropped.

Do not modify the files "turnin1.bat", "data11.txt", data12.txt", "data13.txt" and "results1".

Be sure that all files are properly commented. Each file has to have a header comment, which identifies the file name, author, date, and a short description of the file contents. Use additional comments throughout the code. Also be sure that all system calls should be checked for successful completion. Ise GetLastError() system call to get the error code. Show this code in your error message. The explanation of error codes can be found in: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp

This assignment is strictly individual. Exchange of files between students is not permitted and will be treated as cheating.

END a1.