Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 12 / LAB1_CONSOLE - final / Text
.cpp// Copyright (C) 1991 - 1999 Rational Software Corporation
#include "Text.h"
#include <iostream.h>
#include <ostream.h>
//##ModelId=4709256800AB
Text::Text(char* txt, double sX, double sY):
ID(++count_ID),
startX(sX),
startY(sY)
{
// TODO: Add your specialized code here.
cout << "Constructor: Text object ID: " << ID << endl;
setText(txt);
}
//##ModelId=470924BF01B5
Text::setText(char* txt)
{
int i = 0;
while (txt[i]!='\0') {
txt[i++];
}
this->text=new char[i+1];
for (int j=0;j<i;j++) {
text[j]=txt[j];
}
text[i]='\0';
}
//##ModelId=470925300203
char* Text::getText() const
{
// TODO: Add your specialized code here.
int i = 0;
while (text[i]!='\0') {
text[i++];
}
char*txt = new char[i+1];
for (int j=0;j<i;j++) {
txt[j]=text[j];
}
txt[i]='\0';
return txt;
}
//##ModelId=470A15AA03B9
Text::~Text()
{
// TODO: Add your specialized code here.
delete text;
cout << "Destructor: Text object ID: " << ID << endl;
}
//##ModelId=470A2A86032C
long Text::count_ID = 0;
//##ModelId=470A2E39031C
void Text::draw()
{
// TODO: Add your specialized code here.
cout << "Text::draw() object ID: " << ID << " ";
cout << text << endl;
}
//##ModelId=472F625A009C
double Text::area() {
return 0;
}
//##ModelId=472F625A00BB
void Text::moveTo(double newX, double newY) {
}
//##ModelId=470A3EA602EE
Text& Text::operator+(const Text & txt )
{
// TODO: Add your specialized code here.
// NOTE: Requires a correct return value to compile.
char*t1 = getText();
char*t2 = txt.getText();
int s1 = 0 , s2 = 0;
int i = 0;
while (t1[i]!='\0') {
t1[i++];
}
s1 = i;
i=0;
while (t2[i]!='\0') {
t2[i++];
}
s2 = i;
char*text=new char[s1+s2+1];
for (int j=0;j<s1;j++) {
text[j]=t1[j];
}
for (j=0;j<s2;j++) {
text[j+s1]=t2[j];
}
text[s1+s2]='\0';
Text*t = new Text(text,0,0);
delete t1;
delete t2;
delete text;
return *t;
}
//##ModelId=470A459400BB
Text::Text(const Text& orig):
ID(++count_ID)
{
// ToDo: Add your specialized code here and/or call the base class
cout << "Constructor (copy): Text object ID: " << ID << endl;
char*txt = orig.getText();
setText(txt);
this->startX = orig.startX;
this->startY = orig.startY;
delete txt;
}
void Text::writeIn(ostream& o) const
{
o << (*this);
}
Соседние файлы в папке LAB1_CONSOLE - final