Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have the solution for this problem, but I want to implement file handline in my code. So that when I edit a text file

image text in transcribed

image text in transcribed

I have the solution for this problem, but I want to implement file handline in my code. So that when I edit a text file in my terminal the changes should be reflected in the text file. Please someone help me to do this.

#...............Solution..............#

#include  #include  #include  using namespace std; class Node { public: string line; Node* next; }; class LineEditor { private: Node *head; public: LineEditor() { head = NULL; } void insert(int pos, string str) { Node *tmp = new Node(); tmp->line = str; if (head == NULL) head = tmp; else if (pos == 0 || pos == -1) { Node *p = head; while (p->next != NULL) p = p->next; p->next = tmp; } else { Node *p = head; while (pos > 2) { p = p->next; pos--; if (p->next == NULL && pos > 2) return; } tmp->next = p->next; p->next = tmp; } } void remove(int p1, int p2) { if (head != NULL) { Node *p; if (p1 == 1 || p1 == -1) { p = head; if (head->next == NULL) head = NULL; else { if (p2 == -1) { head = head->next; delete (p); } else while (p1 next != NULL) { p1++; head = head->next; delete (p); } } } else { Node *tmp = p = head; for (int i = 1; i next; if (p->next == NULL && i > p1) return; } if (p2 == -1) { tmp->next = p->next; delete (p); p = tmp->next; } else if (p1 == -1) while (p != NULL) { tmp->next = p->next; delete (p); p = tmp->next; } else while (p1 next != NULL) { tmp->next = p->next; delete (p); p = tmp->next; } } } } void print(int p1, int p2) { Node *p = head; int cnt = 1; for (int i = 1; i next; if (p->next == NULL && i > p1) return; } if (p1 == -1) while (p != NULL) { cout  " line next; } else if (p2 == -1) cout  " line  " line next; } } }; int main() { LineEditor editor; string str, fileName; int lineCnt = 1, func = 0, p1 = -1, p2 = -1; cin >> str; if (str == "EDIT") { cin >> fileName; cin.ignore(); while (true) { cout  "; getline(cin, str); if (str.length()   4> I 3 5. Write a simple line editor. Keep the entire text on a linked list, one line in a separate node. Start the program with entering EDIT file, after which a prompt appears along with the line number. If the letter I is entered with a number following it, then insert the text to be followed before line n. If I is not followed by a number, then insert the text before the current line. If D is entered with two numbers nand m. one n. or no number following it, then delete lines through m. line n. or the current line. Do the same with the command L, which stands for listing lines. If A is entered, then append the text to the existing lines. Entry E significs exit and saving the text in a file. Here is an example: EDIT testfile 1> The first line 2> 3> And another line 3> The second line 4> One more line 5> L 1> The first line 2 3> The second line 4>One more line 5> And another line // This is now line 5, not 3: 5> D 2 // line 5, since I was issued from line 57 4> L // line 4, since one line was deleted: 1> The first line 2> The second line // this and the following lines 3> One more line // now have new numbers: 4 And another line 4> B a. each class in own.cpp/.h b. main is in main.cpp c. no class definitions in main.cpp d. #ifndef/#define should be at the top of every .h e. source code can be in one folder or multiple

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

Project management skills and/or experience desirable

Answered: 1 week ago