Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab exercise Computing III 9 1. There is text file (testl.txt) which contains mu

ID: 3917805 • Letter: L

Question

Lab exercise Computing III 9 1. There is text file (testl.txt) which contains multi-line data including the name "John" at multiple lines as follows. John is a good student. He studies regularly for 8 hours daily and attends to every lecture in school. John wants to be a computer programmer John is also a great sportsman. Open a new file (test2.txt) replacing the name “John" with "Smith" 2. Assume that a text file (text3.txt) stores employee data as follows. 1001, John, Jones, Sales, 10000 1002, Jane,Smith, Production, 8000 1003, Keith,Marshall CustomerService,7000 1004,Pat, Wallace,Sales,9000 The fields are separated by comma. The fields are employee number, first name, last name, department name and salary Write a program which fetches the first name and salary of the employee based on input of employee number

Explanation / Answer

#include #include #include using namespace std; string replaceAll(string str, const string& from, const string& to) { size_t start_pos = 0; while((start_pos = str.find(from, start_pos)) != string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); } return str; } int main() { ifstream in("test1.txt"); ofstream out("test2.txt"); string str; while(getline(in, str)) { out