gpt4 book ai didi

c++ - 如何对卡诺图中的单元格进行分类

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:23:19 27 4
gpt4 key购买 nike

我在卡诺图的分类上遇到了一些问题,我不知道如何定义卡诺表的各种情况,

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

enter image description here

我的程序必须知道这两个“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++ - 如何对卡诺图中的单元格进行分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22744948/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com