Guest User

For Adas: Parallel Numerical Sequence in Matrix V.2

a guest
Nov 5th, 2013
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int i, j, arraySize;
  5.  
  6. void fillArray(double **);
  7. void showArray(double **);
  8. void showInvDiag(double **);
  9. void showOtherDiags(double **);
  10.  
  11. /* Trouble arises when calling 'showInvDiag'
  12. void displayEverything(double **array){
  13.     showArray(array);
  14.     showInvDiag(array);
  15.     showOtherDiags(array);
  16. }
  17. */
  18.  
  19. int main(){
  20.     cout << "Number of lines and columns: "; cin >> arraySize;
  21.     // Create the 2D array
  22.     //****************************************************************
  23.     double **array;
  24.     array = new double *[arraySize];
  25.     for(i = 0; i < arraySize; i++) array[i] = new double [arraySize];
  26.     //****************************************************************
  27.  
  28.     fillArray(array);
  29.     //displayEverything(array); // Not working fully
  30.     showArray(array);
  31.     showInvDiag(array);
  32.     showOtherDiags(array);
  33.  
  34.     return 0;
  35. }
  36.  
  37. void fillArray(double **array){
  38.     for(i = 0; i < arraySize; i++){
  39.         for(j = 0; j < arraySize; j++){
  40.             cout << "(" << i << ", "<< j << ") = ";
  41.             cin >> array[i][j];
  42.         }
  43.     }
  44.     cout << endl;
  45. }
  46. void showArray(double **array){
  47.     for(i = 0; i < arraySize; i++){
  48.         for(j = 0; j < arraySize; j++) cout << array[i][j] << " ";
  49.         cout << endl;
  50.     }
  51.     cout << endl;
  52. }
  53. void showInvDiag(double **array){
  54.     double *diagSum;
  55.     *diagSum = 0;
  56.     j = arraySize - 1;
  57.  
  58.     cout <<"\nInverse Diagonal values are: " << endl;
  59.  
  60.     for(i = 0; i < arraySize; i++){
  61.         *diagSum += array[i][j];
  62.         cout << array[i][j--] << " ";
  63.     }
  64.  
  65.     cout << "\n\nInverse diagonal arithmetic average: " << *diagSum / arraySize << endl;
  66.  
  67.     delete diagSum;
  68. }
  69. void showOtherDiags(double **array){
  70.     int holdX = 0, holdY = 0;
  71.     int x, y;
  72.     j = 1;
  73.  
  74.     cout << "\nOther inverse diagonals." << endl;
  75.     cout << "*************************************" << endl;
  76.     // Upper-Left Diagonal Triangle
  77.     while(j <= arraySize - 1){
  78.         x = holdX; y = holdY;
  79.  
  80.         for(i = 0; i < j; i++) cout << array[x++][y--] << " ";
  81.         cout << endl;
  82.  
  83.         holdY++; j++;
  84.     }
  85.  
  86.     // Lower-Right Diagonal Triangle
  87.     j = arraySize - 1, holdX = 1, holdY = arraySize - 1;
  88.  
  89.     while(j >= 1){
  90.         x = holdX; y = holdY;
  91.  
  92.         for(i = 0; i < j; i++) cout << array[x++][y--] << " ";
  93.         cout << endl;
  94.  
  95.         holdX++; j--;
  96.     }
  97.     cout << "*************************************" << endl;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment