?? table.c
字號:
#include "table.h"void Table::setValue(int r, int c, Description d){ ERROR3((void*)isInRange(r,c), "Table::setValue: r=%d, c=%d out of table range\n", r, c); head[r][c] = d;}Description **Table::alloc(){ Description **Ptr; Ptr = new Description*[Row()]; for(int r = 0; r < Row(); r++) Ptr[r] = new Description[Col()]; return Ptr;}void Table::dealloc(Description **head){ for(int r = 0; r < Row(); r++) delete head[r]; delete head;}void Table::read(Source &src){ src.init(); for(int r = 0; r < Row(); r++) for(int c = 0; c < Col(); c++) head[r][c] = src.readDescription();// removeSerialColumn();}void Table::removeSerialColumn(){ int isSerial = 1; for(int c = 0, r = 1; r < Row(); r++) { isSerial &= head[r][c] - head[r-1][c] == 1; } if(isSerial&&Row()!=1) { col --; // decrease the number of column for(int r = 0; r < Row(); r++) for(int c = 0; c < Col(); c++) head[r][c] = head[r][c+1]; // shift one column }}void Table::readForExtension(Source &src)// This is to read the testing data from the file, such that the// last column will be preserved for the class results{ src.init(); for(int r = 0; r < row; r++) for(int c = 0; c < col-1; c++) head[r][c] = src.readDescription(); removeSerialColumn();}Table::Table(){ head = NULL; row = 0; col = 0;} Table::Table(Source &src, int isExtended){ row = src.numOfInstances(); if(isExtended) col = src.numOfDescriptions()+1; // include the class column // also add one extra column for future classfication else col = src.numOfDescriptions(); // include the class column head = alloc(); if(isExtended) this->readForExtension(src); else this->read(src);#ifdef DBG cout << "Table::row = " << row << ", col = "<<col << endl;#endif} Table::Table(Source &src){ row = src.numOfInstances(); col = src.numOfDescriptions(); // include the class column#ifdef DBG2 cout << "Table::row = " << row << ", col = "<<col << endl;#endif head = alloc(); this->read(src);#ifdef DBG2 cout << "Table::row = " << row << ", col = "<<col << endl;#endif} Table::~Table(){ dealloc(head);}int Table::isEmpty(){ return row==0&&col==0;}Description* Table::getRow(int r){ return head[r];} int Table::isInRange(int r, int c){ return (r>=0&&r<row) && (c>=0&&c<col);}Description Table::value(int r, int c){// ERROR3((void*)isInRange(r,c),// "Table::value: r=%d, c=%d out of table range\n", r, c); return head[r][c];}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -