📄 shit5.cpp
字号:
#include<iostream>
#include<string>
#include<fstream>
#include<process.h>
#include<stdlib.h>
#include<cctype>
#include<stdio.h>
#include <conio.h>
const int max_filename_length=20;
using namespace std;
enum Error_code{overflow,rang_error,underflow,success,fail};
template<class Node_entry>
struct Node{
Node_entry entry;
Node<Node_entry>*next;
Node<Node_entry>*back;
Node();
Node(Node_entry item,Node<Node_entry>*link_back,
Node<Node_entry>*link_next);
};
template<class Node_entry>
Node<Node_entry>::Node(Node_entry item,Node<Node_entry>*link_back,
Node<Node_entry>*link_next)
{
next=link_next;
back=link_back;
entry=item;
}
template<class Node_entry>
Node<Node_entry>::Node()
{
next=back=NULL;
}
template<class List_entry>
class List{
public:
List();
~List();
int size()const;
bool empty()const;
void clear();
void traverse(void(*visit)(List_entry &));
Error_code retrieve(int position,List_entry &x)const;
Error_code replace(int position,const List_entry &x);
Error_code remove(int position,List_entry &x);
Error_code insert(int position,const List_entry &x);
protected:
int count;
mutable int current_position;
mutable Node<List_entry>*current;
void set_position(int position)const;
};
template <class List_entry>
List<List_entry>::List()
{
count=0;
current_position=0;
current=NULL;
}
template <class List_entry>
List<List_entry>::~List()
{
clear();
}
template <class List_entry>
int List<List_entry>::size()const
{
return count;
}
template<class List_entry>
void List<List_entry>::traverse(void(*visit)(List_entry&x))
{
Node<List_entry>* p;
set_position(0);
p=current;
for(int i=0;i<count;i++){
(*visit)(p->entry);
p=p->next;
}
}
template<class List_entry>
bool List<List_entry>::empty()const
{
if(count==0)return true;
return false;
}
template<class List_entry>
Error_code List<List_entry>::remove(int position,List_entry&x)
{
Node<List_entry>*s,*q;
if(position<0||position>count)
return rang_error;
if(position==0)
{
set_position(0);
s=current;
current=s->next;
x=s->entry;
delete s;
count--;
}
else
{
set_position(0);
q=current;
for(int i=0;i<position-1;i++)q=q->next;
if(current==NULL)return underflow;
else
{
s=q->next;
q->next=s->next;
if(s->next!=NULL)
s->next->back=q;
x=s->entry;
delete s;
count--;
}
}
return success;
}
template<class List_entry>
Error_code List<List_entry>::replace(int position,const List_entry&x)
{
Node<List_entry>*p;
if(position<0||position>count)
return rang_error;
set_position(position);
p=current;
p->entry=x;
return success;
}
template <class List_entry>
void List<List_entry>::set_position(int position)const
{
if(current_position<=position)
for(;current_position!=position;current_position++)
current=current->next;
else
for(;current_position!=position;current_position--)
current=current->back;
}
template<class List_entry>
Error_code List<List_entry>::retrieve(int position,List_entry&x)const
{
if(position<0||position>count)
return rang_error;
set_position(position);
x=current->entry;
return success;
}
template<class List_entry>
void List<List_entry>::clear()
{
Node<List_entry>*p;
set_position(0);
p=current;
if (p!=NULL)
current=p->next;
while(current!=NULL){
delete p;
p=current;
current=p->next;
}
}
template <class List_entry>
Error_code List<List_entry>::insert(int position,const List_entry &x)
{
Node<List_entry>*new_node,*following,*preceding;
if(position<0||position>count)return rang_error;
if(position==0){
if(count==0)following=NULL;
else{
set_position(0);
following=current;
}
preceding=NULL;
}
else{
set_position(position-1);
preceding=current;
following=preceding->next;
}
new_node=new Node<List_entry>(x,preceding,following);
if(new_node==NULL)return overflow;
if(preceding!=NULL)preceding->next=new_node;
if(following!=NULL)following->back=new_node;
current=new_node;
current_position=position;
count++;
return success;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
class String
{
public:
String(){};
~String(){};
String(const String ©);
String(const char *copy);
String(List<char>©);
void print();
void operator=(const String ©);
const char*c_str()const;
void changetobig();
void changetosmall();
protected:
char* entries;
int length;
};
bool operator==(const String &first,const String &second);
bool operator>(const String &first,const String &second);
bool operator<(const String &first,const String &second);
bool operator>=(const String &first,const String &second);
bool operator<=(const String &first,const String &second);
bool operator!=(const String &first,const String &second);
int strlen(const String &s)
{
const char *ch=s.c_str();
for(int i=0;ch[i]!='\0';i++);
return i;
}
int strlen_zimu(const char* ch)
{
int num=0;
int i=0;
while(ch[i]!='\0')
{
if((ch[i]>=65&&ch[i]<=90)||(ch[i]>=97&&ch[i]<=122))
num++;
i++;
}
return num;
}
void strcpy(String ©,const String &original)
{
int len=strlen(original);
const char*str=original.c_str();
const char*ch=copy.c_str();
char*ch2;
ch2=new char[len+1];
for(int i=0;i<len;i++)ch2[i]=str[i];
ch2[len]='\0';
copy=ch2;
}
void strncpy(String ©,const String &original,int n)
{
char *cfirst1;
cfirst1=new char[n+1];
const char *csecond=original.c_str();
for(int i=0;i<n;i++)cfirst1[i]=csecond[i];
cfirst1[n]='\0';
copy=cfirst1;
}
int strstr(const String &text,const String &target)
{
int i,j,k;
int len1,len2;
const char *cfirst=text.c_str();
const char *csecond=target.c_str();
len1=strlen(text);
len2=strlen(target);
for(i=0;i<len1;i++)
{
for(j=i,k=0;((cfirst[j]==csecond[k])&&(j<len1)&&(k<len1));j++,k++);
if(k==len2)return(i);
}
return (-1);
}
void strcat(String &add_to,const String &add_on)
{
const char *cfirst=add_to.c_str();
const char *csecond=add_on.c_str();
char*copy=new char[strlen(cfirst)+strlen(csecond)+1];
strcpy(copy,cfirst);
strcat(copy,csecond);
add_to=copy;
delete[]copy;
}
String::String(const char *in_string)
{
length=strlen(in_string);
entries=new char[length+1];
strcpy(entries,in_string);
}
String::String(const String ©)
{
length=strlen(copy);
entries=new char[length+1];
strcpy(entries,copy.entries);
}
String::String(List<char>&in_list)
{
length=in_list.size();
entries=new char[length+1];
for(int i=0;i<length;i++)in_list.retrieve(i,entries[i]);
entries[length]='\0';
}
const char*String::c_str()const
{
return(const char *)entries;
}
void String::changetobig()
{
int i;
for(i=0;i<length;i++)
{
if(entries[i]>=97&&entries[i]<=122)
entries[i]=entries[i]-32;
}
}
void String::changetosmall()
{
int i;
for(i=0;i<length;i++)
{
if(entries[i]>=65&&entries[i]<=90)
entries[i]=entries[i]+32;
}
}
void String::operator=(const String ©)
{
length=strlen(copy);
const char*str=copy.c_str();
entries=new char[length+1];
for(int i=0;i<length;i++)entries[i]=str[i];
entries[length]='\0';
}
void String::print()
{
for(int index=0; index<length;index++)
cout<<entries[index];
cout<<endl;
}
bool operator==(const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())==0;
}
bool operator> (const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())>0;
}
bool operator< (const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())<0;
}
bool operator>= (const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())>=0;
}
bool operator<= (const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())<=0;
}
bool operator!=(const String &first,const String &second)
{
return strcmp(first.c_str(),second.c_str())!=0;
}
char tolower(char ch)
{
if(ch>=97)return ch;
else return (ch+32);
}
bool user_says_yes()
{
char ch;
cout<<"确定?"<<endl;
cin>>ch;
if(ch=='y'||ch=='Y')return true;
return false;
}
String read_in(istream &input)
{
List<char>temp;
int size=0;
char c;
while((c=input.peek())!=EOF&&(c=input.get())!='\n')
temp.insert(size++,c);
String answer(temp);
return answer;
}
void write(String &s)
{
//freopen(out_file.c_str(),"w",stdout);
cout<<s.c_str()<<endl;
}
String read_in(istream &input,int &terminator)
{
List<char>temp;
int size=0;
char c;
while((c=input.peek())!=EOF && (c=input.get())!='\n')
temp.insert(size++,c);
terminator=c;
String answer(temp);
return answer;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
void view()
{
cout << " ***************************可用操作********************************** " <<endl
<< " * 保存文档 a(save) 回到起始行 b(egin) * " <<endl
<< " * 改变当前段的部分内容 c(hange) 删除当前段 d(el) * " <<endl
<< " * 回到文件尾 e(nd) 查找字符串 f(ind) * " <<endl
<< " * 段跳转 g(o) 帮助 h(elp) * " <<endl
<< " * 插入段 i(nsert) 字符数 l(ength)* " <<endl
<< " * 跳至下一行 n(ext) 跳至上一行 p(rior) * " <<endl
<< " * 结束任务 q(uit) 读文档 r(ead) * " <<endl
<< " * 改变当前段的全部内容 s(ubstitute) 阅览文档 v(iew) * " <<endl
<< " * 写文档 w(rite) 改为小写 k(small)* " <<endl
<< " * 改为大写 m(large) 复制段 j(copy) * " <<endl
<< " * 语言选择(默认为中文) t(language) * " <<endl
<< " ********************************************************************* " <<endl;
}
class Editor:public List<String>
{
public:
bool get_command();
void run_command();
Editor();
private:
int mode;
int num1;
int num2;
char current_file[max_filename_length];
char user_command;
Error_code next_line();
Error_code previous_line();
Error_code goto_line();
Error_code insert_line();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -