Repository navigation
Expand file tree
/
Copy pathProject_1.cpp
More file actions
107 lines (84 loc) · 2.34 KB
/
Copy pathProject_1.cpp
File metadata and controls
107 lines (84 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <iostream>
#include <string>
using namespace std;
class TextEditor {
private:
string text;
int cursor_pos;
public:
TextEditor() {
text = "";
cursor_pos = 0;
}
void addText(const string& newtxt) {
text.insert( cursor_pos, newtxt);
cursor_pos += newtxt.length();
}
void deleteText(int a) {
if ( cursor_pos > 0 && cursor_pos <= text.length()) {
text.erase( cursor_pos - 1, a );
cursor_pos--;
}
}
void moveCursorLeft(int b ) {
if ( cursor_pos > 0) {
cursor_pos -= b;
}
}
void backspace(int d) {
if (cursor_pos > 0) {
text.erase(cursor_pos - 1, d);
cursor_pos--;
}
}
void moveCursorRight(int c) {
if ( cursor_pos < text.length()) {
cursor_pos+= c;
}
}
void displayText() {
cout << text << endl;
cout << string( cursor_pos, ' ') << "^" << endl;
}
void displayText() {
cout << text << endl;
}
int findCursor() {
return cursor_pos;
}
string showText(int k) {
return text.substr(cursor_pos, k);
}
};
int main() {
string textin;
int left , right , deletion, back , k;
TextEditor editor;
cout << "Enter your string !!" << endl ;
cin >> textin ;
editor.addText(textin);
editor.displayText();
cout << "Enter number of positions to left :" << endl ;
cin >> left ;
editor.moveCursorLeft(left);
editor.displayText();
cout << "Enter number of positions to right :" << endl ;
cin >> right ;
editor.moveCursorRight(right);
editor.displayText();
cout << "Enter number of letter to delete (will delete from right) :" << endl ;
cin >> deletion ;
editor.deleteText(deletion);
editor.displayText();
cout << "Enter number of letter to backspace : :" << endl ;
cin >> back ;
editor.backspace(back);
editor.displayText();
cout << "Enter value for k for show text :" << endl ;
cin >> k ;
cout << editor.showText(k) << endl;
editor.findCursor();
cout << "Final String : " << endl;
editor.displayTextFinal();
return 0;
}