You are on page 1of 6

Текст програми:

/*#include <cstdlib>

#include <iostream>

using namespace std;

int main(int argc, char *argv[])

system("PAUSE");

return EXIT_SUCCESS;

*/

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

#include <iostream.h>

#include <fstream.h>

//#include <stdarg.h>

#include <stdlib.h>

#include <string.h>

#pragma hdrstop

using namespace std;

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

class TStringConv

protected:

char* cString;

int iStringLen;
char cCharProcessing(char cInput);

public:

void vProcessConv(void);

TStringConv(int iStrLen = 0);

~TStringConv();

friend ifstream& operator >> (ifstream& s, TStringConv& sc)

int iCharCount = 0;

while((!s.eof()) && iCharCount < sc.iStringLen) {

s.get(sc.cString[iCharCount++]); /* Чтение символ*/

if(sc.cString[iCharCount-1] == '\n' || sc.cString[iCharCount-1] == '\r') { /* Подсчет */

sc.cString[iCharCount] = '\0';

if(sc.cString[iCharCount-1] != '\r') break;

} //else iCharCount++;

// s.get(sc.cString,sc.iStringLen,'\n');

return s;

friend ofstream& operator << (ofstream& s, TStringConv& sc)

s << sc.cString << endl;

return s;

};

typedef TStringConv* PTStringConv;

TStringConv::TStringConv(int iStrLen)

iStringLen = iStrLen;

if(iStringLen) cString = new char[iStringLen];

}
TStringConv::~TStringConv()

if(iStringLen) delete cString;

/*

istream& operator >> (istream& s, TStringConv& sc)

s.get(sc.cString,sc.iStringLen,'\n');

return s;

ostream& operator << (ostream& s, TStringConv& sc)

s << sc.cString << endl;

return s;

} */

void TStringConv::vProcessConv(void)

for(int j = 0;j < iStringLen && cString[j];j++) {

char cChar = cCharProcessing(cString[j]); /* Обработка */

cString[j] = cChar;

TStringConv** ppcStringProcessing(TStringConv **ppscText,int iStrCount)

for(int i = 0;i < iStrCount;i++)

ppscText[i]->vProcessConv(); /* Обработка */

return ppscText;

#pragma argsused
int main(int argc, char* argv[])

ifstream fileIn("Input.txt"); /* Объявл.файлы */

/* Открытие Вх. */

/* Счетчики=0 */

int iCharCount = 0, iStrMaxCharCount = 0, iStrCount = 0, i = 0, j = 0;

TStringConv **ppscText;

if (fileIn == NULL) { /* Удачно? */

cerr << "Cannot open input file." << endl; /* нет- Ошибка */

return 1; /* Возврат */

ofstream fileOut("Output.txt"); /* Открытие Вых.*/

if (fileOut == NULL) { /* Удачно? */

fileIn.close(); /* нет- Закр.Вх.*/

cerr << "Cannot open output file." << endl; /* Ошибка */

return 1; /* Возврат */

while (!fileIn.eof()) { /* Цикл подсчета*/

char cChar;

fileIn.get(cChar); /* Чтение символ*/

if(cChar == '\n' || cChar == '\r') { /* Подсчет */

if(iCharCount > iStrMaxCharCount) iStrMaxCharCount = iCharCount;

iCharCount = 0;

if(cChar != '\r') iStrCount++;

} else iCharCount++;

iStrCount++;

ppscText = new PTStringConv[iStrCount];

if (ppscText == NULL) { /* Удачно? */

cerr << "Cannot allocate memory." << endl; /* нет- Ошибка */

fileIn.close(); /* Закрытие Вх. */

fileOut.close(); /* Закрытие Вых.*/

return 1; /* Возврат */
}

iStrMaxCharCount++;

for(i=0;i<iStrCount;i++) {

ppscText[i] = new TStringConv(iStrMaxCharCount);

if (ppscText[i] == NULL) { /* Удачно? */

cerr << "Cannot allocate memory." << endl; /* нет- Ошибка */

for(j = 0;j < i;j++) /*Освобождаем */

delete ppscText[j]; /*память */

fileIn.close(); /* Закрытие Вх. */

fileOut.close(); /* Закрытие Вых.*/

return 1; /* Возврат */

fileIn.clear();

fileIn.seekg(0,ios_base::beg);

// iStrCount = 0;

int k = 0;

while ((!fileIn.eof()) && k < iStrCount) { /* Цикл чтения */

fileIn >> *(ppscText[k]); /* Чтение строки*/

k++;

// iStrCount++;

ppcStringProcessing(ppscText,iStrCount);

for(int i = 0;i < iStrCount;i++)

fileOut << *(ppscText[i]); /* Вывод */

for(int i = 0;i < iStrCount;i++) /*Освобождаем */

delete ppscText[i]; /*память */

delete ppscText;

fileIn.close(); /* Закрытие Вх. */

fileOut.close(); /* Закрытие Вых.*/

cout << "All OK!" << endl;

cin.get(); //getch();

return 0;
}

char TStringConv::cCharProcessing(char cInput)

if(cInput >= 'а' && cInput <= 'я')

return cInput - 32;

else return cInput;

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

Висновки: в даній лабораторній роботі було вивчено класи, оператори та потоки

You might also like