64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
//---------------------------------------------------------------
class Text
{
private:
char S[50];
int length;
int head;
int tail;
int now;
public:
Text();
~Text();
void upDate(); //更新length和tail等数据
void getChar();
char getAChar(int n);
void print();
int getNow();
int getTail();
int getHead();
bool plusNow();
};
Text::Text()
{
for(int i=0;i<50;i++)
this->S[i]='\0';
this->length=0;
this->head=0;
this->tail=0;
this->now=0;
}
Text::~Text(){}
void Text::upDate()
{
int count=0;
while(this->S[count]!='\0')
count++;
this->length=count;
this->tail=this->length;
cout<<"this->length:"<<this->length
<<" this->tail:"<<this->tail<<endl;
}
void Text::getChar()
{
cout<<"cin:";
cin>>this->S;
}
void Text::print()
{
cout<<":"<<this->S<<endl;
}
char Text::getAChar(int n)
{
char c=this->S[n];
return c;
}
int Text::getNow()
{
int n=this->now;
return n;
}
int Text::getTail()
{
return this->tail;
}
int Text::getHead()
{
return this->head;
}
bool Text::plusNow()
{
if(this->now<this->tail)
{
this->now++;
return true;
}
else
return false;
}
int main()
{
Text P,T;
cout<<"T:"<<endl;
T.getChar();
T.upDate();
T.print();
cout<<"P:"<<endl;
T.getChar();
P.upDate();
P.print();
int now,tail;
now=P.getNow();
tail=P.getTail();
return 0;
}