Question: Please do changes in this code. This is a simple Nodepad code in C++ using multilevel linked list. If you can do please add some
Please do changes in this code. This is a simple Nodepad code in C++ using multilevel linked list. If you can do please add some additional functionalities in it.
#include
#include
#include
#include
using namespace std;
class Node {
public:
char data;
Node* left = NULL;
Node* right = NULL;
Node* up = NULL;
Node* down = NULL;
};
Node* head, * tail, * upper_head, * lower_head, root;
Node** arr = new Node * [100];
int row = 0;
void reset() {
head = NULL;
tail = NULL;
}
Node* newNode(char val) {
Node* node = new Node();
node->data = val;
if (head == NULL) {
head = node;
tail = node;
}
return node;
}
void verticle_link() {
upper_head = arr[row - 1];
lower_head = head;
}
void make_doubly_list(char res) {
Node* temp = newNode(res);
tail->right = temp;
temp->left = tail;
tail = temp;
if (row != 0) {
if (upper_head != NULL) {
temp->up = upper_head;
upper_head->down = temp;
upper_head = upper_head->right;
}
}
}
void make_arr() {
arr[row] = head;
reset();
row++;
}
class Note : public Node {
char res{};
string err = "\t oh no! invalid entry! ";
public:
void header();
void menu();
void enterText();
void save(char);
void read();
};
void Note::header() {
cout << "\t Note-pad /c++" << endl << endl;
}
void Note::menu() {
lmao: header();
cout << "1. Enter note" << endl;
cout << "2. Read Notes" << endl;
cout << "3. Exit program" << endl;
repeat: try {
cout << " Enter response: ";
cin >> res;
if (res == '1') {
enterText();
}
else if (res == '2') {
read();
}
else if (res == '3') {
exit(0);
}
else if (res == '4') {
cout << arr[0]->right->right->down->data;
}
else
throw err;
}
catch (string err) {
cout << err << endl;
goto repeat;
}
goto lmao;
}
void Note::enterText() {
system("CLS");
cout << "Enter 0 to stop" << endl;
cout << "Enter here: " << endl;
while (1) {
res = _getch();
if (res == '0')
break;
else if (res == ' ') {
cout << endl;
save(' ');
res = _getch();
cout << res;
make_arr();
verticle_link();
make_doubly_list(res);
save(res);
}
else {
cout << res;
make_doubly_list(res);
save(res);
}
}
}
void Note::save(char r) {
if (r != '0') {
ofstream note_write("notepad.txt", ios::app);
note_write << r;
}
}
void Note::read() {
string data;
ifstream note_read("notepad.txt");
while (getline(note_read, data)) {
cout << data << endl;
}
}
int main() {
Note notepad_1;
notepad_1.menu();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
