Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. /*
  2. * File: main.cpp
  3. * Author: James Rungsawang
  4. * Created on February 11th, 2019, 12:36 PM
  5. * Purpose: Creation of Template to be used for all
  6. * future projects
  7. */
  8.  
  9. //System Libraries
  10. #include <iostream> //Input/Output Library
  11. #include <iomanip> //Format Library
  12. using namespace std;
  13.  
  14. //User Libraries
  15.  
  16. //Global Constants, no Global Variables are allowed
  17. //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...
  18.  
  19. //Function Prototypes
  20. int SIZE = 99;
  21.  
  22. //Execution Begins Here!
  23. int main(int argc, char** argv) {
  24. //Declare Variables
  25. int N = 10;
  26. int M = 3;
  27.  
  28. //Initialize or input i.e. set variable values
  29. cout<<"Enter N"<<endl;
  30. cin>>N;
  31. cout<<"Enter M"<<endl;
  32. cin>>M;
  33.  
  34.  
  35. int array[N][N];
  36. int sums[N][N];
  37. int showcount[N][N];
  38. int shift = (M-1)/2;
  39. int inc = 0;
  40. for(int x = 0; x < N; x++){
  41.  
  42. for(int y = 0; y < N; y++){
  43. array[x][y] = inc;
  44. inc++;
  45. }
  46.  
  47. }
  48.  
  49. for(int x = 0; x < N; x++){
  50.  
  51. for(int y = 0; y < N; y++){
  52. int total = 0;
  53. int count = 0;
  54. int startX = x-shift;
  55.  
  56.  
  57. for(int p = 0; p < M; p++){
  58. int startY = y-shift;
  59. for (int i = 0; i < M; i++){
  60.  
  61. if (startX>=0 and startY>=0 and startX<N and startY<N){
  62. total += array[startX][startY];
  63. count++;
  64.  
  65. }
  66.  
  67. startY++;
  68. }
  69. startX++;
  70. }
  71. showcount[x][y] = count;
  72. total/=count;
  73. sums[x][y] = total;
  74. }
  75.  
  76. }
  77. //Display the headings and the initial values
  78. for(int x = 0; x < N; x++){
  79.  
  80. for(int y = 0; y < N; y++){
  81. cout<<setw(3)<<array[x][y]<<" ";
  82. }
  83. cout<<endl;
  84. }
  85.  
  86. cout<<endl<<endl<<endl;
  87. for(int x = 0; x < N; x++){
  88.  
  89. for(int y = 0; y < N; y++){
  90. cout<<setw(3)<<sums[x][y]<<" ";
  91. }
  92. cout<<endl;
  93. }
  94.  
  95. cout<<endl<<endl<<endl;
  96.  
  97. for(int x = 0; x < N; x++){
  98.  
  99. for(int y = 0; y < N; y++){
  100. cout<<setw(3)<<showcount[x][y]<<" ";
  101. }
  102. cout<<endl;
  103. }
  104. //Map inputs -> outputs
  105.  
  106. //Display the outputs
  107.  
  108. //Exit stage right or left!
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement