【问题标题】:How to assort the cell in Karnaugh map如何在卡诺图中对细胞进行分类
【发布时间】:2014-03-30 14:07:03
【问题描述】:

卡诺图分类有问题,不知道卡诺表的各种情况如何定义,

如果我使用连续的“if”和“else”语句,我认为这是非常低级的编程,我想要一些算法,它本身就会被称为分类,或者使用更少的“if”和“else”语句 这里我有一些卡诺图的分类示例:

我的程序必须知道这两个“1”属于一个类别,并且会同时归类 我怎样才能把这个灌输到我的程序中,我怎样才能实现这个分类 这是我的两个变量卡诺图的代码:

int num_var;        // stores the number of variables entered by user
int squ_4[4];       // variable used for a 1-D array for the 4 square Karnaugh map
int a,b,c;          // variables for entering and checking values in Karnaugh map squares
char var_name[10];  // character string array

strcpy(var_name,"ABCDRSXYZ");   // character string for variable name

printf("\nThis program works out a Boolean function for a 2,3 and 4 variable Karnaugh map.\n\n");

cout << "Enter number of Karnaugh map variables (2,3 or 4) required: ";
cin >> num_var;
do
{
    if(num_var>4)
    {
        printf("\n Sorry, you have chosen too many variables \n");
        printf("\n Please enter 2,3 or 4 variables: ");
        cin >> num_var;
    }
    if(num_var<2)
    {
        printf("\n Sorry, not enough variables chosen \n");
        printf("\n Please enter 2,3 or 4 variables: ");
        cin >> num_var;
    }
}while(num_var>4 || num_var<2);

do
{
    printf("\nVariables are: %c %c \n",var_name[4],var_name[5]);    // output variable names

    printf("\n Please enter value in Karnaugh map square and press RETURN \n")

    for(a=0;a<4;a++)
    {
        printf("\nEnter 1 or 0 into square %d: ",a);
        cin >> squ_4[a];    // store value into array

        while(squ_4[a]!=0 && squ_4[a]!=1)
        {
            printf("\n Value entered in Karnaugh map square %d, was not 1 or 0 \n",a);
            printf("\nPlease enter 1 or 0 into square %d: ",a);
            cin >> squ_4[a];
        }
    }
    printf("\nYour Karnaugh map is: \n\n\t\t     %c'%c \n\t\t   %c'%d %d\n\t\t   %c %d %d \n",var_name[5],var_name[5],var_name[4],squ_4[0],squ_4[1],var_name[4],squ_4[2],squ_4[3]);


    if(squ_4[0]==0 && squ_4[1]==0 && squ_4[2]==0 && squ_4[3]==0)
    {
        printf("\nThere is no function from the Karnaugh map\n\n");
        return 0;
    }
    printf("\nThe Boolean function is: \n\n ");

    if(squ_4[0]==1)
    {
        printf("%c'%c' ",var_name[4],var_name[5]);
        if(squ_4[1]==1 || squ_4[2]==1 || squ_4[3]==1)
        {
            printf("+ ");
        }
    }
    if(squ_4[1]==1)
    {
        printf("%c'%c ",var_name[4],var_name[5]);
        if(squ_4[2]==1 || squ_4[3]==1)
        {
            printf("+ ");
        }
    }
    if(squ_4[2]==1)
    {
        printf("%c%c' ",var_name[4],var_name[5]);
        if(squ_4[3]==1)
        {
            printf("+ ");
        }
    }
    if(squ_4[3]==1)
    {
        printf("%c%c ",var_name[4],var_name[5]);
    }

    cout << "\n\n\n\n";
}while(num_var==2);

【问题讨论】:

  • 还有其他方法可以实现这样的事情吗? :\

标签: c++ boolean-logic logical-operators


【解决方案1】:

将他们的答案存储在某个变量中,并使用循环比较结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-24
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 2019-09-23
    • 2017-05-15
    相关资源
    最近更新 更多