Question
in c++ do the following:: Read in an XML file, create a new Employee object for each. The following steps should be able to be
in c++ do the following:: Read in an XML file, create a new "Employee" object for each. The following steps should be able to be completed.
1) Obtain the name of an XML file to read from the command line (argv[1]). Print an error message and halt the program if there is no command-line argument provided, or if the file does not exist. 2) Read each XML record in the file by repeatedly calling Employee::fromXML, which creates an Employee object on-the-fly, and store it in a vector (I recommend using unique_ptrs in the vector). 3) Loop through your vector and print to cout the Employee data for each object (using the display member function). 4) The next step is to create a new file of fixed-length Employee records. This is explained below. Write the records for each employee to your new file (call it employee.bin) in the order they appear in your vector. Open this file as an fstream object with both read and write capability, and in binary format. 5) Clear your vector in preparation for the next step. 6) Traverse the file by repeated calls to Employee::read, filling your newly emptied vector with Employee pointers for each record read. 7) Loop through your vector and print to cout an XML representation of each Employee using Employee::toXML. 8) Search the file for the Employee with id 12345 using Employee::retrieve. 9) Change the salary for the retrieved object to 150000.00 10) Write the modified Employee object back to file using Employee::store 11) Retrieve the object again by id (12345) and print its salary to verify that the file now has the updated salary. 12) Create a new Employee object of your own with a new, unique id, along with other information. 13) Store it in the file using Employee::store. 14) Retrieve the record with Employee::retrieve and display it to cout.
Your Employee class must contain at least the following: void display(std::ostream&) const; // Write a readable Employee representation to a stream void write(std::ostream&) const; // Write a fixed-length record to current file position void store(std::iostream&) const; // Overwrite (or append) record in (to) file void toXML(std::ostream&) const; // Write XML record for Employee static Employee* read(std::istream&); // Read record from current file position static Employee* retrieve(std::istream&,int); // Search file for record by id static Employee* fromXML(std::istream&); // Read the XML record from a stream
Here is a sample of the employee.xml file that will be used: 40000 John Doe 1234
2230 W. Treeline Dr.
Tucson Arizona USA 520-742-2448 60000 Jane Doe 4321 140000 Michigan Jack Dough 12345 Dearborn USA 303-427-0153
24437 Princeton
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started