C ++中的简单文本编辑器 [英] Simple text editor in c++

查看:109
本文介绍了C ++中的简单文本编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将创建一个简单的逐行文本编辑器.每页包含20行,每行最多包含100个字符.您可能最多有1,000页,而它仅从1页开始,并在用户键入时添加更多页.必须在需要时动态创建每个页面.创建一个Page类,然后在创建Editor类时,Editor类可以创建一个包含1000个指向Page类的指针的数组. (添加新页面时应构建实际页面)
每次都显示一个页面,页面编号在顶部,每行的左侧.底部有一个命令行,它显示了可能的命令,如下所示.
[命令:行号允许您编辑行,"N"跳至下一页,"P"跳至上一页,"Dn"删除第n行– D3删除第3行] ____

这是我所做的,并且不确定如何从此处继续:

You will make a simple line-by-line text editor. Each page contains 20 lines and each line contains up to 100 characters. You may have up to 1,000 pages, while it starts from only 1 page and adds more pages when user types in. Each page has to be dynamically created when needed. Create a Page class and the Editor class can create an array of 1000 pointers to the Page class during the construction of the Editor class. (Actual page should be constructed when a new page is added)
At each time, a page is displayed with page number on the top and the line numbers on the left side of each line. There is a command line at the bottom and it shows possible commands as shown below.
[commands: line number allows you to edit the line, „N‟ goes to next page, „P‟ goes to the previous page, „Dn‟ deletes the line n – D3 deletes line 3]____

Here''s what I have done and not sure how to proceed from here:

const int MAX_LINE = 20;<br />
const int MAX_CHAR = 100;<br />
const int MAX_PAGES = 1000;<br />
class Page {<br />
char aPage[MAX_LINE][MAX_CHAR];<br />
public:<br />
void print();<br />
void edit();<br />
void edit_line(int i);<br />
void delete_line(int i);<br />
};<br />
typedef Page * PagePtr;<br />
class Editor {<br />
PagePtr *pages;<br />
int cur;<br />
int total;<br />
public:<br />
Editor();<br />
void show_commands();<br />
void display_cur_page();<br />
void next();<br />
void prev();<br />
void edit();<br />
};

推荐答案

这似乎需要回到笔记中,并研究如何在类内部创建方法.例如,Page类可能需要某种构造函数,因此当您创建新页面时,它将设置一些初始值. edit方法将需要接受文本并将其添加到页面中,为文本分配空间,等等.
如果您使用Google搜索示例文本编辑器,则应该找到很多帮助您的东西.
This looks like you need to go back to your notes and study how to create methods inside your classes. For example the Page class will probably need some sort of constructor so when you create a new page it will set up some initial values. The edit method will need to accept text and add it to the page, allocating space for the text as it goes, etc. etc.
If you use Google to search for sample text editors you should find lots to help you.


为什么1个投票者?

这是我所做的,不确定从这里开始如何进行:"

您不能只是礼貌地回答(如做的那样)关于如何进行的建议?

投票太快了.
Why the 1 vote guys ?

"Here''s what I have done and not sure how to proceed from here:"

You couldn''t just answer (as was done) politely with a suggestion of how to proceed ?

Too quick to vote.


这篇关于C ++中的简单文本编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆