Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: main.cpp
- * Author: James Rungsawang
- * Created on February 11th, 2019, 12:36 PM
- * Purpose: Creation of Template to be used for all
- * future projects
- */
- //System Libraries
- #include <iostream> //Input/Output Library
- #include <iomanip> //Format Library
- using namespace std;
- //User Libraries
- //Global Constants, no Global Variables are allowed
- //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...
- //Function Prototypes
- int SIZE = 99;
- //Execution Begins Here!
- int main(int argc, char** argv) {
- //Declare Variables
- int N = 10;
- int M = 3;
- //Initialize or input i.e. set variable values
- cout<<"Enter N"<<endl;
- cin>>N;
- cout<<"Enter M"<<endl;
- cin>>M;
- int array[N][N];
- int sums[N][N];
- int showcount[N][N];
- int shift = (M-1)/2;
- int inc = 0;
- for(int x = 0; x < N; x++){
- for(int y = 0; y < N; y++){
- array[x][y] = inc;
- inc++;
- }
- }
- for(int x = 0; x < N; x++){
- for(int y = 0; y < N; y++){
- int total = 0;
- int count = 0;
- int startX = x-shift;
- for(int p = 0; p < M; p++){
- int startY = y-shift;
- for (int i = 0; i < M; i++){
- if (startX>=0 and startY>=0 and startX<N and startY<N){
- total += array[startX][startY];
- count++;
- }
- startY++;
- }
- startX++;
- }
- showcount[x][y] = count;
- total/=count;
- sums[x][y] = total;
- }
- }
- //Display the headings and the initial values
- for(int x = 0; x < N; x++){
- for(int y = 0; y < N; y++){
- cout<<setw(3)<<array[x][y]<<" ";
- }
- cout<<endl;
- }
- cout<<endl<<endl<<endl;
- for(int x = 0; x < N; x++){
- for(int y = 0; y < N; y++){
- cout<<setw(3)<<sums[x][y]<<" ";
- }
- cout<<endl;
- }
- cout<<endl<<endl<<endl;
- for(int x = 0; x < N; x++){
- for(int y = 0; y < N; y++){
- cout<<setw(3)<<showcount[x][y]<<" ";
- }
- cout<<endl;
- }
- //Map inputs -> outputs
- //Display the outputs
- //Exit stage right or left!
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement