新人求助

  大四在写论文  求一个X3D-Edit编辑器的下载链接
阅读更多

新人求助~~~

09-22

大家好!刚学C++不久,下面是我刚做的作业,但是总感觉跟要求的有点不一样!! rn求哪位大侠指点一二!! 谢谢!!rnrn这个是我的作业rnrnhttp://teaching.ics.mq.edu.au/units/comp125/assignments/ass2.htmlrnrnrnrn下面是我自己做的:rnrn// grid.cpprnrn#include rn#include rn#include rn#include rn#include "grid.h"rnrngrid::grid()rnrn rows = 0;rn cols = 0;rn maxBlob = 0;rnrnrnvoid grid::readGrid(string filename)rnrn ifstream inFile;rn inFile.open(filename.c_str());rn rn if (!inFile) rn rn cerr << "File does not exist" << endl; rn rn else rn rn inFile >> rows >> cols;rn rn char a;rn v.resize(rows, vector < bool > (cols,false));rn rn for (int i = 0; i < rows; i++) rn for (int j = 0; j < cols; j++)rn rn if (inFile >> a)rn rn if (a == '*')rn v[i][j] = true;rn else rn v[i][j] = false; rn rn rn rnrnrnvoid grid::printGrid()rnrn for (char r = 0; r < rows; r++)rn rn for (char c = 0; c < cols; c++)rn rn if (v[r][c])rn cout << '*';rn else rn cout << '.'; rn rn cout << endl;rn rnrnrnint grid::getMaxBlob()rn rn int i, j, temp;rn int MaxBlob ;rn for (int i = 0; i < rows && (!isEmpty()); i++)rn rn for (int j = 0; j < cols && (!isEmpty()); j++)rn rn temp = getBlobSize(i,j);rn if (temp > MaxBlob)rn MaxBlob = temp;rn rn rn return MaxBlob; rnrnrnbool grid::isEmpty()rnrn return v.empty();rnrnrnvoid grid::findAllBlobs()rnrn int r, c, tmp;rn for (r = 0; r < rows && (!isEmpty()); r++)rn for (c = 0; c < cols && (!isEmpty()); c++)rn rn tmp = getBlobSize(r,c); rn if (tmp > 1)rn cout << tmp << '\t'; rn rn cout << endl;rnrnrnint grid::getBlobSize(int curRow, int curCol)rnrn if ((curRow >= rows) || (curCol >= cols) || (curRow < 0) || (curCol < 0)) rn return 0;rn else if (!v[curRow][curCol]) rn return 0;rn else rn rn v[curRow][curCol] = false;rn return 1 + getBlobSize(curRow-1, curCol-1)rn + getBlobSize(curRow-1, curCol)rn + getBlobSize(curRow-1, curCol+1)rn + getBlobSize(curRow, curCol+1)rn + getBlobSize(curRow, curCol-1)rn + getBlobSize(curRow+1, curCol-1)rn + getBlobSize(curRow+1, curCol)rn + getBlobSize(curRow+1, curCol+1);rn rnrnrnrn// main functionrn#include rn#include rnrn#include "grid.h"rnrnusing namespace std;rnrnint main(int argc, char *argv[])rnrn string filename;rn grid x;rn cout << "Enter filename" << endl;rn cin >> filename;rn rn x.readGrid(filename);rn x.printGrid(); rn rn x.findAllBlobs(); rn cout << "The maximum of blob size is " << x.getMaxBlob() << endl;rn rn rn system ("PAUSE");rn return 0;rnrn

没有更多推荐了,返回首页