使用C ++中的参数移动数组的内容

时间:2016-11-16 08:36:43

标签: c++ matrix parameters shift

过去几周我一直在玩一些代码。代码是数字1的显示。我想基本上创建一个点阵式打印输出,其中1连续向右移动。 这是我到目前为止的地方:

#include <iostream>
using namespace std;
/* use function to shift all characters one place to the right */
/* use a function to declare the characters of the fiqure */
int i, j;
int matrix([int i][int j]);//dont think this is right

我已经声明了我的变量,以及带有参数I和j的矩阵

int main()
{
    //should the matrix be a global function, therefore can be accessed by the move function?
    /* the matrix is contained within the matrix function. The goal of main, is to manipulate
    the matrix to transponse the elements to the next column*/

    // 8 rows and 13 columns 

    for (i = 0; i < 8; i++)
    {
        int p = (j + 3)%13;
        for (j = p; j < 13 ; j++)
        {
            matrix[i][j] = matrix[i][j + 3];
            //priting out the matrix 
            cout << matrix[i][j];
        }
        cout << "\n";
    }
    cout << endl;
}

int matrix(int i, int j)
/* this function sets up the matrix and returns the value of the matrix. 
this function should simply be a display function */
{
    int matrix[8][13] = { { 0,1,1,1,1,1,0,0,0,0,0,0,0 },
    { 1,1,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 },
    { 0,0,1,1,1,1,0,0,0,0,0,0,0 } };

    //display the elements
    for (i = 0; i < 8; i++)
    {
        for (j = 0; j < 13; j++)
        {
            //priting out the matrix 
            cout << matrix[i][j];
        }
        cout << "\n";
    }
    cout << endl;
    return matrix[i][j];
}

这是主要功能,我尝试为矩阵分配实际参数并将它们传递给矩阵显示。主函数具体定义了一个变量'p'(无论如何计划),使用该变量导致向右移动。 我使用modulo 13运算符尝试在移位后清除(或返回0)值,因此1似乎在矩阵中移动

除了上面的函数之外,我还包含了代码中的最后几位,这些位基本上是我现在正在尝试的注释和想法。

/*
int array_size = sizeof(matrix) / sizeof(matrix[0]);
    for (i = 0; i < 8; i++)
    {
        for (j = array_size-1; j > 0; j--)
        {
            matrix[j] = matrix[j - 1];
        }
        matrix[0]=
        cout << "\n";
    }
}


*/

/*
int x = i;
    int p = (j + 3) % 13;
        int matrix(x, p);
    return 0;
*/

事先感谢任何帮助或指导:)

0 个答案:

没有答案