Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please provide correct c++ code ASAP with outputs please Line Editor = Linked Lists //Complete the line editor program below by implementing all member functions

Please provide correct c++ code ASAP with outputs please

Line Editor = Linked Lists

//Complete the line editor program below by implementing all member functions as instructed.

#include #include #include #include using namespace std;

struct node { string line; node* next, * prev; node() {} node(string s) :line(s) {} };

class editor { private: node* head, * tail; node* current; public: editor() { head = new node; tail = new node; head->next = tail; tail->prev = head; current = head; } void insert(node* newLine, node* before); // insert a new line after void insert(string s); // create a line of s and insert it after using the preceding function void multipleInsert(); //Insert multiple lines with a "." as a terminal line void forward(); // move one line forward unless the next is void backward(); // move one line backward unless the current is head void removeCurrent(); // delete the current line (node) and let current point to the preceding line void displayCurrent(ostream& os); // print the current line void displayAll(ostream& os); // print all lines void save(ostream& os); // print all lines bool readLine(istream& is); // read a new line and insert it after using insert(string) void clear(); // delete all lines void load(ifstream& f); // erase the entire workplace and load a file to the workplace void gotoLine(); // Ask the user to enter line number (i) then make the line(i) void find(node* start = nullptr); // Ask the user to enter a string. Search the entire workspace for this string; // if found, display the found instance, and prompt the user for a subsequent instance. void replace(node* start = nullptr); // Similar to the function find but with the option of replace a string by another string };

void menu() { system("cls"); cout << "press: "; cout << " i to insert a new line "; cout << " m to insert multiple lines "; cout << " d to delete the current new line "; cout << " c to display the current line "; cout << " g to go line "; cout << " v to view the entire workspace "; cout << " e to erase the entire workspace "; cout << " n to move the current line forward "; cout << " p to move the current line backward "; cout << " l to load a file into workspace "; cout << " s to store the workplace to a file "; cout << " f to find a string "; cout << " r to replace a string "; cout << " x to exit "; } int main() { ifstream fi; ofstream fo; string fname; editor e; char c='.'; while (true) { menu(); //c = _getch(); if (c == 'x') break; switch (c) { case ('i'): cout << "New Line: "; e.readLine(cin); break; case ('m'): e.multipleInsert(); break; case ('d'): e.removeCurrent(); break; case ('c'): e.displayCurrent(cout); break; case ('e'): e.clear(); break; case ('l'): cout << "File Name: "; getline(cin, fname); fi.open(fname); e.load(fi); break; case ('n'): e.forward(); e.displayCurrent(cout); break; case ('p'): e.backward(); e.displayCurrent(cout); break; case ('v'): e.displayAll(cout); break; case ('g'): e.gotoLine(); e.displayCurrent(cout); break; case ('s'): cout << "File Name: "; getline(cin,fname); fo.open(fname); e.save(fo); fo.close(); break; case ('f'): e.find(nullptr); break; case ('r'): e.replace(nullptr); break; } cout << endl << "-----Press a key of your choice or space to continue----- "; c=_getch(); } }

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

How To Make A Database In Historical Studies

Authors: Tiago Luis Gil

1st Edition

3030782409, 978-3030782405

More Books

Students also viewed these Databases questions