Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. PROGRAM HELP!!!!!!!

PROGRAM HELP!!!!!!!

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++data-structurestutorialquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    ISUstudent
    wrote on last edited by
    #1

    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

    M H C D 4 Replies Last reply
    0
    • I ISUstudent

      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

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      (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

      C 1 Reply Last reply
      0
      • I ISUstudent

        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

        H Offline
        H Offline
        Hardy_Smith
        wrote on last edited by
        #3

        And, does it work? Looks good so far. You may also want to use memset. memset( board, 0, sizeof( board ) ); Hardy.

        1 Reply Last reply
        0
        • I ISUstudent

          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

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • M Maximilien

            (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

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            Maximilien wrote: (duh to myself ) :laugh: It's been a hard day ?? ;P

            1 Reply Last reply
            0
            • I ISUstudent

              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

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Instead of the for loops, you could simply call memset(). 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

              I 1 Reply Last reply
              0
              • D David Crow

                Instead of the for loops, you could simply call memset(). 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

                I Offline
                I Offline
                ISUstudent
                wrote on last edited by
                #7

                sweet. i just didn't know if i could have for loops and such in my defalut constructor

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups