4.ТП (Готовое ДЗ неизвестного варианта (5))
Описание файла
Файл "4.ТП" внутри архива находится в папке "Готовое ДЗ неизвестного варианта (5)". Документ из архива "Готовое ДЗ неизвестного варианта (5)", который расположен в категории "". Всё это находится в предмете "объектно-ориентированное программирование (ооп)" из 3 семестр, которые можно найти в файловом архиве МГТУ им. Н.Э.Баумана. Не смотря на прямую связь этого архива с МГТУ им. Н.Э.Баумана, его также можно найти и в других разделах. Архив можно найти в разделе "курсовые/домашние работы", в предмете "объектно-ориентированное программирование (ооп)" в общих файлах.
Онлайн просмотр документа "4.ТП"
Текст из документа "4.ТП"
Московский государственный технический университет им. Н.Э.Баумана
_________________________________________________________________
Утверждаю: | |
Большаков С.А. | "__"_____________2008 г. |
Домашнее задание по дисциплине ПППО
“< Классы таблиц >”
<Текст программы>
(вид документа)
A4
(вид носителя)
16
(количество листов)
ИСПОЛНИТЕЛЬ: | |
студент группы ИУ5-61 | Забаева А. Л. |
Большаков С.А. | "__"_____________2008 г. |
Москва - 2008
СОДЕРЖАНИЕ
Файл “Main.cpp” 3
Файл “Table.h” 5
Файл “About.h” 8
Файл “Abstr.h” 9
Файл “Cell.h” 10
Файл “Column.h” 12
Файл “List.h” 13
Файл “Node.h” 16
Файл “Main.cpp”
#include "iostream.h"
#include "stdio.h"
#include "conio.h"
#include "list.h"
#include "table.h"
#include "about.h"
void main()
{
about();
Table* table = new Table();//создание таблицы
char* value = new char[CELL_LENGTH];
cout << "Enter two Columns Header. It was add to Table." << endl;
cout << "First column Header ( < " << CELL_LENGTH <<" symbols): ";
cin >> value;
table->AddCol(value); //добавление столбца
cout << "Second column Header ( < " << CELL_LENGTH <<" symbols): " << endl;
cin >> value;
table->AddCol(value);
cout << "\nAdd to Table empty values: " << endl;
List* list = new List(); //создание нового списка-строки
table->AddRow(list); //добавление строки
table->PrintTable(); //распечатка таблицы
int i;
int colCount = table->GetColCount();
int rowCount = table->GetRowCount();
cout << "\nEnter value to add new Row int Table ( < " << CELL_LENGTH <<" symbols): " << endl;
cin >> value;
for (i = 0; i < colCount; i++)
{
Cell* cell = new Cell(rowCount, i, value);
Node* node = new Node(cell);
list->Add(node);
}
table->AddRow(list);
table->PrintTable();
cout << "\nEnter value to add new Row int Table ( < " << CELL_LENGTH <<" symbols): " << endl;
cin >> value;
Node* node = list->Head;
for (i = 0; i < colCount; i++)
{
(node->A)->Value = value;
node = node->Next;
}
table->AddRow(list);
table->PrintTable();
cout << "\nEnter Header of new Column ( < " << CELL_LENGTH <<" symbols): " << endl;
cin >> value;
table->AddCol(value);
table->PrintTable();
//getch();
list = (List*)table->Columns->Tail->A;
Cell* cell = (Cell*)list->Head->A;
cout << "\nEnter Header of new Column ( < " << CELL_LENGTH <<" symbols): " << endl;
cin >> value;
(Cell*)list->Head->A = *cell + value; //добавление текста в ячейку
table->PrintTable();
getch();
}
Файл “Table.h”
#include "iostream.h"
#include "column.h"
class Table
{
private:
int RowCount;
int ColCount;
public:
List* Columns;
Table();
Table(char* name);
Column* AddCol(char* title);
void AddRow(List* Values);
void PrintTitles();
void PrintTable();
int GetColCount();
int GetRowCount();
~Table();
};
Table::Table()
{
RowCount = 0;
ColCount = 0;
Columns = new List();
};
Table::Table(char* name)
{
RowCount = 0;
ColCount = 0;
Columns = new List(name);
}
int Table::GetColCount()
{
return ColCount;
}
int Table::GetRowCount()
{
return RowCount;
}
Column* Table::AddCol(char* title)
{
ColCount++;
int c = ColCount - 1;
int r;
Column* col = new Column(title, c);
for (r = 0; r < RowCount; r++)
{
Cell* cell = new Cell(r, c, "Cell");
Node* node = new Node(cell);
*col + node;
}
Node* node = new Node(col);
Columns->Add(node);
return col;
}
void Table::AddRow(List* Values)
{
RowCount++;
int r = RowCount - 1;
int c;
char* value;
Node* col = Columns->Head;
Node* addValue = Values->Head;
while (col != NULL)
{
if (addValue != NULL)
{
r = ((Cell*)addValue->A)->Row;
c = ((Cell*)addValue->A)->Col;
value = addValue->A->Value;
}
else
{
c = ((Column*)col->A)->Number;
value = "Cell";
}
Cell* cell = new Cell(r, c, value);
Node* node = new Node(cell);
((List*)col->A)->Add(node);
col = col->Next;
addValue = addValue->Next;
}
}
void Table::PrintTitles()
{
Node* col = Columns->Head;
while (col != NULL)
{
cout << col->A->Value << ((Column*)col->A)->Number << endl;
col = col->Next;
}
cout << endl;
}
void Table::PrintTable()
{
Node* col = Columns->Head;
while (col != NULL)
{
cout.width(CELL_LENGTH);
cout.fill(' ');
cout << col->A->Value << ((Column*)(col->A))->Number;
Node* cell = ((List*)col->A)->Head;
while (cell != NULL)
{
cout.width(CELL_LENGTH);
cout.fill(' ');
((Cell*)cell->A)->PrintValue();
cell = cell->Next;
}
col = col->Next;
cout << endl;
}
cout << "\n";
}
Table::~Table()
{
delete(Columns);
}
Файл “About.h”
#include "iostream.h"
void about()
{
cout << "Class system Table" << endl;
cout << "Zabaeva Anna var.8 IU5-61 2008\n" << endl;
}
Файл “Abstr.h”
#include "iostream.h"
const CELL_LENGTH = 10;
class Abstr
{
public:
char* Value;
Abstr()
{
Value = new char[CELL_LENGTH];
};
Abstr(char* value)
{
Value = new char[CELL_LENGTH];
strcpy(Value, value);
};
virtual Print () {};
~Abstr()
{
delete(Value);
};
};
Файл “Cell.h”
#include "iostream.h"
template <class Any>
void print(Any value)
{
cout << value;
}
class Cell : public Abstr
{
public:
int Row;
int Col;
Cell(int row, int col, char* value) : Abstr(value)
{
Row = row;
Col = col;
}
virtual Print()
{
cout <<"\nCell: r = " << Row << "; Col = " << Col << " ; Value = " << Value << endl;
}
Cell* operator+(char* part)
{
char* s = new char[CELL_LENGTH];
strcpy(s, Value);
strcat(s, part);
Cell* cell = new Cell(Row, Col, s);
return cell;
}
void PrintCol()
{
print(Col);
}
void PrintRow()
{
print(Row);
}
void PrintValue()
{
print(Value);
}
};
Файл “Column.h”
#include "iostream.h"
#include "cell.h"
class Column : public List
{
public:
int Number;
Column(int number) : List()
{
Number = number;
}
Column(char* title, int number) : List(title)
{
Number = number;
}
~Column() {};
virtual Print()
{
cout << "ColumnName: " << Value;
}
};
Файл “List.h”
#include "iostream.h"
#include "string.h"
#include "node.h"
class List : public Abstr
{
public:
Node* Current;
Node* Head;
Node* Tail;
int Count;
List() : Abstr()
{
Current = NULL;
Head = NULL;
Tail = NULL;
Count = 0;
};
List(char* value) : Abstr(value)
{
Current = NULL;
Head = NULL;
Tail = NULL;
Count = 0;
};
void Add(Node* node);
operator+(Node* node);
virtual Print();
void Delete(Node* node);
operator-(Node* node);
~List();
};
void List::Delete(Node* node)
{
if (node->Next != NULL)
{
if (node->Prev != NULL)
{
node->Prev->Next = node->Next;
node->Next->Prev = node->Prev;
}
else
{
node->Next->Prev = NULL;
Head = node->Next;
}
}
else
{
if (node->Prev != NULL)
{
node->Prev->Next = NULL;
Tail = node->Prev;
}
}
if (node != NULL)
{
delete(node);
node = NULL;
}
};
List::operator-(Node* node)
{
Delete(node);
}
List::Print()
{
if (Head != NULL)
{
Node* node;
node = Head;
while (node != NULL)
{
cout << node->A->Value << endl;
node = node->Next;
}
}
};
void List::Add(Node* node)
{
//cout << "Add:" << node; return;
if (node == NULL)
node = new Node();
if (Current != NULL)
{
if (Current->Next == NULL)
{
Current->Next = node;
node->Prev = Current;
Current = node;
Tail = node;
}
else
{
Node* b;
b = Current->Next;
Current->Next = node;
node->Prev = Current;
node->Next = b;
b->Prev = node;
Current = node;
}
}
else
{
Current = node;
Head = node;
node->Prev = NULL;
}
Count++;
}
List::operator+(Node* node)
{
Add(node);
}
List::~List()
{
delete(Current);
delete(Head);
delete(Tail);
}
Файл “Node.h”
#include "iostream.h"
#include "abstr.h"
class Node
{
public:
Node* Prev;
Node* Next;
Abstr* A;
Node()
{
Prev = NULL;
Next = NULL;
}
Node(Abstr* a)
{
Prev = NULL;
Next = NULL;
if (a == NULL)
a = new Abstr();
A = a;
}
~Node()
{
delete(Prev);
delete(Next);
delete(A);
}
};