mercredi 25 janvier 2017

Alter the attached program to draw a truth table. Modify the 'fill' or 'expression' functions to accomplish this

As the title reads I need to modify the code snippet below, and I have no idea where to even begin. I've forgotten more than I thought over the break it seems.Any help would be tremendous.. Thanks for reading! First post so I apologize if I'm doing any wrongs.

void fill(unsigned char arr[ARES][ARES][3]) {
    // puts a color at every array location
    for(int r = 0; r < ARES; r++) {
        for(int c = 0; c < ARES; c++) {
            // this holds logical variables
            bool vars[VARS] = {0};

            // populate the array with truth values
            int temp = r;
            for(int i = VARS-1; i >= 0; i--) {
                // convert current r value into binary
                vars[i] = temp % 2;
                temp /= 2;
            }

            // this sets truth value for a table entry
            bool truth = expression(vars, c);

            // this draws truth values
            arr[r][c][0] = 255 * truth;
            arr[r][c][1] = 255 * truth;
            arr[r][c][2] = 255 * truth;
        }
    }
}


bool expression(bool vars[VARS], int c) {
    /*switch(c) {
        case 0:
            return vars[0] && vars[1];
        case 1:
            return !vars[1];
        case 2:
            return !(vars[0] && vars[1]);
        case 3:
            return !(vars[0] || vars[1]);
    }*/

    // recursive scalable version
    // base cases
    if(c < VARS) {
        return vars[c];
    }

    // recursive cases
    return !imp(vars[c-1], vars[c-2]) || bii(vars[c-3], !vars[c-4]);


}

Aucun commentaire:

Enregistrer un commentaire