I'll post a pdf of the assignment. I have much done, it even tells how many X's there are but The recursion is giving me trouble, I must study for a calculus test not this! I've made 100 everytime so it's not like I just want someone to do my work.
also post any code you have so far
#include <iostream> #include <iomanip> #include <fstream> using namespace std; const int MAXROW=22; const int MAXCOL=72; const int MAXLINE=80; void ClearArray(char IA[][MAXCOL]); void DestroyBlob(char InputArray[MAXROW][MAXCOL],int row,int col); int main (void) { ifstream myfile; char InputArray [MAXROW][MAXCOL]; char InputLine[MAXLINE]; ClearArray(InputArray); myfile.open("blob.txt"); for (int row=1;row<MAXROW-1;row++)//we use -1 bcz it starts with 0 and we added padding { //getline actually doesn't look at special chars that we don't see myfile.getline(InputLine, MAXLINE); cout<<InputLine<<endl; for(int col=1;col<MAXCOL-1;col++) InputArray[row][col]=InputLine[col-1]; } myfile.close(); int number=0; for (int row=1;row<MAXROW-1;row++) { for(int col=1;col<MAXCOL-1;col++) if(InputArray[row][col] != ' ') { number++; DestroyBlob(InputArray,row,col); } } cout<<"done"<<number<<endl; return 0; } void ClearArray(char IA[][MAXCOL]) { for (int row=0; row<MAXROW;row++) for (int col=0; col<MAXCOL;col++) IA[row][col]=' '; } void DestroyBlob(char InputArray[MAXROW][MAXCOL],int row, int col) { InputArray[row][col]=' '; cout<<"Found one!"<<row<<","<<col<<endl; return; }
Some of that is to let me know that it is infact checking for the Xs
can you post blob.txt as well
yes
any help would be ++++++++++++ greatly appreciated you guys have no idea I'm in a tight right now
welp i hate sorting...good luck
it's not much sorting :s
I grabbed most of this code from a Boggle assignment. I didn't test it. void DestroyBlob(char InputArray[MAXROW][MAXCOL],int row, int col) { if( InputArray[row][col] != ' ' ) { // iterate through the row to the left, this row and the row to the righ t for( int checkRow = -1; checkRow <= 1; checkRow++ ) { // iterate through the column above, this column and the column belo w for( int checkCol = -1; checkCol <= 1; checkCol++ ) { // check that we're not checking the current letter if( checkRow != 0 || checkCol != 0 ) { InputArray[row + checkRow][col + checkCol] = ' '; DestroyBlob(char InputArray[MAXROW][MAXCOL],int row + checkRow, int col + checkCol ); } } } } } It would be much better if InputArray was passed by reference.
im not good with pointers any help with adjusting to that? I just got done studying for my calc exam
off topic question: are there any java based questions?
sometimes someone posts about java, you can also join java programming group but it's kinda dead, however you could revive it :D
I love C++ and any objective C but i'm sort of into Java because of my job. I will liberate java!
Pointers and references aren't the same in C++. Passing by reference just passes a reference to the variable that allows a function to modify the argument. The only change that would need to be done is to the declarations of DestroyBlob: void DestroyBlob(char & InputArray[MAXROW][MAXCOL],int row, int col)
I got it ill post my code // ***************************************************************** // * Program Name: blobfinder.cpp * // * Class: COP3014 * // * Description: Reads in a text file, and counts the number of * // * blobs,then displays that number. * // * * // * Date: 12/1/2011 * // * Author: Cody L. Baldwin * // ***************************************************************** #include <iostream> #include <iomanip> #include <fstream> using namespace std; //============================== //Constants for my rows/columns //============================== const int MAXROW=22; const int MAXCOL=72; const int MAXLINE=80; //========================================================== //Set all spaces in a passed array to blanks to initialized //========================================================== void ClearArray(char IA[][MAXCOL]); //============================================================= //Destroys passed in coordinance and checks for those around it //============================================================= void DestroyBlob(char InputArray[][MAXCOL],int row,int col); int main (void) { //=================================== //declare files and arrays being used //=================================== ifstream myfile; char InputArray [MAXROW][MAXCOL]; char InputLine[MAXLINE]; ClearArray(InputArray); myfile.open("blob.txt"); //=================================================== //we use -1 bcz it starts with 0 and we added padding // Kudos to Dr. Gaitros //=================================================== for (int row=1;row<MAXROW-1;row++) { //====================================== //Input the text file one line at a time //====================================== myfile.getline(InputLine, MAXLINE); for(int col=1;col<MAXCOL-1;col++) InputArray[row][col]=InputLine[col-1]; } myfile.close(); //=================================================== //number will be used to keep track of how many blobs //==================================================== int number=0; for (int row=1;row<MAXROW-1;row++) { for(int col=1;col<MAXCOL-1;col++) //================================================ //if it finds a non-blank space call Destroyblob() //================================================ if(InputArray[row][col] != ' ') { number++; DestroyBlob(InputArray,row,col); } } cout<<"Number of blobs: "<<number<<endl; return 0; } //============================================ //2 for loops initialize the array to blanks //============================================ void ClearArray(char IA[][MAXCOL]) { for (int row=0; row<MAXROW;row++) for (int col=0; col<MAXCOL;col++) IA[row][col]=' '; } //============================================================== //8 conditional 'if' statements that test surrounding spots //if one exists clear it and call itself again //============================================================== void DestroyBlob(char InputArray[MAXROW][MAXCOL],int row, int col) { InputArray[row][col]=' '; if (InputArray[row-1][col+1] !=' ') { DestroyBlob(InputArray,row-1,col+1); } if (InputArray[row][col+1] !=' ') { DestroyBlob(InputArray,row,col+1); } if (InputArray[row+1][col+1] !=' ') { DestroyBlob(InputArray,row+1,col+1); } if (InputArray[row+1][col] !=' ') { DestroyBlob(InputArray,row+1,col); } if (InputArray[row+1][col-1] !=' ') { DestroyBlob(InputArray,row+1,col-1); } if (InputArray[row][col-1] !=' ') { DestroyBlob(InputArray,row,col-1); } if (InputArray[row-1][col-1] !=' ') { DestroyBlob(InputArray,row-1,col-1); } if (InputArray[row-1][col] !=' ') { DestroyBlob(InputArray,row-1,col); } return; }
Join our real-time social learning platform and learn together with your friends!