Ok, new to C++ and my first assignment is to covert C code to C++, I'm getting pretty frustrated and have been looking at the code for the last two days not truly understanding how to do it. The teacher gave us a program in C which I have an ok understanding of from last quarter and wants us to change it into C++ code. The entire code in C is in one main and he wants us to change it into a class CMatrix and have 4 member functions in it. There is also the issue of pointers and pointer array and passing them that has gotten me so confused. Please help!

This is the initial C Code

/* MAGIC SQUARE - An NxN matrix containing values from 1 to N*N that are  */
/* ordered so that the sum of the rows, columns, and the major diagonals  */
/* are all equal.  There is a particular algorithm for odd integers, and  */
/* this program constructs that matrix, up to 13 rows and columns.  This   */
/* program also adds the sums of the row, columns, and major diagonals.   */

#include <stdio.h>

main()
{
   int input;                               /* User defined integer       */
   int loc[14][14];                         /* Array holding all          */
                                            /*  input*input values.       */
   int row;                                 /* Determines row of matrix   */
   int col;                                 /* Determines col of matrix   */
   int value;                               /* Integer between 1 and      */
                                            /*  input*input               */
   int otherdiag;                           /* Total of one matrix diagonal*/

/*                                                                        */
/* Print introduction of what this program is all about.                  */
/*                                                                        */
   printf("\nMagic Squares: This program produces an NxN matrix where\n");
   printf("N is some positive odd integer.  The matrix contains the \n");
   printf("values 1 to N*N.  The sum of each row, each column, and \n");
   printf("the two main diagonals are all equal.  Not only does this \n");
   printf("program produces the matrix, it also computes the totals for\n");
   printf("each row, column, and two main diagonals.\n");

   printf("\nBecause of display constraints, this program can work with\n");
   printf("values up to 13 only.\n\n");

    printf("Enter a positive, odd integer (-1 to exit program):\n");
   while (scanf("%d",&input) == 1)
   {

/*                                                                        */
/*    If input = -1, then exit program.                                   */
/*                                                                        */
      if (input == -1)
	 break;
/*                                                                        */
/*    Validity check for input: Must be a positive odd integer < 13.      */
/*                                                                        */
      if (input <= 0)
      {
         printf("Sorry, but the integer has to be positive.\n");
	 printf("\nEnter a positive, odd integer (-1 to exit program):\n");
  	 continue;
      }
      if (input > 13)
      {
	 printf("Sorry, but the integer has to be less than 15.\n");
	 printf("\nEnter a positive, odd integer (-1 to exit program):\n");
	 continue;
      }
      if (input%2 == 0)
      {
	 printf("Sorry, but the integer has to be odd.\n");
	 printf("\nEnter a positive, odd integer (-1 to exit program):\n");
	 continue;
      }
/*                                                                        */
/*    Initialize matrix, row, col, and otherdiag                          */
/*                                                                        */
      for (row = 0; row <= input; row++)    /* Initialize matrix with     */
         for (col = 0; col <= input; col++) /*  all zeroes.               */
            loc[row][col] = 0;              /* Values will reside within  */
                                            /*  rows 1 to input*input and */
                                            /*  columns 1 to input*input. */
                                            /* Row totals will reside in  */
                                            /*  loc[row][0], where row is */
                                            /*  the row number, while the */
                                            /*  column totals will reside */
                                            /*  in loc[0][col], where col */
                                            /*  is the column number.     */  
      row = 1;                              /* First value gets to sit on */
      col = input/2 + 1;                    /*  1st row, middle of matrix.*/
      otherdiag = 0;

 /*                                                                        */
/*    Loop for every value up to input*input, and position value in matrix*/
/*                                                                        */
      for (value = 1; value <= input*input; value++)
      {                                     /* Loop for all values.       */
         if (loc[row][col] > 0)             /* If some value already      */
         {                                  /*  present, then             */
            row += 2;                       /*  move down 1 row of prev.  */
            if (row > input)                /*  If exceeds side, then     */    
               row -= input;                /*   go to other side.        */

            col--;                          /*  move left 1 column.       */
            if (col < 1)                    /*  If exceeds side, then     */
               col = input;                 /*   go to other side.        */
         }

         loc[row][col] = value;             /* Assign value to location.  */

/*                                                                        */
/*       Add to totals                                                    */ 
/*                                                                        */
         loc[0][col] += value;              /* Add to its column total.   */
         loc[row][0] += value;              /* Add to its row total.      */
         if (row == col)                    /* Add to diagonal total if   */
            loc[0][0] += value;             /*  it falls on the diagonal. */

         if (row+col == input+1)            /* Add to other diagonal if   */
            otherdiag += value;             /*  it falls on the line.     */

/*                                                                        */
/*       Determine where new row and col are                              */
/*                                                                        */
         row--;
         if (row < 1)                       /* If row exceeds side then   */
            row = input;                    /*  goto other side.          */
         col++;
         if (col > input)                   /* If col exceeds side then   */
            col = 1;                        /*  goto other side.          */
      }                                     /* End of getting all values. */

/*                                                                        */
/*    Print out the matrix with its totals                                */
/*                                                                        */
      printf("\nThe number you selected was %d",input);
      printf(", and the matrix is:\n\n");
      for (row = 1; row <=input; row++)     /* Loop: print a row at a time*/
      {
         printf("     ");                   /* Create column for diag.total*/
         for (col = 1; col <=input; col++)
            printf("%5d",loc[row][col]);    /* Print values found in a row*/
         printf(" = %5d\n",loc[row][0]);    /* Print total of row.        */
      }

 /*                                                                        */
/*    Print out the totals for each column, starting with diagonal total. */
/*                                                                        */
      for (col = 0; col <=input; col++)     /* Print line separating the  */
         printf("-----");                   /*  value matrix and col totals*/
      printf("\n%5d",otherdiag);            /* Print out the diagonal total*/
      for (col = 1; col <=input; col++)
         printf("%5d",loc[0][col]);         /* Print out the column totals*/
      printf("   %5d\n",loc[0][0]);         /* Print out the other diagonal*/
                                            /*  total                     */
      printf("\nEnter a positive, odd integer (-1 to exit program):\n");

   }                                        /* End of while input>-1 loop */
   printf("\nBye bye!\n");
}

And this is what I have done so far. Alot of stuff i've comented out are stuff I've tried but doesn't seem to work. So far I just called the Init (to initialize the matrix) directly from the loop but I understand that i'm suppose to make the input into a pointer and get it from the main which i've tried doing alot and I dont kown how to get it to work

#include <iostream>
#include <limits>
#include <cctype>
using namespace std;

class CMatrix
{
    public:
           void GetData();
           void Init(int input);
           void Calculate();
           void Display();
           
    private:
            int* pInput;
            int input;
//            int** pnLoc;
            int** loc;
            int value;
            int otherdiag;
};

void CMatrix::GetData()
{
     int input = 0;

     for(;;) //infinite for loop
     {
            cout << "\nEnter a positive,";
            cout << " odd integer (-1 to exit program):\n";
            cin >> input;
//            pInput = &input;
            
//            cout << "Pointer " << *pInput << "\n" << input;
            
            //if numbers entered, enter the block
            if (cin.good()){
               if (input == -1){
                  break;
               }
               else if (input > 15){
                    cout << "Sorry, but the integer has";
                    cout << " to be less than 15.\n";
               }
               else if (input%2 == 0){
                    cout << "Sorry, but the integer has to be odd.\n";
               }   
            Init(input);
            }//end if cin.good()
            else if (!isdigit(input))
                 cout <<"Only digits are allowed!\n";
                 
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(),'\n');
     }//end for loop
}

void CMatrix::Init(int input)
{
     int row, col;

//     cout << "\n" << input;
     
     int **loc = 0;
     
     for (row = 0; row <= input; row++)
         loc[row] = new int[input];
     
     for (row = 0; row <= input; row++)
         for (col = 0; col <= input; col++) 
             *(loc[row] + col) = col;
                                            
     row = 1;                              
     col = input/2 + 1;                    
     otherdiag = 0;
}

void CMatrix::Calculate()
{
     *pInput = input;
     
     int row, col;

/*                                                                        */
/*    Loop for every value up to input*input, and position value in matrix*/
/*                                                                        */
      for (value = 1; value <= input*input; value++)
      {                                     /* Loop for all values.       */
         if (loc[row][col] > 0)             /* If some value already      */
         {                                  /*  present, then             */
            row += 2;                       /*  move down 1 row of prev.  */
            if (row > input)                /*  If exceeds side, then     */    
               row -= input;                /*   go to other side.        */

            col--;                          /*  move left 1 column.       */
            if (col < 1)                    /*  If exceeds side, then     */
               col = input;                 /*   go to other side.        */
         }

         loc[row][col] = value;             /* Assign value to location.  */

/*                                                                        */
/*       Add to totals                                                    */ 
/*                                                                        */
         loc[0][col] += value;              /* Add to its column total.   */
         loc[row][0] += value;              /* Add to its row total.      */
         if (row == col)                    /* Add to diagonal total if   */
            loc[0][0] += value;             /*  it falls on the diagonal. */

         if (row+col == input+1)            /* Add to other diagonal if   */
            otherdiag += value;             /*  it falls on the line.     */

/*                                                                        */
/*       Determine where new row and col are                              */
/*                                                                        */
         row--;
         if (row < 1)                       /* If row exceeds side then   */
            row = input;                    /*  goto other side.          */
         col++;
         if (col > input)                   /* If col exceeds side then   */
            col = 1;                        /*  goto other side.          */
      }                                     /* End of getting all values. */
//      cout << *pInput << "\n" << input;
        delete [] loc;
}

void CMatrix::Display()
{
     *pInput = input;
     
      cout << "\nThe number you selected was " << input << ", and the matrix is:\n\n";
      
      for (int row = 1; row <=input; row++)     /* Loop: print a row at a time*/
      {
         cout << "     ";                       /* Create column for diag.total*/
         for (int col = 1; col <=input; col++)
            cout << loc[row][col];              /* Print values found in a row*/
         cout << " = " << loc[row][0] << "\n";  /* Print total of row.        */
      }

/*                                                                        */
/*    Print out the totals for each column, starting with diagonal total. */
/*                                                                        */
      for (int col = 0; col <=input; col++)     /* Print line separating the  */
         cout << "-----";                       /*  value matrix and col totals*/
      cout << otherdiag;                        /* Print out the diagonal total*/
      for (int col = 1; col <=input; col++)
         cout << loc[0][col];                   /* Print out the column totals*/
      cout << loc[0][0] << "\n";                /* Print out the other diagonal*/
                                                /*  total                     */
      cout << "\nEnter a positive, odd integer (-1 to exit program):\n";
}

int main()
{   
//    CMatrix *pInput = new CMatrix;
    
    CMatrix Homework;
    Homework.GetData();
//    Homework.Init();
    Homework.Calculate();
    Homework.Display();
}

Ok i've been working on it more and here's what I have so far... I can send the input into the Init and then send it into the calculate function but I can't seem to send the pointer for the array into the calculate function please help!

#include <iostream>
#include <limits>
#include <cctype>
using namespace std;

class CMatrix
{
    public:
           void GetData();
           void Init(int input);
           void Calculate(int input, int* loc[]);
           void Display();
           
    private:
            int* pInput;
            int input;
//            int** pnLoc;
            int** loc;
            int value;
            int otherdiag;
};

void CMatrix::GetData()
{
     int input = 0;
     int** loc;
     
     for(;;) //infinite for loop
     {
            cout << "\nEnter a positive,";
            cout << " odd integer (-1 to exit program):\n";
            cin >> input;
//            pInput = &input;
            
//            cout << "Pointer " << *pInput << "\n" << input;
            
            //if numbers entered, enter the block
            if (cin.good()){
               if (input == -1){
                  break;
               }
               else if (input > 15){
                    cout << "Sorry, but the integer has";
                    cout << " to be less than 15.\n";
               }
               else if (input%2 == 0){
                    cout << "Sorry, but the integer has to be odd.\n";
               }   
            Init(input);
            }//end if cin.good()
            else if (!isdigit(input))
                 cout <<"Only digits are allowed!\n";
                 
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(),'\n');
     }//end for loop
}

void CMatrix::Init(int input)
{
     int row, col;

//     cout << "\n" << input;
     
     int **loc = 0;
     
     loc = new int*[input];
     
     for (row = 0; row <= input; row++)
         loc[row] = new int[input];
     
     for (row = 0; row <= input; row++)
         for (col = 0; col <= input; col++) 
             *(loc[row] + col) = col;
                                            
     row = 1;                              
     col = input/2 + 1;                    
     otherdiag = 0;
     
     Calculate(input, loc);
     
     delete [] loc;
}

void CMatrix::Calculate(int input, int* loc[])
{
//     *pInput = input;
     
     int row, col;

//     cout << "\n" << input;

/*                                                                        */
/*    Loop for every value up to input*input, and position value in matrix*/
/*                                                                        */
      for (value = 1; value <= input*input; value++)
      {                                     /* Loop for all values.       */
         if (loc[row][col] > 0)             /* If some value already      */
         {                                  /*  present, then             */
            row += 2;                       /*  move down 1 row of prev.  */
            if (row > input)                /*  If exceeds side, then     */    
               row -= input;                /*   go to other side.        */

            col--;                          /*  move left 1 column.       */
            if (col < 1)                    /*  If exceeds side, then     */
               col = input;                 /*   go to other side.        */
         }

         loc[row][col] = value;             /* Assign value to location.  */

/*                                                                        */
/*       Add to totals                                                    */ 
/*                                                                        */
         loc[0][col] += value;              /* Add to its column total.   */
         loc[row][0] += value;              /* Add to its row total.      */
         if (row == col)                    /* Add to diagonal total if   */
            loc[0][0] += value;             /*  it falls on the diagonal. */

         if (row+col == input+1)            /* Add to other diagonal if   */
            otherdiag += value;             /*  it falls on the line.     */

/*                                                                        */
/*       Determine where new row and col are                              */
/*                                                                        */
         row--;
         if (row < 1)                       /* If row exceeds side then   */
            row = input;                    /*  goto other side.          */
         col++;
         if (col > input)                   /* If col exceeds side then   */
            col = 1;                        /*  goto other side.          */
      }                                     /* End of getting all values. */
//      cout << *pInput << "\n" << input;
        delete [] loc;
}

void CMatrix::Display()
{
     *pInput = input;
     
      cout << "\nThe number you selected was " << input << ", and the matrix is:\n\n";
      
      for (int row = 1; row <=input; row++)     /* Loop: print a row at a time*/
      {
         cout << "     ";                       /* Create column for diag.total*/
         for (int col = 1; col <=input; col++)
            cout << loc[row][col];              /* Print values found in a row*/
         cout << " = " << loc[row][0] << "\n";  /* Print total of row.        */
      }

/*                                                                        */
/*    Print out the totals for each column, starting with diagonal total. */
/*                                                                        */
      for (int col = 0; col <=input; col++)     /* Print line separating the  */
         cout << "-----";                       /*  value matrix and col totals*/
      cout << otherdiag;                        /* Print out the diagonal total*/
      for (int col = 1; col <=input; col++)
         cout << loc[0][col];                   /* Print out the column totals*/
      cout << loc[0][0] << "\n";                /* Print out the other diagonal*/
                                                /*  total                     */
      cout << "\nEnter a positive, odd integer (-1 to exit program):\n";
}

int main()
{   
//    CMatrix *pInput = new CMatrix;
    
    CMatrix Homework;
    Homework.GetData();
//    Homework.Init();
//    Homework.Calculate();
    Homework.Display();
}

Oh, there's too much code... Could you please tell the exact error place? Why can't you use Calculate() function? What does exactly happen if you try?

Latest work

#include <iostream>
#include <limits>
#include <cctype>
using namespace std;

class CMatrix
{
    public:
           void GetData();
           void Init();
           void Calculate();
           void Display();
    private:
            int mInput;
            int** loc;
            int value;
            int otherdiag;
};

void CMatrix::GetData()
{
     int input = 0;
     int** loc;

/*                                                                        */
/* Print introduction of what this program is all about.                  */
/*                                                                        */
     cout << "\nMagic Squares: This program produces an NxN matrix where\n";
     cout << "N is some positive odd integer.  The matrix contains the \n";
     cout << "values 1 to N*N.  The sum of each row, each column, and \n";
     cout << "the two main diagonals are all equal.  Not only does this \n";
     cout << "program produces the matrix, it also computes the totals for\n";
     cout << "each row, column, and two main diagonals.\n";

     cout << "\nBecause of display constraints, this program can work with\n";
     cout << "values up to 13 only.\n\n";
     
     for(;;) //infinite for loop
     {
            cout << "\nEnter a positive,";
            cout << " odd integer (-1 to exit program):\n";
            cin >> input;
            
            mInput = input;
            
            //if numbers entered, enter the block
            if (cin.good())
            {
               if (input == -1)
               {
                  break;
               }
               else if (input > 15)
               {
                    cout << "Sorry, but the integer has";
                    cout << " to be less than 15.\n";
                    continue;
               }
               else if (input%2 == 0)
               {
                    cout << "Sorry, but the integer has to be odd.\n";
                    continue;
               }
            Init();   
            Calculate();
//            Display();
            }//end if cin.good()
            else if (!isdigit(input))
                 cout <<"Only digits are allowed!\n";
            
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(),'\n');
     }//end for loop
}

void CMatrix::Init()
{
     int row, col;

     cout << "Init = " << mInput << "\n";
     
     int **loc = 0;
     
     loc = new int*[mInput];
     
     for (row = 0; row < mInput; row++)
         loc[row] = new int[mInput];
     
     for (row = 0; row < mInput; row++)
     {
         for (col = 0; col < mInput; col++)
         {
             *(loc[row] + col) = col;  
             cout << loc[row][col];
         }
         cout << "\n";
     }    
     
     row = 1;                              
     col = mInput/2 + 1;                    
     otherdiag = 0;

     for (row = 0; row < mInput; row++)
         delete [] loc[row];
     
     delete [] loc;
}

void CMatrix::Calculate()
{    
     int row = 0;
     int col = 0;
     
     cout << "Calculate = " << mInput << "\n";
     
     for (row = 0; row < mInput; row++)
     {
         for (col = 0; col < mInput; col++)
         {  
            cout << loc[row][col];
         }
     cout << "\n";
     }
/*                                                                        */
/*    Loop for every value up to input*input, and position value in matrix*/
/*                                                                        */
     for (value = 1; value <= mInput*mInput; value++)
     {                                     /* Loop for all values.       */
        if (loc[row][col] > 0)             /* If some value already      */
        {                                  /*  present, then             */
           row += 2;                       /*  move down 1 row of prev.  */
           if (row > mInput)                /*  If exceeds side, then     */    
              row -= mInput;                /*   go to other side.        */

           col--;                          /*  move left 1 column.       */
           if (col < 1)                    /*  If exceeds side, then     */
              col = mInput;                 /*   go to other side.        */
        }
        
          
        loc[row][col] = value;             /* Assign value to location.  */

/*                                                                        */
/*       Add to totals                                                    */ 
/*                                                                        */
        loc[0][col] += value;              /* Add to its column total.   */
        loc[row][0] += value;              /* Add to its row total.      */
        if (row == col)                    /* Add to diagonal total if   */
           loc[0][0] += value;             /*  it falls on the diagonal. */

        if (row+col == mInput+1)            /* Add to other diagonal if   */
           otherdiag += value;             /*  it falls on the line.     */

/*                                                                        */
/*       Determine where new row and col are                              */
/*                                                                        */
        row--;
        if (row < 1)                       /* If row exceeds side then   */
           row = mInput;                    /*  goto other side.          */
        
        col++;
        if (col > mInput)                   /* If col exceeds side then   */
           col = 1;                        /*  goto other side.          */
     }                                     /* End of getting all values. */
}

void CMatrix::Display()
{
     
     cout << "\nThe number you selected was " << mInput << ", and the matrix is:\n\n";
      
      for (int row = 1; row <=mInput; row++)     /* Loop: print a row at a time*/
      {
         cout << "     ";                       /* Create column for diag.total*/
         for (int col = 1; col <=mInput; col++)
            cout << loc[row][col];              /* Print values found in a row*/
         cout << " = " << loc[row][0] << "\n";  /* Print total of row.        */
      }

/*                                                                        */
/*    Print out the totals for each column, starting with diagonal total. */
/*                                                                        */
      for (int col = 0; col <=mInput; col++)     /* Print line separating the  */
         cout << "-----";                       /*  value matrix and col totals*/
      cout << otherdiag;                        /* Print out the diagonal total*/
      for (int col = 1; col <=mInput; col++)
         cout << loc[0][col];                   /* Print out the column totals*/
      cout << loc[0][0] << "\n";                /* Print out the other diagonal*/
                                                /*  total                     */
      cout << "\nEnter a positive, odd integer (-1 to exit program):\n";
}

int main()
{   
    CMatrix Homework;
    Homework.GetData();
}
#include <iostream>
#include <limits>
#include <cctype>
using namespace std;

class CMatrix
{
    public:
           void GetData();
           void Init();
           void Calculate();
           void Display();
    private:
            int mInput;
            int** loc;
            int value;
            int otherdiag;
};

void CMatrix::GetData()
{
     int input = 0;

/*                                                                        */
/* Print introduction of what this program is all about.                  */
/*                                                                        */
     cout << "\nMagic Squares: This program produces an NxN matrix where\n";
     cout << "N is some positive odd integer.  The matrix contains the \n";
     cout << "values 1 to N*N.  The sum of each row, each column, and \n";
     cout << "the two main diagonals are all equal.  Not only does this \n";
     cout << "program produces the matrix, it also computes the totals for\n";
     cout << "each row, column, and two main diagonals.\n";

     cout << "\nBecause of display constraints, this program can work with\n";
     cout << "values up to 13 only.\n\n";
     
     for(;;) //infinite for loop
     {
            cout << "\nEnter a positive,";
            cout << " odd integer (-1 to exit program):\n";
            cin >> input;
            
            mInput = input;
            
            //if numbers entered, enter the block
            if (cin.good())
            {
               if (input == -1)
               {
                  break;
               }
               else if (input > 15)
               {
                    cout << "Sorry, but the integer has";
                    cout << " to be less than 15.\n";
                    continue;
               }
               else if (input%2 == 0)
               {
                    cout << "Sorry, but the integer has to be odd.\n";
                    continue;
               }
            Init();   
            Calculate();
            Display();
            }//end if cin.good()
            else if (!isdigit(input))
                 cout <<"Only digits are allowed!\n";
            
            cin.clear();
            cin.ignore(numeric_limits<streamsize>::max(),'\n');
     }//end for loop
}

void CMatrix::Init()
{
     int row, col;

//     cout << "Init = " << mInput << "\n";
     
     loc = 0;
     
     loc = new int*[mInput];
     
     for (row = 0; row <= mInput; row++)
         loc[row] = new int[mInput];
     
     for (row = 0; row <= mInput; row++)
     {
         for (col = 0; col <= mInput; col++)
         {
             *(loc[row] + col) = 0;  
             cout << loc[row][col];
         }
         cout << "\n";
     }    
     

}

void CMatrix::Calculate()
{    
     int row = 1;                              
     int col = mInput/2 + 1;                    
     otherdiag = 0;
     
//     cout << "Calculate = " << mInput << "\n";
     cout << loc[row][col];     
/*                                                                        */
/*    Loop for every value up to input*input, and position value in matrix*/
/*                                                                        */
     for (value = 1; value <= mInput*mInput; value++)
     {     
//           cout << "row = " << row;
//           cout << "col = " << col;
//           cout << "value = " << value;  
                                           /* Loop for all values.       */
        if (loc[row][col] > 0)             /* If some value already      */
        {                                  /*  present, then             */
           row += 2;                       /*  move down 1 row of prev.  */
           if (row > mInput)                /*  If exceeds side, then     */    
              row -= mInput;                /*   go to other side.        */

           col--;                          /*  move left 1 column.       */
           if (col < 1)                    /*  If exceeds side, then     */
              col = mInput;                 /*   go to other side.        */
        }
        
        
        loc[row][col] = value;             /* Assign value to location.  */

/*                                                                        */
/*       Add to totals                                                    */ 
/*                                                                        */
        loc[0][col] += value;              /* Add to its column total.   */
        loc[row][0] += value;              /* Add to its row total.      */
        if (row == col)                    /* Add to diagonal total if   */
           loc[0][0] += value;             /*  it falls on the diagonal. */

        if (row+col == mInput+1)           /* Add to other diagonal if   */
           otherdiag += value;             /*  it falls on the line.     */

/*                                                                        */
/*       Determine where new row and col are                              */
/*                                                                        */
        row--;
        if (row < 1)                       /* If row exceeds side then   */
           row = mInput;                   /*  goto other side.          */
        
        col++;
        if (col > mInput)                  /* If col exceeds side then   */
           col = 1;                        /*  goto other side.          */
     }                                     /* End of getting all values. */

     for (row = 0; row <= mInput; row++)
     {
         for (col = 0; col <= mInput; col++)
         {
//             *(loc[row] + col) = 0;  
             cout << loc[row][col];
         }
         cout << "\n";
     }    


     
     for (row = 0; row < mInput; row++)
         delete [] loc[row];
     
     delete [] loc;
}

void CMatrix::Display()
{

     for (int row = 0; row <= mInput; row++)
     {
         for (int col = 0; col <= mInput; col++)
         {
//             *(loc[row] + col) = 0;  
             cout << loc[row][col];
         }
         cout << "\n";
     }    

     
     cout << "\nThe number you selected was " << mInput << ", and the matrix is:\n\n";
      
      for (int row = 1; row <=mInput; row++)    /* Loop: print a row at a time*/
      {
         cout << "     ";                       /* Create column for diag.total*/
         for (int col = 1; col <=mInput; col++)
            cout << loc[row][col];              /* Print values found in a row*/
         cout << " = " << loc[row][0] << "\n";  /* Print total of row.        */
      }

/*                                                                        */
/*    Print out the totals for each column, starting with diagonal total. */
/*                                                                        */
      for (int col = 0; col <=mInput; col++)    /* Print line separating the  */
         cout << "-----";                       /*  value matrix and col totals*/
      cout << "   \n   " << otherdiag;                        /* Print out the diagonal total*/
      for (int col = 1; col <=mInput; col++)
         cout << " " << loc[0][col];                   /* Print out the column totals*/
      cout << "   " << loc[0][0];                /* Print out the other diagonal*/
                                                /*  total                     */
}

int main()
{   
    CMatrix Homework;
    Homework.GetData();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.