Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
4
Добавлен:
30.05.2020
Размер:
298.71 Кб
Скачать

Література

  1. Архангельский А.Я. Программирование в C++ Builder, 7 изд.,Бином,2010. — 1304 с.

  2. Бобровский С. Самоучитель программирования на C++ в системе C++ Builder. ДЕСС, 2003. — 810 с.

  3. Культин Н.Б. Самоучитель C++ Builder., Высшая школа,2006. — 380 с.

  4. Архангельский А.Я. C++ Builder 6 справочное пособие, 2005. — 635 с.

  5. Алексанкин Т.А. BorlandC++, 2003— 540 с.

  6. Ермолаев В., Сорока Т. C++ BuilderКнига рецептов, 2003. — 560 с.

  7. Культин Н.Б. C++ Builderв задачах и примерах, 2000. — 400 с.

  8. Бобровский С. Технологии C++ Builder.,2005. — 490 с.

  9. Парта С. Язык программирования C++ Лекции и упражениния, 1999. – 630 с.

Додаток а Лістинг модуля StringUnit

#include <vcl.h>

#pragma hdrstop

#include "StringUnit.h"

#include "Stdio.h"

#include "Io.h"

#include "WorkWithText.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)

{

WorkWithText *WWT=new WorkWithText;

WWT->ReadFromFile(Memo1);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N4Click(TObject *Sender)

{

WorkWithText *WWT=new WorkWithText;

WWT->ChangeWordOrder(Memo2);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N5Click(TObject *Sender)

{

WorkWithText *WWT=new WorkWithText;

WWT->TextFromFirstLetter(Memo2);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N6Click(TObject *Sender)

{

WorkWithText *WWT=new WorkWithText;

WWT->TextWithoutFirstLetter(Memo2);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N7Click(TObject *Sender)

{

WorkWithText *WWT=new WorkWithText;

WWT->WriteToFile(Memo2);

WWT->ReadFromFile(Memo1);

}

Додаток б Лістинг класуWorkWithText

class WorkWithText{

public:

void ReadFromFile(TMemo *memo)

{

this->info="";

if((this->F=fopen("info.txt", "r"))==NULL)

{

ShowMessage("Файл \"info.txt\" не створений!");

return;

}

memo->Clear();

while(!feof(this->F))

{

fscanf(F,"%s ",&this->temp);

this->info+=temp;

this->info+=" ";

}

memo->Lines->Add(this->info);

fclose(this->F);

}

void WriteToFile(TMemo *memo)

{

memo->Lines->SaveToFile("info.txt");

}

void ChangeWordOrder(TMemo *memo)

{

this->info="";

int IsFirst=0,isWord=0;

int a=0,b=0;

char temp1[255],temp2[255];

if((this->F=fopen("info.txt", "r"))==NULL)

{

ShowMessage("Файл \"info.txt\" не створений!");

return;

}

memo->Clear();

while(!feof(this->F))

{

fscanf(F,"%s ",&this->temp);

if((this->temp[0]>='A')&&(this->temp[0]<='z'))

if(IsFirst==0)

{

strcpy(temp1,this->temp);

IsFirst=1;

}

else

{

strcpy(temp2,this->temp);

isWord=1;

}

}

fclose(this->F);

if(isWord!=1)

{

ShowMessage("В файлі відсутні слова, які написані латинецею. Буде відображено вміст початкового файлу");

this->ReadFromFile(Form1->Memo2);

return;

}

this->F=fopen("info.txt", "r");

while(!feof(this->F))

{

fscanf(F,"%s ",&this->temp);

if(strcmp(this->temp,temp1)==0)

this->info+=temp2;

else

if(strcmp(this->temp,temp2)==0)

this->info+=temp1;

else

this->info+=this->temp;

this->info+=" ";

}

fclose(this->F);

String temps1=temp1,temps2=temp2;

ShowMessage("Перше слово, яке написане латинецею: '"+temps1+"'. Останнє слово, яке написане латиницею: '"+temps2+"'. Слова змінили свое місцеположення.");

memo->Lines->Add(this->info);

}

void TextFromFirstLetter(TMemo *memo)

{

this->info="";

if((this->F=fopen("info.txt", "r"))==NULL)

{

ShowMessage("Файл \"info.txt\" не створений!");

return;

}

memo->Clear();

while(!feof(this->F))

{

fscanf(F,"%s ",&this->temp);

if((this->temp[0]>='А')&&(this->temp[0]<='я'))

{ this->info+=temp[0]; this->info+=" ";}

}

fclose(this->F);

memo->Lines->Add(this->info);

}

void TextWithoutFirstLetter(TMemo *memo)

{

this->info="";

String temps;

if((this->F=fopen("info.txt", "r"))==NULL)

{

ShowMessage("Файл \"info.txt\" не створений!!");

return;

}

memo->Clear();

while(!feof(this->F))

{

fscanf(F,"%s ",&this->temp);

if((this->temp[0]>='А')&&(this->temp[0]<='я'))

{

temps=this->temp;

temps=temps.SubString(2,temps.Length());

info+=temps;

}

else

this->info+=this->temp;

this->info+=" ";

}

fclose(this->F);

memo->Lines->Add(this->info);

}

private:

FILE *F;char temp[255];String info;

};