13.01.2015 Views

Объектно-ориентированное программирование на С++ - eDrive

Объектно-ориентированное программирование на С++ - eDrive

Объектно-ориентированное программирование на С++ - eDrive

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

double scholarship;<br />

};<br />

Student example;<br />

example.firstName = MyForm–>Edit1–>Text ;<br />

example.birthYear = StrToInt (MyForm–>Edit2–>Text);<br />

example.scholarship = StrToFloat (MyForm–>Edit3–>Text) ;<br />

MyForm–>StringGrid1–>Cells[1][1] = example.firstName;<br />

MyForm–>StringGrid1–>Cells[2][1] = example.birthYear;<br />

MyForm–>StringGrid1–>Cells[3][1] = example.scholarship;<br />

}<br />

void Structures2 () {<br />

TStringGrid *sg = StringGrid1;<br />

int rows = sg–>RowCount;<br />

struct s { int n; AnsiString nm; };<br />

s group;<br />

try {<br />

for (int i=0; iCells[0][i]);<br />

group.nm = sg–>Cells[1][i];<br />

ShowMessage (IntToStr (group.n) + ' ' + group.nm);<br />

}<br />

} catch (...) { ShowMessage ("Заполнить ячейки"); }<br />

}<br />

50<br />

Следующий пример посвящен пузырьковой сортировке строк String-<br />

Grid с использованием структуры:<br />

void Structures3 () {<br />

TStringGrid *sg = StringGrid1;<br />

int rows = sg–>RowCount;<br />

struct s { AnsiString name; int year; };<br />

s temp;<br />

for (int i=1; ii; – –j)<br />

if (sg–>Cells[0][j] < sg–>Cells[0][j–1]) {<br />

temp.name = sg–>Cells[0][j];<br />

sg–>Cells[0][j] = sg–>Cells[0][j–1];<br />

sg–>Cells[0][j–1] = temp.name;<br />

temp.year = StrToInt (sg–>Cells[1][j]);<br />

sg–>Cells[1][j] = sg–>Cells[1][j–1];<br />

sg–>Cells[1][j–1] = temp.year;<br />

}<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!