Write a C++ object-oriented program to manage an I/O process list and a ready pr
ID: 3887151 • Letter: W
Question
Write a C++ object-oriented program to manage an I/O process list and a ready process list for an operating system. The structure of a process is as follows:
Process id – unsigned integer
Process name – string
Process running time – unsigned integer
The program will manipulate these lists based on the process requirements from the file process.dat
Class requirements
Create a process class or struct based on the process structure
Create a processes class which contains three private members – an array of processes, the size of the array and a function to print the contents of a process. The processes class will also provide the following functionality.
Load data from a data file into a process list
Retrieve and print a process from a process list
Create a process and assign it the given values
Insert a process into a process list
Delete a process from the process list
Print the contents of a process
Print the contents of a process list
Processing requirements
Load the I/O list from the file io.dat
Load the Ready list from the file ready.dat
Read through the process file and carry out the given operations
Structure of the files
io.dat – process id, process name, process running time
ready.dat – process id, process name, process running time
process.dat – a) operation code, process id, process name, process running time, list (for operation code i[insert])
b) operation code, process id, list (for operation codes d[delete], r[retrieve])
c) operation code, list (for operation code p[print])
0 represents the i/o list, 1 represents the ready list
Explanation / Answer
#include #include // the class declarations for file stream objects using namespace std; ... int main () { ifstream my_input_file; // an input file stream object ofstream my_output_file; // an output file stream object ... } The above example code declares two objects, an input file stream object, and an output file stream object. Of course, they can be named whatever you wish, like any other C++ variable. 1 A disk file consists of a body of text on the disk, arranged in a way determined by your computer's Operating System (OS), which is responsible for keeping track of the information. If the file is deleted, moved, expanded, contracted, etc., the OS keeps track of exactly where it is on the disk and how much of it there is. The C/C++ facilities for working with disk files actually call OS subroutines to do the work. So before you can use a disk file, you have to establish a relationship between your file stream object and the disk file. More exactly, you have to ask the OS to connect your stream to the file. Fortunately, this is easy: Just tell the stream object that you want to "open" the disk file and supply the name of the disk file as a C-string; the open member function negotiates with the OS to locate that file on the disk and establish the connection between that file and your stream object. Continuing the example: ifstream my_input_file; // an input file stream object ofstream my_output_file; // an output file stream object my_input_file.open("input_data"); // open the file named "input_data" my_output_file.open("output_data"); // open the file named "output_data" Now the stream my_input_file is connected to the text file on disk named "input_data" and the stream my_output_file is connected to the text file on disk named "output_data". Instead of creating and then opening the file streams in separate statements, you can use a constructor that takes the file name as an argument; after doing the normal initializations, the constructor completes the initialization by opening the named file. The above four statements would then condense down to two: ifstream my_input_file("input_data"); // create and open ofstream my_output_file("output_data"); In both ways of opening a file, you can specify the file path or file name either with a C-string array or literal (as the above examples do), or in C++11 with a std::string. For example: string filename; cin >> filename; ifstream my_input_file(filename);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.