PROGRAM HELP!!!!!!!
-
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor. Here is what I have so for the my header (.h) file... class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor }; And here is what I have in my .cpp file.... ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM! THANKS GUYS ..YOU GUYS SAVE MY LIFE ;) Data Members: 1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros. 2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board. Methods 1.)a default constructor to initialize both arrays – filling them both completely with zeros
-
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor. Here is what I have so for the my header (.h) file... class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor }; And here is what I have in my .cpp file.... ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM! THANKS GUYS ..YOU GUYS SAVE MY LIFE ;) Data Members: 1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros. 2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board. Methods 1.)a default constructor to initialize both arrays – filling them both completely with zeros
(duh to myself )
board[12][13] = 0; numChips[7] = 0;
Think harder, how are arrays indexed in C++ ( or C ). you're getting there ... hang tough ...
Maximilien Lincourt Your Head A Splode - Strong Bad
-
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor. Here is what I have so for the my header (.h) file... class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor }; And here is what I have in my .cpp file.... ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM! THANKS GUYS ..YOU GUYS SAVE MY LIFE ;) Data Members: 1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros. 2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board. Methods 1.)a default constructor to initialize both arrays – filling them both completely with zeros
ISUstudent wrote: board[12][13] = 0; numChips[7] = 0; Remove this two lines: you are writing a zero outside the arrays (numChips[6] is the last cell of your array because it is zero indexed). Otherwise it is correct.
-
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor. Here is what I have so for the my header (.h) file... class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor }; And here is what I have in my .cpp file.... ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM! THANKS GUYS ..YOU GUYS SAVE MY LIFE ;) Data Members: 1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros. 2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board. Methods 1.)a default constructor to initialize both arrays – filling them both completely with zeros
And, does it work? Looks good so far. You may also want to use memset. memset( board, 0, sizeof( board ) ); Hardy.
-
(duh to myself )
board[12][13] = 0; numChips[7] = 0;
Think harder, how are arrays indexed in C++ ( or C ). you're getting there ... hang tough ...
Maximilien Lincourt Your Head A Splode - Strong Bad
Maximilien wrote: (duh to myself ) :laugh: It's been a hard day ?? ;P
-
Ok...can anyone help me with this problem. I"m havinng troulbe to figure out how to use the data members and fill them both completely with zeros while initiallize them in the default constructor. Here is what I have so for the my header (.h) file... class ConnectFour { private: //date members int board[12][13]; int numChips[7]; public: ConnectFour(); //default constructor }; And here is what I have in my .cpp file.... ConnectFour::ConnectFour() { board[12][13] = 0; numChips[7] = 0; for(int i=0; i < 12; i++) { for(int j=0; j<13; j++) { board[i][j] = 0; } } for(int i=0; i<7; i++) { numChips[i]= 0; } } IS THIS RIGHT?....BELOW IS HOW IT IS SUPPOSED TO BE DONE ON THE DIRECTIONS FOR THIS PROGRAM! THANKS GUYS ..YOU GUYS SAVE MY LIFE ;) Data Members: 1.)a 2-dimensional array to hold the board – To make it easier to check for wins you chould use a board that has 12 rows and 13 columns. Only rows 3 – 8 and columns 3 – 9 will actually hold the board (which has 6 rows and 7 columns). The remaining cells will always contain zeros. 2.)a single-dimensional array of 7 ints to hold the number of chips dropped into each column of the board. Methods 1.)a default constructor to initialize both arrays – filling them both completely with zeros
Instead of the
for
loops, you could simply callmemset()
. Other than that, what you have so far is okay.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
-
Instead of the
for
loops, you could simply callmemset()
. Other than that, what you have so far is okay.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
sweet. i just didn't know if i could have for loops and such in my defalut constructor