Объектно-ориентированное программирование. Написание программы, которая в заданной Базе маршрутов поездов находит минимальный по времени маршрут между двумя пунктами, страница 2

void set_focus(char focuss);

};

class CLabel

{

unsigned int x, y;

CString caption;

public:

CLabel(){};

~CLabel(){};

void set(unsigned xx, unsigned yy, char *text){x=xx; y=yy; caption = text;};

void draw();

};

class CEdit: public CObject

{

protected:

CString text;

public:

CEdit();

~CEdit(){};

void draw();

void press_key(unsigned char key);

CString get_text();

};

class CButton: public CObject

{

protected:

CString caption;

public:

CButton();

~CButton(){};

void draw();

void down_up();

};

class CFindButton: public CButton

{

public:

CFindButton();

~CFindButton(){};

void press_key(CApplication &Application, unsigned char key);

};

class CQuitButton: public CButton

{

public:

CQuitButton();

~CQuitButton(){};

void press_key(CApplication &Application, unsigned char key);

};

class CForm: public CObject

{

public:

CEdit city1;

CEdit city2;

CLabel label1;

CLabel label2;

CFindButton find;

CQuitButton quit;

CString caption;

CForm();

~CForm(){};

void draw();

void draw_elem();

void press_key(unsigned char key);

};

class CApplication

{

char Quit;

public:

CForm mainform;

CApplication();

~CApplication();

void execute();

void terminate();

};

#endif

Методы классов:

  • CString (CString.cpp)

#include "cstring.h"

CString::CString()

{

len = 0;

data = new char;

data[0] = 0;

}

CString::CString(char* str)

{

len = 0;

while (str[len]) len++;

data = new char[len+1];

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

data[i] = str[i];

data[len] = 0;

}

CString::CString(CString& str)

{

len = str.len;

data = new char[len+1];

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

data[i] = str.data[i];

}

CString::~CString()

{

if (data!=NULL) delete [] data;

}

CString& CString::operator = (CString& str)

{

if (&str==this) return *this;

if (data!=NULL) delete [] data;

len = str.len;

data = new char[len+1];

for (int i =0; i<=len; ++i) data[i] = str.data[i];

return *this;

}

CString& CString::operator = (char* str)

{

if (data!=NULL) delete [] data;

len = 0;

while (str[len]) ++len;

data = new char[len+1];

for (int i=0; i<=len; ++i) data[i] = str[i];

return *this;

}

CString CString::operator + (CString& str)

{

CString string;

string.len = len+str.len;

string.data = new char[string.len+1];

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

string.data[i] = data[i];

for (i=len; i<=string.len; ++i)

string.data[i] = str.data[i-len];

return string;

}

CString CString::operator + (char* str)

{

CString string;

int str_len = 0;

while (str[str_len]) ++str_len;

string.len = len+str_len;

string.data = new char[string.len+1];

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

string.data[i] = data[i];

for (i=len; i<=string.len; ++i)

string.data[i] = str[i-len];

return string;}

char CString::operator == (CString& str)

{

unsigned int min_len = len<str.len?len:str.len;

for (int i=0; data[i]==str.data[i] && i<min_len; ++i);

if (i==min_len && len==str.len) return 1; else return 0;

}

char CString::operator > (CString& str)

{

unsigned int min_len = len<str.len?len:str.len;

for (int i=0; data[i]==str.data[i] && i<min_len; ++i);

if (i==min_len)

{

if (len==str.len || min_len!=str.len) return 0;

return 1;

}

if (data[i]>str.data[i]) return 1;

return 0;

}

char CString::operator < (CString& str)

{

unsigned int min_len = len<str.len?len:str.len;

for (int i=0; data[i]==str.data[i] && i<min_len; ++i);

if (i==min_len)

{

if (len==str.len || min_len!=len) return 0;

return 1;

}

if (data[i]<str.data[i]) return 1;

return 0;

}

unsigned int CString::length()

{

return len;

}

char* CString::get_data()

{

return data;

}

void CString::del_sym(unsigned int pos)

{

if (pos<=len)

{

CString string;

int i;

string.data = new char [len];

string.len = len-1;

for (i=0; i<pos-1; ++i)

string.data[i] = data[i];

for (; i<len; ++i) string.data[i] = data[i+1];

*this = string;

}

}

  • CTime (CTime.cpp)

#include "ctime.h"

CTime::CTime()

{

hh = 0;

mm = 0;